1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 13:00:08 +00:00

add dollar sign for jquery objects

This commit is contained in:
Lu Wang 2013-06-13 23:00:42 +08:00
parent b6df9d5763
commit 3b3efb6845

View File

@ -42,19 +42,18 @@ var pdf2htmlEX = (function(){
if(page == undefined) return;
this.loaded = false;
this.p = $(page);
this.$p = $(page);
this.$container = $(container);
this.container = container;
this.n = parseInt(this.$p.data('page-no'), 16);
this.$b = $('.'+CSS_CLASS_NAMES['page_content_box'], this.$p);
this.$d = this.$p.parents('.'+CSS_CLASS_NAMES['page_decoration']);
this.n = parseInt(this.p.attr('data-page-no'), 16);
this.b = $('.'+CSS_CLASS_NAMES['page_content_box'], this.p);
this.d = this.p.parents('.'+CSS_CLASS_NAMES['page_decoration']);
this.h = this.p.height(); // Need to make rescale work when page_content_box is not loaded, yet
this.w = this.p.width();
this.h = this.$p.height(); // Need to make rescale work when page_content_box is not loaded, yet
this.w = this.$p.width();
// if page is loaded
if (this.b[0]) {
if (this.$b.length > 0) {
/*
* scale ratios
*
@ -62,9 +61,9 @@ var pdf2htmlEX = (function(){
* set_r : last set
* cur_r : currently using
*/
this.default_r = this.set_r = this.cur_r = this.p.height() / this.b.height();
this.default_r = this.set_r = this.cur_r = this.$p.height() / this.$b.height();
this.data = JSON.parse($($('.'+CSS_CLASS_NAMES['page_data'], this.p)[0]).attr('data-data'));
this.data = JSON.parse($($('.'+CSS_CLASS_NAMES['page_data'], this.$p)[0]).data('data'));
this.ctm = this.data.ctm;
this.ictm = invert(this.ctm);
@ -75,15 +74,14 @@ var pdf2htmlEX = (function(){
$.extend(Page.prototype, {
/* hide & show are for contents, the page frame is still there */
hide : function(){
this.b.removeClass('opened');
this.$b.removeClass('opened');
},
show : function(){
if(Math.abs(this.set_r - this.cur_r) > EPS) {
this.cur_r = this.set_r;
//TODO make it cross-browser compliant
this.b.css('transform', 'scale('+this.cur_r.toFixed(3)+')');
this.$b.css('transform', 'scale('+this.cur_r.toFixed(3)+')');
}
this.b.addClass('opened');
this.$b.addClass('opened');
},
rescale : function(ratio, is_relative) {
if(ratio == 0) {
@ -97,13 +95,13 @@ var pdf2htmlEX = (function(){
/* wait for redraw */
this.hide();
this.p.height(this.b.height() * this.set_r);
this.p.width(this.b.width() * this.set_r);
this.$p.height(this.$b.height() * this.set_r);
this.$p.width(this.$b.width() * this.set_r);
},
/* return if any part of this page is shown in the container */
is_visible : function() {
var off = this.position();
return !((off[1] > this.height()) || (off[1] + this.container.height() < 0));
return !((off[1] > this.height()) || (off[1] + this.$container.height() < 0));
},
/* return if this page or any neighbor of it is visible */
is_nearly_visible : function() {
@ -111,18 +109,18 @@ var pdf2htmlEX = (function(){
/* 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
*/
return !((off[1] > this.height() * 2) || (off[1] + this.container.height() * 2 < 0));
return !((off[1] > this.height() * 2) || (off[1] + this.$container.height() * 2 < 0));
},
/* return the coordinate of the top-left corner of container
* in our cooridnate system
*/
position : function () {
var off = this.p.offset();
var off_c = this.container.offset();
var off = this.$p.offset();
var off_c = this.$container.offset();
return [off_c.left-off.left, off_c.top-off.top];
},
height : function() {
return this.p.height();
return this.$p.height();
}
});
@ -147,39 +145,42 @@ var pdf2htmlEX = (function(){
/*hide all pages before loading, will reveal only visible ones later */
this.pre_hide_pages();
},
init_after_loading_content : function() {
this.sidebar = $('#'+this.sidebar_id);
this.outline = $('#'+this.outline_id);
this.container = $('#'+this.container_id);
this.$sidebar = $('#'+this.sidebar_id);
this.$outline = $('#'+this.outline_id);
this.$container = $('#'+this.container_id);
// Open the outline if nonempty
if(this.outline.children().length > 0) {
this.sidebar.addClass('opened');
if(this.$outline.children().length > 0) {
this.$sidebar.addClass('opened');
}
this.find_pages();
// register schedule rendering
var _ = this;
this.container.scroll(function(){ _.schedule_render(); });
this.$container.scroll(function(){ _.schedule_render(); });
//this.zoom_fixer();
// 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);
this.render();
},
find_pages : function() {
var new_pages = new Array();
var pl= $('.'+CSS_CLASS_NAMES['page_frame'], this.container);
var $pl= $('.'+CSS_CLASS_NAMES['page_frame'], this.$container);
/* don't use for(..in..) */
for(var i = 0, l = pl.length; i < l; ++i) {
var p = new Page(pl[i], this.container);
for(var i = 0, l = $pl.length; i < l; ++i) {
var p = new Page($pl[i], this.$container);
new_pages[p.n] = p;
}
this.pages = new_pages;
},
load_page : function(idx, pages_to_preload, successCallback, errorCallback) {
if (idx >= this.pages.length)
return; // Page does not exist
@ -191,7 +192,7 @@ var pdf2htmlEX = (function(){
return; // Page is already loading
var page_no_hex = idx.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)
return; // Page does not exist
@ -205,10 +206,10 @@ var pdf2htmlEX = (function(){
url: url,
dataType: 'text'
}).done(function(data){
_.pages[idx].p.parent().replaceWith(data);
_.pages[idx].$p.parent().replaceWith(data);
var $new_pf = _.container.find('#' + CSS_CLASS_NAMES['page_frame'] + page_no_hex);
_.pages[idx] = new Page($new_pf, _.container);
var $new_pf = _.$container.find('#' + CSS_CLASS_NAMES['page_frame'] + page_no_hex);
_.pages[idx] = new Page($new_pf, _.$container);
_.pages[idx].rescale(_.scale);
_.schedule_render();
@ -235,8 +236,8 @@ var pdf2htmlEX = (function(){
if (--pages_to_preload > 0)
_.load_page(idx+1, pages_to_preload);
},
pre_hide_pages : function() {
/* pages might have not been loaded yet, so add a CSS rule */
var s = '@media screen{.'+CSS_CLASS_NAMES['page_content_box']+'{display:none;}}';
@ -429,8 +430,8 @@ var pdf2htmlEX = (function(){
var cur_target_pos = target_page.position();
this.container.scrollLeft(this.container.scrollLeft()-cur_target_pos[0]+pos[0]);
this.container.scrollTop(this.container.scrollTop()-cur_target_pos[1]+pos[1]);
this.$container.scrollLeft(this.$container.scrollLeft()-cur_target_pos[0]+pos[0]);
this.$container.scrollTop(this.$container.scrollTop()-cur_target_pos[1]+pos[1]);
},
__last_member__ : 'no comma' /*,*/