diff --git a/CMakeLists.txt b/CMakeLists.txt index 49501a0..6f558cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -231,7 +231,12 @@ target_link_libraries(pdf2htmlEX ${PDF2HTMLEX_LIBS}) add_custom_target(pdf2htmlEX.js ALL DEPENDS ${CMAKE_SOURCE_DIR}/share/pdf2htmlEX.js) add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/share/pdf2htmlEX.js - COMMAND ${CMAKE_SOURCE_DIR}/share/js_src/compile.sh) + COMMAND ${CMAKE_SOURCE_DIR}/share/js_src/compile.sh + DEPENDS + ${CMAKE_SOURCE_DIR}/share/js_src/css_class_names.js + ${CMAKE_SOURCE_DIR}/share/js_src/header.js + ${CMAKE_SOURCE_DIR}/share/js_src/viewer.js + ) install (TARGETS pdf2htmlEX DESTINATION bin) file (GLOB datafiles diff --git a/share/js_src/compile.sh b/share/js_src/compile.sh index cfb2f63..ced9016 100755 --- a/share/js_src/compile.sh +++ b/share/js_src/compile.sh @@ -9,7 +9,7 @@ BASEDIR=$(dirname $0) OUTPUT="$BASEDIR/../pdf2htmlEX.js" -(echo 'Compiling pdf2htmlEX.js with closure-compiler...' && \ +(echo 'Building pdf2htmlEX.js with closure-compiler...' && \ tmpfile=$(mktemp 2>/dev/null) && \ java -jar "$BASEDIR/../../3rdparty/closure-compiler/compiler.jar" --compilation_level ADVANCED_OPTIMIZATIONS --process_jquery_primitives --externs "$BASEDIR/../jquery.js" --js "$BASEDIR/css_class_names.js" --js "$BASEDIR/viewer.js" > "$tmpfile" 2>/dev/null && \ cat "$BASEDIR/header.js" "$tmpfile" > "$OUTPUT" && \ diff --git a/share/js_src/viewer.js b/share/js_src/viewer.js index 8fc34bc..8c49ffb 100644 --- a/share/js_src/viewer.js +++ b/share/js_src/viewer.js @@ -11,6 +11,25 @@ * css_class_names.js */ +/* + * Attention: + * This files is to be optimized by closure-compiler, + * so pay attention to the forms of property names: + * + * string/bracket form is safe, won't be optimized: + * var obj={ 'a':'b' }; obj['a'] = 'b'; + * name/dot form will be optimized, the name is likely to be modified: + * var obj={ a:'b' }; obj.a = 'b'; + * + * Either form can be used for internal objects, + * but must be consistent for each one respectively. + * + * string/bracket form must be used for external objects + * e.g. DEFAULT_CONFIG, object stored in page-data + * property names are part of the `protocol` in these cases. + * + */ + 'use strict'; /* The namespace */ @@ -26,7 +45,7 @@ // id of the element for outline 'outline_id' : 'outline', // class for the loading indicator - 'loading_indicator_cls' : 'loading_indicator_cls', + 'loading_indicator_cls' : 'loading-indicator', // How many page shall we preload that are below the last visible page 'preload_pages' : 3, // Smooth zoom is enabled when the number of pages shown is less than the threshold @@ -66,8 +85,8 @@ 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.parent('.'+CSS_CLASS_NAMES['page_decoration']); + this.$b = $('.'+CSS_CLASS_NAMES.page_content_box, this.$p); + this.$d = this.$p.parent('.'+CSS_CLASS_NAMES.page_decoration); // page size // Need to make rescale work when page_content_box is not loaded, yet @@ -84,10 +103,9 @@ * cur_r : currently using */ this.default_r = this.set_r = this.cur_r = this.h / this.$b.height(); + this.page_data = $($('.'+CSS_CLASS_NAMES.page_data, this.$p)[0]).data('data'); - this.data = $($('.'+CSS_CLASS_NAMES['page_data'], this.$p)[0]).data('data'); - - this.ctm = this.data.ctm; + this.ctm = this.page_data['ctm']; this.ictm = invert(this.ctm); this.loaded = true; @@ -187,14 +205,14 @@ //this.register_key_handler(); // 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..) since $pl is more than an Array */ for(var i = 0, l = $pl.length; i < l; ++i) { var p = new Page($pl[i], this.$container); @@ -214,7 +232,7 @@ 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 @@ -234,14 +252,14 @@ // the loading indicator on this page should also be destroyed _.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].hide(); _.pages[idx].rescale(_.scale); _.schedule_render(); // 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 delete _.pages_loading[idx]; @@ -267,7 +285,7 @@ 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;}}'; + var s = '@media screen{.'+CSS_CLASS_NAMES.page_content_box+'{display:none;}}'; var n = document.createElement('style'); n.type = 'text/css'; if (n.styleSheet) { @@ -513,7 +531,7 @@ get_containing_page : function(obj) { /* get the page obj containing obj */ - var p = obj.closest('.'+CSS_CLASS_NAMES['page_frame'])[0]; + var p = obj.closest('.'+CSS_CLASS_NAMES.page_frame)[0]; return p && this.pages[(new Page(p)).n]; },