1 /********************************************************/ 2 /** HERE MAIN MODIFIED PART FOR turnjs SUPPORT **/ 3/********************************************************/ 4/// requires jQuery and turnjs 5/// all code added in viewer.js (from pdfjs build) in order to support 6/// flipbook is commented with 'jQueryFB:' string to allow to find it easilly 7 8var bookFlip = { 9 _width: [], //flipbook pages width 10 _height: [], //flipbook pages height 11 active: false, //flipbook mode on 12 _spreadBk: NaN, //spread mode backup to restore 13 _evSpread: null,//spread mode changed default event handler 14 _spread: NaN, //spread page mode 15 toStart: false, //PDFjs require flipbook at start 16 _intoView: null,//link handler default function 17 _visPages: null,//visible pages function 18 _ready: false, //ready to start flipbook 19 20 // event listeners when bookFlip need different handling 21 init: function(){ 22 jQuery(document).on('rotationchanging', () => {this.rotate()}); 23 jQuery(document).on('scalechanging', () => {this.resize()}); 24 jQuery(document).on('pagechanging', () => {this.flip()}); 25 //jQuery(document).on('pagenumberchanged', () => {this.flip()}); 26 27 jQuery(document).on('documentinit', () => { 28 this.stop(); 29 this._ready = false; 30 }); 31 32 jQuery(document).on('scrollmodechanged', () => { 33 var scroll = PDFViewerApplication.pdfViewer.scrollMode; 34 if (scroll === 3)this.start(); 35 else this.stop(); 36 var button = PDFViewerApplication.appConfig.secondaryToolbar.bookFlipButton; 37 button.classList.toggle('toggled', scroll === 3); 38 }); 39 40 jQuery(document).on('presentationmodechanged', () => { 41 var new_pres_mode = PDFViewerApplication.pdfViewer.presentationModeState; 42 43 if( new_pres_mode == 2){ 44 this.spread(0); 45 PDFViewerApplication.eventBus.dispatch('spreadmodechanged', { 46 source: PDFViewerApplication, 47 mode: 0 48 }); 49 } else if( new_pres_mode == 1 ) { 50 this.spread(tnc_spread_default); 51 PDFViewerApplication.eventBus.dispatch('spreadmodechanged', { 52 source: PDFViewerApplication, 53 mode: tnc_spread_default 54 }); 55 } 56 }); 57 58 jQuery(document).on('switchspreadmode', (evt) => { 59 this.spread(evt.originalEvent.detail.mode); 60 PDFViewerApplication.eventBus.dispatch('spreadmodechanged', { 61 source: PDFViewerApplication, 62 mode: evt.originalEvent.detail.mode 63 }); 64 }); 65 66 jQuery(document).on('pagesloaded', () => { 67 this._ready = true; 68 if(this.toStart){ 69 this.toStart = false;
70 PDFViewerApplication.pdfViewer.scrollMode = 3; 71 } 72 }); 73 74 jQuery(document).on('baseviewerinit', () => { 75 76 PDFViewerApplicationOptions.set('scrollModeOnLoad',3); 77 78 this._intoView = PDFViewerApplication.pdfViewer.scrollPageIntoView; 79 this._visPages = PDFViewerApplication.pdfViewer._getVisiblePages; 80 }); 81 }, 82 // startup flipbook 83 start: function(){ 84 if(this.active || !this._ready)return; 85 this.active = true; 86 87 var viewer = PDFViewerApplication.pdfViewer; 88 89 jQuery('.scrollModeButtons').removeClass('toggled'); 90 jQuery("#pvfw-next-page").hide(); 91 jQuery("#pvfw-previous-page").hide(); 92 jQuery("#pvfw-flip-next-page").show(); 93 jQuery("#pvfw-flip-previous-page").show(); 94 95 this._spreadBk = tnc_spread_default; 96 // this._spreadBk = viewer.spreadMode; 97 var selected = jQuery('.spreadModeButtons.toggled').attr('id'); 98 // this._spread = (this._spreadBk !== 2) ? 0 : 2; 99 this._spread = this._spreadBk; 100 viewer.spreadMode = 0; 101 viewer._spreadMode = -1; 102 jQuery('.spreadModeButtons').removeClass('toggled'); 103 jQuery('#' + selected).addClass('toggled'); 104 105 this._evSpread = PDFViewerApplication.eventBus._listeners.switchspreadmode; 106 PDFViewerApplication.eventBus._listeners.switchspreadmode = null; 107 108 viewer.scrollPageIntoView = (data) => {return this.link(data)}; 109 viewer._getVisiblePages = () => {return this.load()}; 110 111 var scale = viewer.currentScale; 112 113 var parent = this; 114 jQuery('#viewer .page').each(function(){ 115 // Hard 116 jQuery(this).addClass(tnc_flip_type); 117 parent._width[jQuery(this).attr('data-page-number')] = jQuery(this).width() / scale; 118 parent._height[jQuery(this).attr('data-page-number')] = jQuery(this).height() / scale; 119 }); 120 121 jQuery('#viewer').removeClass('pdfViewer').addClass('bookViewer').css({ opacity: 1 });; 122 123 // jQuery('#spreadOdd').prop('disabled', true); 124 // var pages = PDFViewerApplication.pagesCount; 125 // for(var page = 3; page < pages + (pages%2); page ++){ 126 // if(this._height[page]!=this._height[page-1] || this._width[page]!=this._width[page-1]){ 127 // jQuery('#spreadEven').prop('disabled', true); 128 // this._spread = 0; 129 // } 130 // } 131 if(window.location.hash) { 132 var hash = window.location.hash.substr(1); 133 134 var hash_param = hash.split('&').reduce(function (res, item) { 135 var parts = item.split('='); 136 res[parts[0]] = parts[1]; 137 return res; 138 }, {}); 139 if( hash_param.page ){ 140 page_to_open = hash_param.page; 141 } else { 142 page_to_open = PDFViewerApplication.page; 143 } 144 } else { 145 page_to_open = PDFViewerApplication.page; 146 } 147 jQuery('#viewer').turn({ 148 elevation: 50, 149 width: this._size(PDFViewerApplication.page,'width') * this._spreadMult(), 150 height: this._size(PDFViewerApplication.page,'height'), 151 //duration 152 duration:tnc_page_turning_speed, 153 page: page_to_open, 154 when: { 155 turning: function(event, page, view) { 156 var audio = document.getElementById("audio"); 157 var $btn = jQuery('#pvfw-sound-on-off'); 158 159 if ($btn.hasClass('enable')) { 160 audio.currentTime = 0; // Reset audio to beginning 161 audio.play().catch(function(err) { 162 console.warn('Audio play error:', err); 163 }); 164 } 165 }, 166 turned: function(event, page) { 167 var numPages = PDFViewerApplication.pagesCount; 168 if((page > numPages) || (page < 1)){ 169 return; 170 } 171 PDFViewerApplication.page = page; 172 //PDFViewerApplication.page = page; 173 viewer.update(); 174 }, 175 }, 176 display: this._spreadType() 177 }); 178 this.resize(); 179 }, 180 // shutdown flipbook 181 stop: function(){ 182 if(!this.active)return; 183 this.active = false; 184 185 var viewer = PDFViewerApplication.pdfViewer; 186 187 jQuery('#viewer').turn('destroy'); 188 189 viewer.scrollPageIntoView = this._intoView; 190 viewer._getVisiblePages = this._visPages; 191 192 PDFViewerApplication.eventBus._listeners.switchspreadmode = this._evSpread; 193 viewer.spreadMode = this._spreadBk; 194 195 jQuery("#pvfw-next-page").show(); 196 jQuery("#pvfw-previous-page").show(); 197 jQuery("#pvfw-flip-next-page").hide(); 198 jQuery("#pvfw-flip-previous-page").hide(); 199 200 jQuery('#viewer .page').removeAttr('style'); 201 jQuery('#viewer').removeAttr('style').removeClass('shadow bookViewer').addClass('pdfViewer'); 202
203 var parent = this; 204 jQuery('#viewer .page').each(function(){ 205 var page = jQuery(this).attr('data-page-number'); 206 jQuery(this).css( 'width', parent._size(page,'width')).css( 'height', parent._size(page,'height')); 207 }); 208 209 }, 210 // resize flipbook pages 211 resize: function(){ 212 if(!this.active)return; 213 var viewer = PDFViewerApplication.pdfViewer; 214 215 var page = PDFViewerApplication.page; 216 var page_width = this._size(page,'width') * this._spreadMult(); 217 var page_height = this._size(page,'height'); 218 var window_width = window.innerWidth; 219 var window_height = window.innerHeight; 220 var viewerHeight = document.getElementById("viewerContainer").offsetHeight; 221 222 var scale = viewer.currentScale; 223 224 var pageWidthScale = parseFloat((window_width - 35 ) / page_width * scale); 225 var pageHeightScale = parseFloat(( viewerHeight ) / page_height * scale); 226 var flip_scale_max = Math.max(pageWidthScale, pageHeightScale); 227 var flip_scale_min = Math.min(pageWidthScale, pageHeightScale); 228 229 if( window.innerWidth < 600 ){ 230 if( viewer.currentScale < flip_scale_min){ 231 viewer.currentScale = flip_scale_min; 232 } 233 } else { 234 let tncPvfwScaleSelectValue = jQuery('#scaleSelect').val(); 235 let tncPvfwScaleAllValue = [ 'page-fit' ]; 236 if (jQuery.inArray(tncPvfwScaleSelectValue, tncPvfwScaleAllValue) !== -1 ) { 237 viewer.currentScale = flip_scale_min; 238 } else { 239 viewer.currentScale = scale; 240 } 241 } 242 243 244 var page_width = this._size(page,'width') * this._spreadMult(); 245 var page_height = this._size(page,'height'); 246 247 jQuery('#viewer').turn('size', page_width, page_height); 248 }, 249 // rotate flipbook pages 250 rotate: function(){ 251 if(!this.active)return; 252 [this._height, this._width] = [this._width, this._height]; 253 this.resize(); 254 }, 255 // change flipbook spread mode 256 spread: function(spreadMode){ 257 if(!this.active)return; 258 this._spread = spreadMode; 259 var viewer = PDFViewerApplication.pdfViewer; 260 jQuery('#viewer').turn('display', this._spreadType()); 261 this.resize(); 262 }, 263 // turn page 264 flip: function(){ 265 if(!this.active)return; 266 var $viewer = jQuery('#viewer'); 267 $viewer.turn('page', PDFViewerApplication.page); 268 if(!PDFViewerApplication.pdfViewer.hasEqualPageSizes){ 269 // turn('size') inside resize() stops the running flip animation, so 270 // 'turned' never fires and the new pages never render. Resize after. 271 if($viewer.turn('animating')) $viewer.one('turned', () => this.resize()); 272 else this.resize(); 273 } 274 }, 275 // follow internal links 276 link: function(data){ 277 if(!this.active)return; 278 PDFViewerApplication.page = data.pageNumber; 279 }, 280 // load pages near shown page 281 load: function(){ 282 if(!this.active)return; 283 var views = PDFViewerApplication.pdfViewer._pages; 284 var arr = []; 285 var page = PDFViewerApplication.page; 286 var min = Math.max(page - ((this._spread === 0) ? 2 : 3 + (page%2)), 0); 287 var max = Math.min(page + ((this._spread === 0) ? 1 : 3 - (page%2)), views.length); 288 for (var i = min, ii = max; i < ii; i++) 289 { 290 arr.push({ 291 id: views[i].id, 292 view: views[i], 293 x: 0, y: 0, percent: 100 294 }); 295 } 296 297 let t= { first:arr[page - min - 1], last:arr[arr.length-1], views:arr }; 298 return t; 299 }, 300 _spreadType: function(){ 301 if( tnc_same_mobile_spread == '1' ){ 302 return (this._spread === 0) ? 'single' : 'double'; 303 } else { 304 if(window.innerWidth < 600){ 305 return 'single'; 306 } else { 307 return (this._spread === 0) ? 'single' : 'double'; 308 } 309 } 310 }, 311 _spreadMult: function(){ 312 if( tnc_same_mobile_spread == '1' ){ 313 return (this._spread === 0) ? 1 : 2; 314 } else { 315 if(window.innerWidth < 600){ 316 return 1; 317 } else { 318 return (this._spread === 0) ? 1 : 2; 319 } 320 } 321 }, 322 _size: function(page,request){ 323 var size; 324 if (request === 'width') size = this._width[page]; 325 if (request === 'height') size = this._height[page]; 326 return size * PDFViewerApplication.pdfViewer.currentScale; 327 } 328}; 329 330bookFlip.init();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.