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:
|
Contributors:
|
||||||
Chris Cinelli <chris@allestelle.com>
|
Chris Cinelli <chris@allestelle.com>
|
||||||
|
Daniel Bonniot de Ruisselet <dbonniot@chemaxon.com>
|
||||||
Deepak <iapain@gmail.com>
|
Deepak <iapain@gmail.com>
|
||||||
filodej <philode@gmail.com>
|
filodej <philode@gmail.com>
|
||||||
hasufell <julian.ospald@googlemail.com>
|
hasufell <julian.ospald@googlemail.com>
|
||||||
|
@ -187,8 +187,8 @@ var pdf2htmlEX = (function(){
|
|||||||
var _ = this;
|
var _ = this;
|
||||||
this.$container.scroll(function(){ _.schedule_render(); });
|
this.$container.scroll(function(){ _.schedule_render(); });
|
||||||
|
|
||||||
//this.zoom_fixer();
|
//this.register_key_handler();
|
||||||
|
|
||||||
// handle links
|
// handle links
|
||||||
this.$container.add(this.$outline).on('click', '.'+CSS_CLASS_NAMES['link'], this, this.link_handler);
|
this.$container.add(this.$outline).on('click', '.'+CSS_CLASS_NAMES['link'], this, this.link_handler);
|
||||||
|
|
||||||
@ -233,22 +233,22 @@ var pdf2htmlEX = (function(){
|
|||||||
url: url,
|
url: url,
|
||||||
dataType: 'text'
|
dataType: 'text'
|
||||||
}).done(function(data){
|
}).done(function(data){
|
||||||
_.pages[idx].$d.replaceWith(data);
|
_.pages[idx].$d.replaceWith(data);
|
||||||
|
|
||||||
var $new_pf = _.$container.find('#' + CSS_CLASS_NAMES['page_frame'] + page_no_hex);
|
var $new_pf = _.$container.find('#' + CSS_CLASS_NAMES['page_frame'] + page_no_hex);
|
||||||
_.pages[idx] = new Page($new_pf, _.$container);
|
_.pages[idx] = new Page($new_pf, _.$container);
|
||||||
_.pages[idx].hide();
|
_.pages[idx].hide();
|
||||||
_.pages[idx].rescale(_.scale);
|
_.pages[idx].rescale(_.scale);
|
||||||
_.schedule_render();
|
_.schedule_render();
|
||||||
|
|
||||||
// disable background image dragging
|
// disable background image dragging
|
||||||
$new_pf.find('.'+CSS_CLASS_NAMES['background_image']).on('dragstart', function(e){return false;});
|
$new_pf.find('.'+CSS_CLASS_NAMES['background_image']).on('dragstart', function(e){return false;});
|
||||||
|
|
||||||
// Reset loading token
|
// Reset loading token
|
||||||
delete _.pages_loading[idx];
|
delete _.pages_loading[idx];
|
||||||
|
|
||||||
if (successCallback) successCallback();
|
if (successCallback) successCallback();
|
||||||
}
|
}
|
||||||
).fail(function(jqXHR, textStatus, errorThrown){
|
).fail(function(jqXHR, textStatus, errorThrown){
|
||||||
console.error('error loading page ' + idx + ': ' + textStatus);
|
console.error('error loading page ' + idx + ': ' + textStatus);
|
||||||
|
|
||||||
@ -311,7 +311,10 @@ var pdf2htmlEX = (function(){
|
|||||||
}, this.config['render_timeout']);
|
}, 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
|
* When user try to zoom in/out using ctrl + +/- or mouse wheel
|
||||||
* handle this and prevent the default behaviours
|
* handle this and prevent the default behaviours
|
||||||
@ -328,27 +331,97 @@ var pdf2htmlEX = (function(){
|
|||||||
});
|
});
|
||||||
|
|
||||||
$(window).on('keydown', function keydown(e) {
|
$(window).on('keydown', function keydown(e) {
|
||||||
if (e.ctrlKey || e.metaKey) {
|
var handled = false;
|
||||||
switch (e.keyCode) {
|
var cmd = (evt.ctrlKey ? 1 : 0) |
|
||||||
case 61: // FF/Mac '='
|
(evt.altKey ? 2 : 0) |
|
||||||
case 107: // FF '+' and '='
|
(evt.shiftKey ? 4 : 0) |
|
||||||
case 187: // Chrome '+'
|
(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);
|
_.rescale(1.0 / _.config['scale_step'], true);
|
||||||
break;
|
handled = true;
|
||||||
case 173: // FF/Mac '-'
|
}
|
||||||
case 109: // FF '-'
|
break;
|
||||||
case 189: // Chrome '-'
|
case 173: // FF/Mac '-'
|
||||||
|
case 109: // FF '-'
|
||||||
|
case 189: // Chrome '-'
|
||||||
|
if(with_ctrl){
|
||||||
_.rescale(_.config['scale_step'], true);
|
_.rescale(_.config['scale_step'], true);
|
||||||
break;
|
handled = true;
|
||||||
case 48: // '0'
|
}
|
||||||
|
break;
|
||||||
|
case 48: // '0'
|
||||||
|
if(with_ctrl){
|
||||||
_.rescale(0, false);
|
_.rescale(0, false);
|
||||||
break;
|
handled = true;
|
||||||
default:
|
}
|
||||||
return;
|
break;
|
||||||
}
|
case 33: // Page UP:
|
||||||
e.preventDefault();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 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) {
|
rescale : function (ratio, is_relative, offsetX, offsetY) {
|
||||||
@ -427,16 +500,16 @@ var pdf2htmlEX = (function(){
|
|||||||
},
|
},
|
||||||
|
|
||||||
get_active_page : function () {
|
get_active_page : function () {
|
||||||
// get page that are on the center of the view //TODO better on top?!
|
// get page that are on the center of the view //TODO better on top?!
|
||||||
var y_center = this.$container.offset().top + this.$container.height() / 2;
|
var y_center = this.$container.offset().top + this.$container.height() / 2;
|
||||||
var pl = this.pages;
|
var pl = this.pages;
|
||||||
var last_page = -1;
|
var last_page = -1;
|
||||||
for (var i in pl) {
|
for (var i in pl) {
|
||||||
if (pl[i].$p.offset().top > y_center)
|
if (pl[i].$p.offset().top > y_center)
|
||||||
break;
|
break;
|
||||||
last_page = i;
|
last_page = i;
|
||||||
}
|
}
|
||||||
return pl[last_page];
|
return pl[last_page];
|
||||||
},
|
},
|
||||||
|
|
||||||
get_containing_page : function(obj) {
|
get_containing_page : function(obj) {
|
||||||
@ -476,7 +549,7 @@ var pdf2htmlEX = (function(){
|
|||||||
switch(detail[1]) {
|
switch(detail[1]) {
|
||||||
case 'XYZ':
|
case 'XYZ':
|
||||||
pos = [(detail[2] == null) ? cur_pos[0] : detail[2]
|
pos = [(detail[2] == null) ? cur_pos[0] : detail[2]
|
||||||
,(detail[3] == null) ? cur_pos[1] : detail[3]];
|
,(detail[3] == null) ? cur_pos[1] : detail[3]];
|
||||||
ok = true;
|
ok = true;
|
||||||
break;
|
break;
|
||||||
case 'Fit':
|
case 'Fit':
|
||||||
@ -529,12 +602,15 @@ var pdf2htmlEX = (function(){
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/* pos=[x,y], where (0,0) is the top-left corner */
|
/* pos=[x,y], where (0,0) is the top-left corner */
|
||||||
scroll_to : function(pageno, pos) {
|
scroll_to : function(pageno, pos) {
|
||||||
var target_page = this.pages[pageno];
|
var target_page = this.pages[pageno];
|
||||||
if(target_page == undefined) return;
|
if(target_page == undefined) return;
|
||||||
|
|
||||||
|
if(pos == undefined)
|
||||||
|
pos = [0,0];
|
||||||
|
|
||||||
var cur_target_pos = target_page.position();
|
var cur_target_pos = target_page.position();
|
||||||
|
|
||||||
this.$container.scrollLeft(this.$container.scrollLeft()-cur_target_pos[0]+pos[0]);
|
this.$container.scrollLeft(this.$container.scrollLeft()-cur_target_pos[0]+pos[0]);
|
||||||
|
Loading…
Reference in New Issue
Block a user