]> _ Git - fluidbook-html5.git/commitdiff
wip #1701 @12
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 31 Oct 2017 10:19:26 +0000 (11:19 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 31 Oct 2017 10:19:26 +0000 (11:19 +0100)
_index.html
js/libs/cube/fb.js
js/libs/fluidbook/fluidbook.bookmarks.js
js/libs/fluidbook/fluidbook.js
js/libs/fluidbook/fluidbook.loader.js
js/libs/fluidbook/fluidbook.nav.js
js/libs/fluidbook/fluidbook.support.js
js/main.js

index e1b137b24413768595bce75b3efc9b166319630d..5f9efb9e69712a6b526cc000731ffa2f6f80ff95 100644 (file)
@@ -8,7 +8,7 @@
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=Edge">
        <meta http-equiv="Content-Security-Policy"
-             content="default-src * gap://ready file:; style-src 'self' 'unsafe-inline'; font-src 'self' data:; script-src 'self' 'unsafe-inline' 'unsafe-eval' *.google-analytics.com *.youtube.com *.ytimg.com; img-src * data:">
+             content="default-src 'self' data: gap: 'unsafe-inline' *; style-src 'self' 'unsafe-inline'; font-src 'self' data:; script-src 'self' 'unsafe-inline' 'unsafe-eval' *.google-analytics.com *.youtube.com *.ytimg.com; img-src * data:">
        <!--<meta name="apple-mobile-web-app-capable" content="yes">-->
        <meta name="viewport" content="initial-scale=1,minimum-scale=1,user-scalable=no">
        <meta name="google" content="notranslate">
index 479691aa2104cb57ec94a79387c2b510debc65ce..0f897e91ba03c46bb12db478449bedd70d629734 100644 (file)
@@ -24,10 +24,6 @@ function fb(o, type) {
        return;
 }
 
-// window.onerror = function(errorMsg, url, lineNumber) {
-//     console.log(errorMsg + ' in ' + url + ' at line ' + lineNumber, 'error');
-// };
-
 function is(type, obj) {
        var clas = Object.prototype.toString.call(obj).slice(8, -1);
        return obj !== undefined && obj !== null && clas === type;
index 8c6522168d0438080ac85c88498a819797eca205..9c6aaab2acdba83222209f8c5eb6f7d0d66386ff 100644 (file)
@@ -44,6 +44,7 @@ FluidbookBookmarks.prototype = {
         });
 
         $(document).on('click', '.bookmarkssub a.print', function () {
+            $(this).data('ios-preview', '1');
             $this.fluidbook._openFile($this.getPDF(), $(this), 'pdf', $this.getBookmarksCompacted() + '.pdf');
             return false;
         });
index caaf05e4831a97c1be3e866352db45b7c3abf4fd..8070465beadff962bca30fa4538643121711b66e 100644 (file)
@@ -390,7 +390,7 @@ Fluidbook.prototype = {
         var doublePage = $("#nextDoublePage");
         var currentDoublePage = $("#currentDoublePage");
         this.displayLoader();
-        this.loader.preloadPagesBeforeTransition([turning.currentLeft, turning.currentRight], function () {
+        this.loader.preloadPagesBeforeTransition(turning.end, function () {
             $("#pages").addClass('_3dtransition');
             $this.loader.setContentsInDoublePage(currentDoublePage, turning.flat, true, function () {
                 $this.loader.setContentsInDoublePage(doublePage, turning.flip, true, function () {
@@ -788,7 +788,7 @@ Fluidbook.prototype = {
         $('#menuList > ul > li, #shareLinks').fadeIn(300);
     },
 
-    print: function () {
+    print: function (button) {
         var $this = this;
         var pdf;
         var pdfName;
@@ -805,7 +805,7 @@ Fluidbook.prototype = {
          $this._openFile(pdf, $("#print"), 'pdf', pdfName);
          });
          } else {*/
-        this._openFile(pdf, $("#print"), 'pdf', pdfName);
+        this._openFile(pdf, button, 'pdf', pdfName);
         //}
     },
     _openFile: function (url, e, type, localname) {
@@ -818,7 +818,7 @@ Fluidbook.prototype = {
             }
 
             if (url.indexOf('http') == 0) {
-                return this._downloadFilePhonegap(url, localname, LocalFileSystem.TEMPORARY, this._openFilePhonegap, [url, e, type]);
+                return this._downloadFilePhonegap(url, localname, window.TEMPORARY, this._openFilePhonegap, [url, e, type]);
             } else {
                 if (this._openFilePhonegap(url, e, type)) {
                     return;
@@ -829,6 +829,7 @@ Fluidbook.prototype = {
         this.wopen(url, '_blank');
     },
     _downloadFilePhonegap: function (url, localname, fs, callback, callbackArgs) {
+        console.log('download file phonegap');
         var $this = this;
         if (fs == undefined) {
             fs = LocalFileSystem.PERSISTENT;
@@ -838,7 +839,9 @@ Fluidbook.prototype = {
             window.webkitRequestFileSystem;
 
         requestFileSystem(fs, 0, function (fileSystem) {
+            console.log('fs requested');
             fileSystem.root.getFile("dummy.html", {create: true, exclusive: false}, function (fileEntry) {
+                console.log('dummy file created')
                 var filePath = fileEntry.toURL().replace("dummy.html", "") + localname;
                 var fileTransfer = new FileTransfer();
                 var uri = encodeURI(url);
@@ -846,6 +849,7 @@ Fluidbook.prototype = {
                     uri,
                     filePath,
                     function (entry) {
+                        console.log('file donwloaded');
                         if (callback != undefined) {
                             if (callbackArgs == undefined) {
                                 callbackArgs = [];
@@ -855,7 +859,7 @@ Fluidbook.prototype = {
                         }
                     },
                     function (error) {
-
+                        console.log('file error');
                     }
                 );
             });
@@ -868,19 +872,40 @@ Fluidbook.prototype = {
         var types_ios = {pdf: 'com.adobe.pdf'};
         var types_android = {pdf: 'application/pdf'};
         if (this.datas.phonegap == 'ios') {
+            console.log('open download on ios ' + type + ' -> ' + types_ios[type]);
             this.displayLoader();
             if (types_ios[type] != undefined) {
-                var offset = $(e).offset();
-                offset.left += ($(e).width() / 2);
-                offset.top += ($(e).height());
+                console.log('intro to open with External file util');
+
+                try {
+                    var offset = $(e).offset();
+
+                    offset.left += ($(e).width() / 2);
+                    offset.top += ($(e).height() / 2);
+
+                    offset.left *= window.devicePixelRatio;
+                    offset.top *= window.devicePixelRatio;
+
+                    if ($(e).data('ios-preview') == '1') {
+                        offset.top = offset.left = 0;
+                    }
+                } catch (err) {
+                    console.log('error while getting offset');
+                }
+
                 try {
+                    console.log('attempt to open with External file util');
                     ExternalFileUtil.openWith(url, types_ios[type], function () {
+                        console.log('ok to open with External file util : ' + url);
+
                         $this.hideLoader();
                     }, function () {
+                        console.log('failed to open with External file util');
                         $this.wopen(url, "_blank", 'location=no');
                         $this.hideLoader();
                     }, offset);
                 } catch (err) {
+                    console.error('unable to open with externalfileutil');
                     $this.wopen(url, "_blank", 'location=no');
                     $this.hideLoader();
                 }
index 7f599a2bf2f6fba18ae5d5272b56ed796da7e546..465b901be04ff3c3291e9a65206fccb85ca14ee1 100644 (file)
@@ -265,6 +265,7 @@ FluidbookLoader.prototype = {
             div = $('<div />');
         }
 
+
         left = ((page % 2 == 0) && this.fluidbook.l10n.ltr) || ((page % 2 == 1) && this.fluidbook.l10n.rtl);
 
         var h = this.fluidbook.datas.thumbHeight;
@@ -304,11 +305,11 @@ FluidbookLoader.prototype = {
     loadImage: function (src, width, height, type, callback) {
         var img = new Image();
         var $this = this;
-        var callbackCalled=false;
+        var callbackCalled = false;
         if (callback && typeof callback == 'function') {
             $(img).one('load', function () {
                 setTimeout(function () {
-                    if(!callbackCalled) {
+                    if (!callbackCalled) {
                         callbackCalled = true;
                         callback();
                     }
@@ -333,7 +334,7 @@ FluidbookLoader.prototype = {
         }
         if (callback && typeof callback == 'function' && (img.complete || img.readyState == 'complete' || img.readyState == 4)) {
             setTimeout(function () {
-                if(!callbackCalled) {
+                if (!callbackCalled) {
                     callbackCalled = true;
                     callback();
                 }
index a6daf994970dba6867679577e673103569a66a0a..25d72c0738ff91c08cac0ceea1ac2df4ea73ff42 100644 (file)
@@ -24,9 +24,15 @@ FluidbookNav.prototype = {
             // Allow #anchor links to trigger correctly and close the menu
             // Ref: https://github.com/FrDH/jQuery.mmenu/issues/687#issuecomment-279377172
             onClick: {
-                preventDefault: function () {
-                    $this.menuAPI.close();
-                }
+                close: function () {
+                    if (fluidbook.datas.phonegap == 'ios') {
+                        return !$(this).is('#menu_download,#menu_print');
+                    }
+                    return true;
+                },
+                preventDefault:function(){
+                    return false;
+                },
             },
 
             "extensions": [
@@ -378,34 +384,25 @@ FluidbookNav.prototype = {
                 // Sharing icons - this may contain many different icons
             } else if (icon == 'friend') {
                 if (this.fluidbook.share.isEnabled()) {
-
                     if (navType == 'horizontalNav') {
-
                         if (this.fluidbook.datas.share) {
                             link = this.addLink(navType, 'nav-share', '#/share', 'share', 'share', 'share');
                         }
-
                     } else if (navType == 'menu') {
-
                         // Save HTML so it can be added to menu once MMenu is initialised
                         this.shareLinksHTML = '<div id="shareLinks"><div class="share-icons">' + this.fluidbook.share.getShareLinks(true) + '</div></div>';
-
                     }
                 }
 
             } else if (icon == 'bookmark' && this.fluidbook.datas.bookmark) {
                 link = this.addLink(navType, 'nav-bookmarks', '#/bookmark', 'bookmarks', 'bookmarks', 'bookmarks');
-
             } else if (icon == 'pdf' && this.fluidbook.datas.pdf) {
                 link = this.addLink(navType, 'nav-download', '#', 'download', 'download', 'download');
-
             } else if (icon == 'print' && this.fluidbook.datas.print) {
                 link = this.addLink(navType, 'nav-print', '#', 'print', 'print', 'print');
-
             } else if (icon == 'lang' && this.fluidbook.l10n.multilangEnabled) {
                 // Note: the "!" at the beginning of the title/help parameters means that we don't want these strings translated
                 link = this.addLink(navType, 'nav-locales', '#/locales', 'locales', '!' + this.fluidbook.l10n.getCurrentLanguageName(), '!Select Language');
-
             } else if (icon == 'archives') {
                 if (this.fluidbook.datas.archivesLink != '') {
                     link = this.addLink(navType, 'nav-archives', this.fluidbook.datas.archivesLink, 'archives', '!' + this.fluidbook.datas.archivesLabel, '!' + this.fluidbook.datas.archivesLabel);
@@ -572,13 +569,13 @@ FluidbookNav.prototype = {
 
         // Download icon
         $(document).on('click', '.icon-download', function () {
-            $this.fluidbook.print();
+            $this.fluidbook.print($(this));
             return false;
         });
 
         // Print icon
         $(document).on('click', '.icon-print', function () {
-            $this.fluidbook.print();
+            $this.fluidbook.print($(this));
             return false;
         });
 
index 45f17fb42df08545908f0fb16c78a8dbf9d4e40b..5f51d4da0052d292234e7a49129f9106ba292c53 100644 (file)
@@ -22,6 +22,7 @@ function FluidbookSupport(fluidbook) {
             break;
     }
 
+
     this.transitions2d = Modernizr.csstransforms && Modernizr.csstransitions;
     this.transitions3d = Modernizr.csstransforms3d && Modernizr.preserve3d && this.transitions2d;
 
@@ -35,7 +36,7 @@ function FluidbookSupport(fluidbook) {
         if (Modernizr.mq('(min-device-width : 320px) and (max-device-width : 480px)')) {
             this.resolution = 150;
         } else {
-            this.resolution = Modernizr.mq('(-webkit-min-device-pixel-ratio: 2)') ? 300 : 150;
+            this.resolution = Modernizr.mq('(-webkit-min-device-pixel-ratio: 2)') ? this.fluidbook.datas.retinaResolution : 150;
         }
     } else {
         this.resolution = window.resolution;
index 4250f11a718e715092a596c9e600b143ef3de564..0636a26f646b18853b9ba8aabbdbe691129fa435 100644 (file)
@@ -58,9 +58,7 @@ try {
 
         document.addEventListener("resume", onAppResume, false);
 
-        loadJSLibrary(
-            cordovaPath
-            , cordovaLoaded);
+        loadJSLibrary(cordovaPath, cordovaLoaded);
         if (window.cordova) {
             console.log('cordova already loaded');
             cordovaLoaded();
@@ -112,7 +110,7 @@ try {
         if (PLATFORM == 'ios') {
             try {
                 window.ExternalFileUtil = cordova.require('com.techblue.cordova.plugin.externalfileutilios.ExternalFileUtilIos');
-            }catch (err){
+            } catch (err) {
                 console.error('Error while loading ExternalFileUtil plugin');
             }
         } else if (PLATFORM == 'android') {
@@ -197,7 +195,7 @@ try {
         }
     }
 
-    function loadJSLibrary(url, callback) {
+    function loadJSLibrary(url, callback, error) {
         if (jsLibraries.indexOf(url) > -1) {
             if (callback != undefined) {
                 callback();
@@ -225,6 +223,12 @@ try {
                     callback();
                 }
             };
+            script.onerror = function () {
+                console.error('Error loading ' + url);
+                if (error != undefined) {
+                    error();
+                }
+            }
         }
 
         script.src = url;
@@ -237,6 +241,7 @@ try {
     }
 
     function init() {
+        console.log('init !');
         if (INITED == true) {
             return;
         }
@@ -263,6 +268,7 @@ try {
     }
 
     function initEvents() {
+        console.log('init events');
         resize(true);
 
         if (DATAS.preventRightClick) {
@@ -382,6 +388,7 @@ try {
         });
 
         $(document).trigger('fluidbookready');
+        $(this).trigger('fluidbook.ready');
 
         setTimeout(function () {
             resize();
@@ -390,6 +397,8 @@ try {
         if (!startAfterLoading) {
             fluidbook.changeAddress();
         }
+
+        console.log('fluidbook.ready');
     }
 } catch (err) {
     console.log(err);