From 33946f1da747234db2235a5ae0e803096e60fc84 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 8 Mar 2018 11:42:40 +0100 Subject: [PATCH] #819 --- js/libs/fluidbook/fluidbook.js | 52 +++++++++++++++++--------- js/libs/fluidbook/fluidbook.nav.js | 2 +- js/libs/fluidbook/fluidbook.support.js | 2 + 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/js/libs/fluidbook/fluidbook.js b/js/libs/fluidbook/fluidbook.js index 686daa37..42c00c69 100644 --- a/js/libs/fluidbook/fluidbook.js +++ b/js/libs/fluidbook/fluidbook.js @@ -153,11 +153,11 @@ Fluidbook.prototype = { }, - onReady: function(callback) { + onReady: function (callback) { if (this.isReady) { callback(); } else { - $(this).on('fluidbook.ready', function() { + $(this).on('fluidbook.ready', function () { callback(); }); } @@ -785,9 +785,9 @@ Fluidbook.prototype = { } if (this.datas.url_link.indexOf('#') === 0) { - window.location.hash = this.datas.url_link; + window.location.hash = this.datas.url_link; } else { - this.wopen(this.datas.url_link, '_blank'); + this.wopen(this.datas.url_link, '_blank'); } }, @@ -830,6 +830,14 @@ Fluidbook.prototype = { }, print: function (button) { + return this.openPDF(button, true); + }, + + downloadPDF: function (button) { + return this.openPDF(button, false) + }, + + openPDF: function (button, print) { var $this = this; var pdf; var pdfName; @@ -840,16 +848,12 @@ Fluidbook.prototype = { } var e = pdf.split('/'); pdfName = e.pop(); - /*if (this.gal && !OFFLINEAPP) { - this.displayLoader(); - this.gal.downloadAndCall('extras', function () { - $this._openFile(pdf, $("#print"), 'pdf', pdfName); - }); - } else {*/ - this._openFile(pdf, button, 'pdf', pdfName); - //} + + this._openFile(pdf, button, 'pdf', pdfName, print); }, - _openFile: function (url, e, type, localname) { + + + _openFile: function (url, e, type, localname, print) { var $this = this; if (this.datas.phonegap != false) { @@ -867,7 +871,12 @@ Fluidbook.prototype = { } } - this.wopen(url, '_blank'); + var w = this.wopen(url, '_blank', ''); + if (print) { + setTimeout(function () { + w.print(); + }, 2000); + } }, _downloadFilePhonegap: function (url, localname, fs, callback, callbackArgs) { console.log('download file phonegap'); @@ -1042,7 +1051,15 @@ Fluidbook.prototype = { }, - wopen: function (url, target, options) { + wopen: function (url, target, options, print) { + var win; + if (this.support.nwjs) { + win = nw.Window.get().window; + } else { + win = window; + } + + if (target == undefined) { target = '_self'; } @@ -1091,7 +1108,7 @@ Fluidbook.prototype = { var w; if (options == undefined && replace == undefined) { if (this.support.IE == 0) { - w = window.open(url, mtarget); + w = win.open(url, mtarget); } else { $("#wopen").remove(); $('body').append(''); @@ -1101,7 +1118,7 @@ Fluidbook.prototype = { }, 200); } } else { - w = window.open(url, mtarget, options, replace); + w = win.open(url, mtarget, options, replace); } try { @@ -1112,5 +1129,6 @@ Fluidbook.prototype = { } catch (e) { } + return w; } } diff --git a/js/libs/fluidbook/fluidbook.nav.js b/js/libs/fluidbook/fluidbook.nav.js index ae66938c..9f2be0dd 100644 --- a/js/libs/fluidbook/fluidbook.nav.js +++ b/js/libs/fluidbook/fluidbook.nav.js @@ -657,7 +657,7 @@ FluidbookNav.prototype = { // Download icon $(document).on('click', '.icon-download', function () { - $this.fluidbook.print($(this)); + $this.fluidbook.downloadPDF($(this)); return false; }); diff --git a/js/libs/fluidbook/fluidbook.support.js b/js/libs/fluidbook/fluidbook.support.js index ded1923c..b9a7233f 100644 --- a/js/libs/fluidbook/fluidbook.support.js +++ b/js/libs/fluidbook/fluidbook.support.js @@ -52,6 +52,8 @@ function FluidbookSupport(fluidbook) { this.isMobile = isMobile(); this.SVG = Modernizr.svg && this.fluidbook.datas.mobileIconVector; + this.nwjs = (typeof process !== "undefined" && process.versions['node-webkit']); + this.screenWidth = Math.min(window.screen.availWidth, window.screen.availHeight); this.screenHeight = Math.max(window.screen.availWidth, window.screen.availHeight); -- 2.39.5