From: Vincent Vanwaelscappel Date: Tue, 31 Oct 2017 10:19:26 +0000 (+0100) Subject: wip #1701 @12 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=602644968f72c7b3728f41a13b5edb06e309bc1a;p=fluidbook-html5.git wip #1701 @12 --- diff --git a/_index.html b/_index.html index e1b137b2..5f9efb9e 100644 --- a/_index.html +++ b/_index.html @@ -8,7 +8,7 @@ + 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:"> diff --git a/js/libs/cube/fb.js b/js/libs/cube/fb.js index 479691aa..0f897e91 100644 --- a/js/libs/cube/fb.js +++ b/js/libs/cube/fb.js @@ -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; diff --git a/js/libs/fluidbook/fluidbook.bookmarks.js b/js/libs/fluidbook/fluidbook.bookmarks.js index 8c652216..9c6aaab2 100644 --- a/js/libs/fluidbook/fluidbook.bookmarks.js +++ b/js/libs/fluidbook/fluidbook.bookmarks.js @@ -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; }); diff --git a/js/libs/fluidbook/fluidbook.js b/js/libs/fluidbook/fluidbook.js index caaf05e4..8070465b 100644 --- a/js/libs/fluidbook/fluidbook.js +++ b/js/libs/fluidbook/fluidbook.js @@ -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(); } diff --git a/js/libs/fluidbook/fluidbook.loader.js b/js/libs/fluidbook/fluidbook.loader.js index 7f599a2b..465b901b 100644 --- a/js/libs/fluidbook/fluidbook.loader.js +++ b/js/libs/fluidbook/fluidbook.loader.js @@ -265,6 +265,7 @@ FluidbookLoader.prototype = { 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(); } diff --git a/js/libs/fluidbook/fluidbook.nav.js b/js/libs/fluidbook/fluidbook.nav.js index a6daf994..25d72c07 100644 --- a/js/libs/fluidbook/fluidbook.nav.js +++ b/js/libs/fluidbook/fluidbook.nav.js @@ -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 = ''; - } } } 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; }); diff --git a/js/libs/fluidbook/fluidbook.support.js b/js/libs/fluidbook/fluidbook.support.js index 45f17fb4..5f51d4da 100644 --- a/js/libs/fluidbook/fluidbook.support.js +++ b/js/libs/fluidbook/fluidbook.support.js @@ -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; diff --git a/js/main.js b/js/main.js index 4250f11a..0636a26f 100644 --- a/js/main.js +++ b/js/main.js @@ -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);