mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-21 20:50:07 +00:00
fix js
This commit is contained in:
parent
7787b26e5b
commit
cc79880d57
1
TODO
1
TODO
@ -1,3 +1,4 @@
|
|||||||
|
page idx vs no
|
||||||
move $container outside Page
|
move $container outside Page
|
||||||
tracking current page
|
tracking current page
|
||||||
more js annoatation
|
more js annoatation
|
||||||
|
@ -193,7 +193,7 @@
|
|||||||
*/
|
*/
|
||||||
function Viewer(config) {
|
function Viewer(config) {
|
||||||
/* do nothing if jQuery is not ready */
|
/* do nothing if jQuery is not ready */
|
||||||
if(!window.jQuery) return;
|
if(!jQuery) return;
|
||||||
|
|
||||||
this.config = $.extend({}, DEFAULT_CONFIG, config);
|
this.config = $.extend({}, DEFAULT_CONFIG, config);
|
||||||
this.pages_loading = [];
|
this.pages_loading = [];
|
||||||
@ -248,24 +248,25 @@
|
|||||||
/* don't use for(..in..) since $pl is more than an Array */
|
/* don't use for(..in..) since $pl is more than an Array */
|
||||||
for(var i = 0, l = $pl.length; i < l; ++i) {
|
for(var i = 0, l = $pl.length; i < l; ++i) {
|
||||||
var p = new Page($pl[i], this.$container);
|
var p = new Page($pl[i], this.$container);
|
||||||
|
new_page_map[p.n] = i;
|
||||||
new_pages.push(p);
|
new_pages.push(p);
|
||||||
new_page_map[p.n] = p;
|
|
||||||
}
|
}
|
||||||
this.pages = new_pages;
|
this.pages = new_pages;
|
||||||
this.page_map = new_page_map;
|
this.page_map = new_page_map;
|
||||||
},
|
},
|
||||||
|
|
||||||
load_page : function(idx, pages_to_preload, successCallback, errorCallback) {
|
load_page : function(idx, pages_to_preload, successCallback, errorCallback) {
|
||||||
if (idx >= this.pages.length)
|
var pages = this.pages;
|
||||||
|
if (idx >= pages.length)
|
||||||
return; // Page does not exist
|
return; // Page does not exist
|
||||||
|
|
||||||
if (this.pages[idx].loaded)
|
if (pages[idx].loaded)
|
||||||
return; // Page is loaded
|
return; // Page is loaded
|
||||||
|
|
||||||
if (this.pages_loading[idx])
|
if (this.pages_loading[idx])
|
||||||
return; // Page is already loading
|
return; // Page is already loading
|
||||||
|
|
||||||
var page_no_hex = idx.toString(16);
|
var page_no_hex = pages[idx].n.toString(16);
|
||||||
var $pf = this.$container.find('#' + CSS_CLASS_NAMES.page_frame + page_no_hex);
|
var $pf = this.$container.find('#' + CSS_CLASS_NAMES.page_frame + page_no_hex);
|
||||||
if($pf.length == 0)
|
if($pf.length == 0)
|
||||||
return; // Page does not exist
|
return; // Page does not exist
|
||||||
@ -298,7 +299,7 @@
|
|||||||
// Reset loading token
|
// Reset loading token
|
||||||
delete _.pages_loading[idx];
|
delete _.pages_loading[idx];
|
||||||
|
|
||||||
if (successCallback) successCallback();
|
if (successCallback) successCallback(_.pages[idx]);
|
||||||
}
|
}
|
||||||
).fail(function(jqXHR, textStatus, errorThrown){
|
).fail(function(jqXHR, textStatus, errorThrown){
|
||||||
// Reset loading token
|
// Reset loading token
|
||||||
@ -337,13 +338,14 @@
|
|||||||
render : function () {
|
render : function () {
|
||||||
/* hide (positional) invisible pages */
|
/* hide (positional) invisible pages */
|
||||||
var pl = this.pages;
|
var pl = this.pages;
|
||||||
|
var pm = this.page_map;
|
||||||
for(var i = 0, l = pl.length; i < l; ++i) {
|
for(var i = 0, l = pl.length; i < l; ++i) {
|
||||||
var p = pl[i];
|
var p = pl[i];
|
||||||
if(p.is_nearly_visible()){
|
if(p.is_nearly_visible()){
|
||||||
if (p.loaded) {
|
if (p.loaded) {
|
||||||
p.show();
|
p.show();
|
||||||
} else
|
} else
|
||||||
this.load_page(p.n);
|
this.load_page(pm[p.n]);
|
||||||
} else {
|
} else {
|
||||||
p.hide();
|
p.hide();
|
||||||
}
|
}
|
||||||
@ -470,7 +472,8 @@
|
|||||||
// Immediate rendering optimizations enabled to improve reactiveness while zooming
|
// Immediate rendering optimizations enabled to improve reactiveness while zooming
|
||||||
// Find out which pages are visible
|
// Find out which pages are visible
|
||||||
var min_visible, max_visible;
|
var min_visible, max_visible;
|
||||||
min_visible = max_visible = active_page.n;
|
// TODO: page index
|
||||||
|
min_visible = max_visible = this.page_map[active_page.n];
|
||||||
while (pl[min_visible] && pl[min_visible].is_visible()) { --min_visible; }
|
while (pl[min_visible] && pl[min_visible].is_visible()) { --min_visible; }
|
||||||
++ min_visible;
|
++ min_visible;
|
||||||
while (pl[max_visible] && pl[max_visible].is_visible()) { ++max_visible; }
|
while (pl[max_visible] && pl[max_visible].is_visible()) { ++max_visible; }
|
||||||
@ -515,7 +518,7 @@
|
|||||||
if(!active_page) return;
|
if(!active_page) return;
|
||||||
|
|
||||||
this.rescale(this.$container.width() / active_page.w, false);
|
this.rescale(this.$container.width() / active_page.w, false);
|
||||||
this.scroll_to(active_page.n, [0,0]);
|
this.scroll_to(this.page_map[active_page.n], [0,0]);
|
||||||
},
|
},
|
||||||
|
|
||||||
fit_height : function () {
|
fit_height : function () {
|
||||||
@ -523,7 +526,7 @@
|
|||||||
if(!active_page) return;
|
if(!active_page) return;
|
||||||
|
|
||||||
this.rescale(this.$container.height() / active_page.h, false);
|
this.rescale(this.$container.height() / active_page.h, false);
|
||||||
this.scroll_to(active_page.n, [0,0]);
|
this.scroll_to(this.page_map[active_page.n], [0,0]);
|
||||||
},
|
},
|
||||||
|
|
||||||
get_active_page : function () {
|
get_active_page : function () {
|
||||||
@ -629,7 +632,7 @@
|
|||||||
transform_and_scroll(target_page);
|
transform_and_scroll(target_page);
|
||||||
} else {
|
} else {
|
||||||
// Scroll to the exact position once loaded.
|
// Scroll to the exact position once loaded.
|
||||||
_.load_page(target_page.n, undefined, transform_and_scroll);
|
_.load_page(target_page_idx, undefined, transform_and_scroll);
|
||||||
|
|
||||||
// In the meantime page gets loaded, scroll approximately position for maximum responsiveness.
|
// In the meantime page gets loaded, scroll approximately position for maximum responsiveness.
|
||||||
_.scroll_to(target_page_idx, [0,0]);
|
_.scroll_to(target_page_idx, [0,0]);
|
||||||
|
Loading…
Reference in New Issue
Block a user