1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-07-05 01:28:39 +00:00
This commit is contained in:
Lu Wang 2013-11-01 15:34:18 +08:00
parent ac0e8ab893
commit a0f602c6b0

View File

@ -106,11 +106,13 @@
this.loaded = false; this.loaded = false;
this.shown = false; this.shown = false;
this.$p = $(page); this.$p = $(page); // page frame element
this.$container = $(container); this.$container = $(container);
this.n = parseInt(this.$p.data('page-no'), 16); this.n = parseInt(this.$p.data('page-no'), 16);
// content box
this.$b = $('.'+CSS_CLASS_NAMES.page_content_box, this.$p); this.$b = $('.'+CSS_CLASS_NAMES.page_content_box, this.$p);
// decoration
this.$d = this.$p.parent('.'+CSS_CLASS_NAMES.page_decoration); this.$d = this.$p.parent('.'+CSS_CLASS_NAMES.page_decoration);
// page size // page size
@ -177,12 +179,14 @@
/* return if this page or any neighbor of it is visible */ /* return if this page or any neighbor of it is visible */
is_nearly_visible : function() { is_nearly_visible : function() {
var off = this.position(); var off = this.position();
/* I should use the height of the previous page or the next page here /*
* I should use the height of the previous page or the next page here
* but since they are not easily available, just use '*2', which should be a good estimate in most cases * but since they are not easily available, just use '*2', which should be a good estimate in most cases
*/ */
return !((off[1] > this.h * 2) || (off[1] + this.$container.height() * 2 < 0)); return !((off[1] > this.h * 2) || (off[1] + this.$container.height() * 2 < 0));
}, },
/* return the coordinate of the top-left corner of container /*
* return the coordinate of the top-left corner of container
* in our coordinate system * in our coordinate system
*/ */
position : function () { position : function () {
@ -265,48 +269,51 @@
if (idx >= pages.length) if (idx >= pages.length)
return; // Page does not exist return; // Page does not exist
if (pages[idx].loaded) var cur_page = pages[idx];
if (cur_page.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 = pages[idx].n.toString(16); var page_no_hex = cur_page.n.toString(16);
var $pf = this.$container.find('#' + CSS_CLASS_NAMES.page_frame + page_no_hex); var $pf = cur_page.$p;
if($pf.length == 0)
return; // Page does not exist
this.$loading_indicator.clone().show().appendTo($pf); this.$loading_indicator.clone().show().appendTo($pf);
var _ = this;
var url = $pf.data('page-url'); var url = $pf.data('page-url');
if (url && url.length > 0) { if (url) {
this.pages_loading[idx] = true; // Set semaphore this.pages_loading[idx] = true; // Set semaphore
/* closure variables */
var _ = this;
var _idx = idx;
$.ajax({ $.ajax({
url: url, url: url,
dataType: 'text' dataType: 'text'
}).done(function(data){ }).done(function(data){
// replace the old page with loaded data // replace the old page with loaded data
// the loading indicator on this page should also be destroyed // the loading indicator on this page should also be destroyed
_.pages[idx].$d.replaceWith(data); var p = _.pages[idx];
p.$d.replaceWith(data);
var $new_pf = _.$container.find('#' + CSS_CLASS_NAMES.page_frame + page_no_hex); var $new_pf = p.find('.' + CSS_CLASS_NAMES.page_frame);
_.pages[idx] = new Page($new_pf, _.$container); p = new Page($new_pf, _.$container);
_.pages[idx].hide(); p.hide();
_.pages[idx].rescale(_.scale); p.rescale(_.scale);
_.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;});
_.pages[idx] = p;
_.schedule_render();
// Reset loading token // Reset loading token
delete _.pages_loading[idx]; delete _.pages_loading[idx];
if (successCallback) successCallback(_.pages[idx]); if (successCallback) successCallback(_.pages[idx]);
} }).fail(function(jqXHR, textStatus, errorThrown){
).fail(function(jqXHR, textStatus, errorThrown){
// Reset loading token // Reset loading token
delete _.pages_loading[idx]; delete _.pages_loading[idx];
@ -318,7 +325,7 @@
pages_to_preload = this.config['preload_pages']; pages_to_preload = this.config['preload_pages'];
if (--pages_to_preload > 0) if (--pages_to_preload > 0)
_.load_page(idx+1, pages_to_preload); this.load_page(idx+1, pages_to_preload);
}, },
pre_hide_pages : function() { pre_hide_pages : function() {
@ -334,12 +341,6 @@
document.getElementsByTagName('head')[0].appendChild(n); document.getElementsByTagName('head')[0].appendChild(n);
}, },
hide_pages : function() {
var pl = this.pages;
for(var i = 0, l = pl.length; i < l; ++i)
pl[i].hide();
},
render : function () { render : function () {
/* hide (positional) invisible pages */ /* hide (positional) invisible pages */
var pl = this.pages; var pl = this.pages;