2 Copyright (c) 2012, anekos.
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
8 1. Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
13 3. The names of the authors may not be used to endorse or promote products
14 derived from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
20 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25 THE POSSIBILITY OF SUCH DAMAGE.
28 ###################################################################################
29 # http://sourceforge.jp/projects/opensource/wiki/licenses%2Fnew_BSD_license #
30 # に参考になる日本語訳がありますが、有効なのは上記英文となります。 #
31 ###################################################################################
37 <plugin name="PDF.js.js" version="1.0.0"
38 href="http://vimpr.github.com/"
39 summary="PDF.js controller."
41 xmlns="http://vimperator.org/namespaces/liberator">
42 <author email="anekos@snca.net">anekos</author>
43 <license>New BSD License</license>
44 <project name="Vimperator" minVersion="3.0"/>
47 <tags>:pdfjs-mapping-sample</tags>
48 <description><p>mapping sample</p><code><![CDATA[
49 nnoremap -urls ^\\.pdf$ i :<C-u>pdfjs index<Space>
50 nnoremap -urls ^\\.pdf$ z :<C-u>pdfjs zoom<Space>
51 ]]></code></description>
62 function getScrollHeight (count
) {
63 let base
= content
.innerHeight
/ 10;
66 return base
* scrollCount
;
69 function addMap (keys
, desc
, action
) {
73 desc
+ ' - PDF.js.js',
77 matchingUrls
: /\.pdf$/
82 function getOutline () {
83 return Array
.slice(content
.document
.querySelector('#outlineView').querySelectorAll('.outlineItem > a'));
86 function getOutlineLevel (node
) {
88 while (node
&& (node
.getAttribute('id') != 'outlineView')) {
89 node
= node
.parentNode
;
92 return node
? (level
/ 2): 0;
95 function nSpace (level
) {
97 for (i
= 0; i
< level
; i
++)
110 content
.document
.querySelector('#viewerContainer').scrollTop
+= getScrollHeight(count
);
118 content
.document
.querySelector('#viewerContainer').scrollTop
-= getScrollHeight(count
);
126 content
.window
.wrappedJSObject
.PDFView
.page
+= (count
> 0 ? count
: 1);
134 content
.window
.wrappedJSObject
.PDFView
.page
-= (count
> 0 ? count
: 1);
140 'Go to page top or N page.',
143 content
.window
.wrappedJSObject
.PDFView
.page
= count
;
145 content
.window
.wrappedJSObject
.PDFView
.page
= 1;
153 liberator
.execute('pdfjs zoom page-fit');
159 'Fit to page to width.',
161 liberator
.execute('pdfjs zoom page-width');
167 'Fit to page to width.',
169 liberator
.execute('pdfjs zoom auto');
175 'Fit to page to width.',
177 commandline
.open('', 'pdfjs zoom ', modes
.EX
);
183 commands
.addUserCommand( // {{{
186 function () void 'Meow is best',
191 'Jump page by index',
193 let index
= args
.literalArg
.match(/^#(\d+)$/);
195 let os
= getOutline();
196 buffer
.followLink(os
[parseInt(index
[1], 10)], liberator
.CURRENT_TAB
);
198 content
.window
.wrappedJSObject
.PDFView
.page
= parseInt(args
.literalArg
, 10);
203 completer: function (context
, args
) {
205 const PageRE
= /#page=(\d+)\&/;
206 if (o
.href
&& PageRE
.test(o
.href
)) {
207 return `${nSpace(getOutlineLevel(o))} ${o.textContent} (p${o.href.match(PageRE)[1]})`;
209 return `${nSpace(getOutlineLevel(o))} ${o.textContent}`;
213 let os
= getOutline();
214 context
.compare
= void 0;
215 context
.filters
= [CompletionContext
.Filter
.textDescription
];
216 context
.completions
= [
220 for ([i
, o
] in Iterator(os
))
230 content
.window
.wrappedJSObject
.PDFView
.parseScale(args
.literalArg
);
234 completer: function (context
, args
) {
235 let os
= Array
.slice(content
.document
.querySelector('#scaleSelect').querySelectorAll('option'));
236 context
.completions
= [
237 [o
.value
, o
.textContent
]
238 for ([, o
] in Iterator(os
))
250 // vim:sw=2 ts=2 et si fdm=marker: