]> _ Git - fluidbook-html5.git/commitdiff
#819
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 8 Mar 2018 10:42:40 +0000 (11:42 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 8 Mar 2018 10:42:40 +0000 (11:42 +0100)
js/libs/fluidbook/fluidbook.js
js/libs/fluidbook/fluidbook.nav.js
js/libs/fluidbook/fluidbook.support.js

index 686daa373c60c39bdf95f4788b83d82da90bda81..42c00c690ef09e7804fb3c832966e94e8e157af0 100644 (file)
@@ -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('<a id="wopen" href="' + url + '" target="' + mtarget + '"></a>');
@@ -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;
     }
 }
index ae66938ce2ae6d869bf178649d9dca18b5ac3747..9f2be0ddbd7a0f045eb2c798bfecb1b46bf67790 100644 (file)
@@ -657,7 +657,7 @@ FluidbookNav.prototype = {
 
         // Download icon
         $(document).on('click', '.icon-download', function () {
-            $this.fluidbook.print($(this));
+            $this.fluidbook.downloadPDF($(this));
             return false;
         });
 
index ded1923c5f3d6f5bb257452350610573efaf958f..b9a7233fa15ecf83a34ed3aaf83ad99c5870f5c2 100644 (file)
@@ -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);