1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 04:50:09 +00:00
Add key handler, and implement page up, page down, ctrl-home and ctrl-end.

First commit on github and first javascript coding :)
This commit is contained in:
Daniel Bonniot 2013-07-03 09:57:00 +02:00
parent 132478c1c1
commit 316d547ac0

View File

@ -164,6 +164,8 @@ var pdf2htmlEX = (function(){
//this.zoom_fixer();
this.add_key_handler();
// handle links
this.$container.add(this.$outline).on('click', '.'+CSS_CLASS_NAMES['link'], this, this.link_handler);
@ -323,6 +325,64 @@ var pdf2htmlEX = (function(){
});
},
add_key_handler : function () {
var _ = this;
$(window).on('keydown', function keydown(e) {
switch (e.keyCode) {
case 33: // Page Down
_.scroll_to_page(_.get_prev_page());
break;
case 34: // Page Up
_.scroll_to_page(_.get_next_page());
break;
case 35: // End
if (e.ctrlKey)
_.scroll_to_page(_.pages[_.pages.length-1]);
break;
case 36: // Home
if (e.ctrlKey)
_.scroll_to_page(_.pages[1]);
break;
}
});
},
// Find the first page that is at least half a page below the current position
get_next_page : function() {
var _ = this;
var position = [0,0];
var page_height = _.$container.height();
var pl = this.pages;
for(var i in pl) {
var page = pl[i];
var page_position = page.position();
if (page_position[1] < position[1] - page_height/2)
return page;
}
return undefined;
},
// Find the last page that is at least half a page above the current position
get_prev_page : function() {
var _ = this;
var position = [0,0];
var page_height = _.$container.height();
var pl = this.pages.slice().reverse();
for(var i in pl) {
var page = pl[i];
var page_position = page.position();
if (page_position[1] > position[1] + page_height/2)
return page;
}
return undefined;
},
rescale : function (ratio, is_relative) {
var pl = this.pages;
for(var i in pl) {
@ -423,6 +483,16 @@ var pdf2htmlEX = (function(){
}
},
scroll_to_page : function(target_page) {
if (target_page == undefined) return;
// Show a bit of space above the target page when scrolling
// TODO: do not hardcode!
var page_padding = 10;
this.scroll_to(target_page.n, [0,-page_padding]);
},
/* pos=[x,y], where (0,0) is the top-left corner */
scroll_to : function(pageno, pos) {
var target_page = this.pages[pageno];