/* NEW BSD LICENSE {{{ Copyright (c) 2009, anekos. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The names of the authors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ################################################################################### # http://sourceforge.jp/projects/opensource/wiki/licenses%2Fnew_BSD_license # # に参考になる日本語訳がありますが、有効なのは上記英文となります。 # ################################################################################### }}} */ // PLUGIN_INFO {{{ let PLUGIN_INFO = Auto wildoptions Automatically toggle wildoptions=auto 自動的に wildoptions=auto をオンオフします。 1.0.0 anekos new BSD License (Please read the source code comments of this plugin) 修正BSDライセンス (ソースコードのコメントを参照してください) https://github.com/vimpr/vimperator-plugins/raw/master/auto-wildoptions.js 2.0 2.1pre ; // }}} (function () { function around (obj, name, func) { let next = obj[name]; obj[name] = function () let (self = this, args = arguments) func.call(self, function () next.apply(self, args), args); } let context = mappings.getDefault(modes.NORMAL, 'g<').action; around( liberator.eval('Completions', context).prototype.complete, 'complete', function (next, args) { options.get('wildoptions').set('auto'); return next(); } ); around( commandline, 'open', function (next, args) { options.get('wildoptions').set(''); return next(); } ); })(); // vim:sw=2 ts=2 et si fdm=marker: a/nico-fullscreen&id=cc88cd3b0310a6ea7692b5ef06188d4493c70953'>takahashiPresentation.js
blob: 03f5ff989af7ca9bfd4ba4a08976c4e45a7cd2e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// PLUGIN_INFO//{{{
var PLUGIN_INFO =
<VimperatorPlugin>
    <name>{NAME}</name>
    <description>simple takahashi-method presentation tool</description>
    <author mail="konbu.komuro@gmail.com" homepage="http://d.hatena.ne.jp/hogelog/">hogelog</author>
    <version>0.1.1</version>
    <minVersion>2.3pre</minVersion>
    <maxVersion>2.3pre</maxVersion>
    <updateURL>https://github.com/vimpr/vimperator-plugins/raw/master/takahashiPresentation.js</updateURL>
    <date>2008/12/23 09:20:07</date>
    <detail><![CDATA[

== COMMANDS ==
presentation:
   start presentation
== HOWTO ==
open HTML file includes <pre id="page">...</pre> and <div id="text">...</div>.
start :presentation.
     ]]></detail>
</VimperatorPlugin>;
//}}}
(function() {
    let keys = [
        ['<Right>', 'next page', function() nextPage()],
        ['<Left>', 'prev page', function() prevPage()],
        ['^', 'first page', function() loadPage(0)],
        ['$', 'last page', function() loadPage(pages.length-1)],
        ['.', 'last page', function(count) loadPage(count?count-1:0), {count: true}],
        ['q', 'stop presentation', function() stop()],
    ];
    let win;
    let doc;
    let pages = [];
    let curpage = 0;
    let pre;
    let header;
    let fontSize = 18.0;

    function addKeys() {
        keys.forEach(function([key, desc, action, extra])
            mappings.addUserMap([modes.NORMAL], [key], desc, action, extra));
    }
    function fitPage() {
        if(pre.innerHTML=='') return;
        pre.style.display = 'inline';
        let parentWidth = pre.parentNode.offsetWidth;
        let parentHeight = pre.parentNode.offsetHeight;
        let width = pre.offsetWidth;
        let height = pre.offsetHeight;
        let preRatio = width/height;
        let winRatio = parentWidth/parentHeight;
        if(preRatio>winRatio) {
            fontSize *= 0.9*(parentWidth-10)/width;
        } else {
            fontSize *= 0.9*(parentHeight-10)/height;
        }
        pre.style.fontSize = fontSize+'px';
        pre.style.display = 'block';
    }
    function loadPage(page) {
        let text = pages[page];
        pre.innerHTML = text;
        if(header) {
            header.innerHTML = (page+1)+'/'+pages.length;
        }
        fitPage();
    }
    function nextPage() {
        curpage = curpage>=pages.length-1 ? 0 : curpage+1;
        loadPage(curpage);
    }
    function prevPage() {
        curpage = curpage<=0 ? pages.length-1 : curpage-1;
        loadPage(curpage);
    }
    function parsePages(text) {
        return text.split('----')
                   .map(function(txt) txt.replace(/^(?:\r\n|[\r\n])|(?:\r\n|[\r\n])$/g, ''));
    }
    function save_setting(setting) {
        setting.fullscreen = options.fullscreen;
        setting.guioptions = options.guioptions;
        // TODO: save key mapping
        //setting.mappings = keys.map(function([key,]) {
        //    let mapping = mappings.get(modes.NORMAL, key);
        //    return [mapping.modes, key, mapping.description, mapping.action, mapping.extra];
        //});
    }
    function load_setting(setting) {
        options.fullscreen = setting.fullscreen;
        options.guioptions = setting.guioptions;
        // TODO: load key mapping
        //setting.mappings.forEach(function([modes, key, desc, action, extra]) {
        //    mappings.addUserMap(modes, [key], desc, action, extra);
        //});
    }
    let original_setting = {};
    function start() {
        save_setting(original_setting);

        options.fullscreen = true;
        options.guioptions = '';
        win = window.content;
        doc = win.document;
        let text = util.evaluateXPath('//div[@id="text"]').snapshotItem(0);
        pages = parsePages(text.innerHTML);
        addKeys();

        header = util.evaluateXPath('//*[@id="header"]').snapshotItem(0);

        pre = util.evaluateXPath('//pre[@id="page"]').snapshotItem(0);
        pre.style.fontSize = fontSize+'px';
        pre.style.margin = '0px';

        loadPage(0);
    }
    function stop() {
        load_setting(original_setting);
    }

    commands.add(['presentation'], 'start presentation', //{{{
        function(args) {
            start();
        },
        {
            argCount: '0',
        }); //}}}

})();
// vim: fdm=marker sw=4 ts=4 et: