mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-21 12:40:08 +00:00
add navigation key handler
This commit is contained in:
commit
c7e6c52f3c
1
AUTHORS
1
AUTHORS
@ -3,6 +3,7 @@ Lu Wang <coolwanglu@gmail.com>
|
||||
|
||||
Contributors:
|
||||
Chris Cinelli <chris@allestelle.com>
|
||||
Daniel Bonniot de Ruisselet <dbonniot@chemaxon.com>
|
||||
Deepak <iapain@gmail.com>
|
||||
filodej <philode@gmail.com>
|
||||
hasufell <julian.ospald@googlemail.com>
|
||||
|
@ -187,7 +187,7 @@ var pdf2htmlEX = (function(){
|
||||
var _ = this;
|
||||
this.$container.scroll(function(){ _.schedule_render(); });
|
||||
|
||||
//this.zoom_fixer();
|
||||
//this.register_key_handler();
|
||||
|
||||
// handle links
|
||||
this.$container.add(this.$outline).on('click', '.'+CSS_CLASS_NAMES['link'], this, this.link_handler);
|
||||
@ -311,7 +311,10 @@ var pdf2htmlEX = (function(){
|
||||
}, this.config['render_timeout']);
|
||||
},
|
||||
|
||||
zoom_fixer : function () {
|
||||
/*
|
||||
* Handling key events, zooming, scrolling etc.
|
||||
*/
|
||||
register_key_handler: function () {
|
||||
/*
|
||||
* When user try to zoom in/out using ctrl + +/- or mouse wheel
|
||||
* handle this and prevent the default behaviours
|
||||
@ -328,27 +331,97 @@ var pdf2htmlEX = (function(){
|
||||
});
|
||||
|
||||
$(window).on('keydown', function keydown(e) {
|
||||
if (e.ctrlKey || e.metaKey) {
|
||||
var handled = false;
|
||||
var cmd = (evt.ctrlKey ? 1 : 0) |
|
||||
(evt.altKey ? 2 : 0) |
|
||||
(evt.shiftKey ? 4 : 0) |
|
||||
(evt.metaKey ? 8 : 0);
|
||||
var with_ctrl = (cmd == 9);
|
||||
var with_alt = (cmd == 2);
|
||||
switch (e.keyCode) {
|
||||
case 61: // FF/Mac '='
|
||||
case 107: // FF '+' and '='
|
||||
case 187: // Chrome '+'
|
||||
if(with_ctrl){
|
||||
_.rescale(1.0 / _.config['scale_step'], true);
|
||||
handled = true;
|
||||
}
|
||||
break;
|
||||
case 173: // FF/Mac '-'
|
||||
case 109: // FF '-'
|
||||
case 189: // Chrome '-'
|
||||
if(with_ctrl){
|
||||
_.rescale(_.config['scale_step'], true);
|
||||
handled = true;
|
||||
}
|
||||
break;
|
||||
case 48: // '0'
|
||||
if(with_ctrl){
|
||||
_.rescale(0, false);
|
||||
handled = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
case 33: // Page UP:
|
||||
if (with_alt) { // alt-pageup -> scroll one page up
|
||||
_.scroll_to(_.get_prev_page());
|
||||
} else { // pageup -> scroll one screen up
|
||||
_.$container.scrollTop(_.$container.scrollTop()-_.$container.height());
|
||||
}
|
||||
handled = true;
|
||||
break;
|
||||
case 34: // Page DOWN
|
||||
if (with_alt) { // alt-pagedown -> scroll one page down
|
||||
_.scroll_to(_.get_next_page());
|
||||
} else { // pagedown -> scroll one screen down
|
||||
_.$container.scrollTop(_.$container.scrollTop()+_.$container.height());
|
||||
}
|
||||
handled = true;
|
||||
break;
|
||||
case 35: // End
|
||||
if (with_ctrl) {
|
||||
_.$container.scrollTop(_.$container[0].scrollHeight);
|
||||
handled = true;
|
||||
}
|
||||
break;
|
||||
case 36: // Home
|
||||
if (e.with_ctrl) {
|
||||
_.$container.scrollTop(0);
|
||||
handled = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if(handled) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
},
|
||||
// Find the first page that is at least half a page below the current position
|
||||
get_next_page : function() {
|
||||
var page_height = this.$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 page_height = this.$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, offsetX, offsetY) {
|
||||
@ -535,6 +608,9 @@ var pdf2htmlEX = (function(){
|
||||
var target_page = this.pages[pageno];
|
||||
if(target_page == undefined) return;
|
||||
|
||||
if(pos == undefined)
|
||||
pos = [0,0];
|
||||
|
||||
var cur_target_pos = target_page.position();
|
||||
|
||||
this.$container.scrollLeft(this.$container.scrollLeft()-cur_target_pos[0]+pos[0]);
|
||||
|
Loading…
Reference in New Issue
Block a user