Skip to content

Instantly share code, notes, and snippets.

@teramako
Created December 9, 2011 16:54
Show Gist options
  • Save teramako/1452357 to your computer and use it in GitHub Desktop.
Save teramako/1452357 to your computer and use it in GitHub Desktop.
[Vimperator-plugin]pdf-js mappings
/*
* for pdf.js
* @see https://github.com/mozilla/pdf.js
*
* == Mappings ==
* {count}<C-j> : go next page
* {count}<C-k> : go previous page
* go : go to {num} page
* {count}zz : zoom {count} % or 100%(if ommit)
* zw : zoom page width
* zf : zoom fit
*/
var viewerReg = /^chrome:\/\/pdf\.js\/content\/web\/viewer.html\?file=.*/;
var maps = [
Map([modes.NORMAL], ["<C-j>"], "pdf.js go next page",
function (count) {
content.window.PDFView.page += Math.max(count, 1);
}, {
count: true,
matchingUrls: viewerReg,
}
),
Map([modes.NORMAL], ["<C-k>"], "pdf.js go previous page",
function (count) {
content.window.PDFView.page -= Math.max(count, 1);
}, {
count: true,
matchingUrls: viewerReg,
}
),
Map([modes.NORMAL], ["go"], "pdf.js go to page",
function () {
var pageCount = content.window.PDFView.pages.length;
commandline.input("pdf.js go to page [1 - " + pageCount + "]", function onSubmit(res) {
if (res) {
let num = parseInt(res);
if (!isNaN(num) && 0 < num && num <= pageCount) {
content.window.PDFView.page = num;
}
}
});
}, {
matchingUrls: viewerReg,
}
),
Map([modes.NORMAL], ["zz"], "pdf.js zoom percent",
function (count) {
content.window.PDFView.setScale(count ? count / 100 : 1);
}, {
count: true,
matchingUrls: viewerReg,
}
),
Map([modes.NORMAL], ["zw"], "pdf.js zoom page width",
function () {
content.window.PDFView.parseScale("page-width");
}, {
matchingUrls: viewerReg,
}),
Map([modes.NORMAL], ["zf"], "pdf.js zoom page fit",
function () {
content.window.PDFView.parseScale("page-fit");
}, {
matchingUrls: viewerReg,
}
),
];
maps.forEach(function (map) {
mappings._addMap(map);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment