From 681ff79b8dbae9a2420e217124851a35529b35bb Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 25 Sep 2013 08:10:28 +0000 Subject: [PATCH] --- js/libs/fluidbook/fluidbook.js | 18 ++++++++----- js/libs/fluidbook/fluidbook.loader.js | 16 +++++++---- js/libs/fluidbook/fluidbook.resize.js | 7 +++-- js/libs/fluidbook/fluidbook.tooltip.js | 37 ++++++++++++++------------ js/libs/gal/gal.js | 24 +++++++++++++++-- js/main.js | 24 ++++++++++++----- 6 files changed, 87 insertions(+), 39 deletions(-) diff --git a/js/libs/fluidbook/fluidbook.js b/js/libs/fluidbook/fluidbook.js index c8e3aa0c..dfc5ff0a 100644 --- a/js/libs/fluidbook/fluidbook.js +++ b/js/libs/fluidbook/fluidbook.js @@ -727,10 +727,8 @@ Fluidbook.prototype = { _openView: function(view, param1, param2, callback) { var $this = this; if (this.gal != null && ['index', 'search', 'bookmark'].indexOf(view) >= 0) { - this.gal.check('thumbnails', function(info) { - if (info.success === true) { - $this.__openView(view, param1, param2, callback); - } + this.gal.downloadAndCall('thumbnails', function() { + $this.__openView(view, param1, param2, callback); }); } else { this.__openView(view, param1, param2, callback); @@ -1141,8 +1139,6 @@ Fluidbook.prototype = { if (this.l10n.dir == 'rtl') { left = -1 * ($(window).width() - left - $("#q").outerWidth()); } - - $("#searchHints").css({top: top, left: left}).show(); }, killLastSearchHint: function() { @@ -1198,8 +1194,16 @@ Fluidbook.prototype = { this.stats.track(12); }, print: function() { + var $this = this; var pdf = getBaseURL() + '/data/' + this.datas.pdfName; - this._openFile(pdf, $("#print"), 'pdf', this.datas.pdfName); + if (this.gal) { + this.displayLoader(); + this.gal.downloadAndCall('extras', function() { + $this._openFile(pdf, $("#print"), 'pdf', $this.datas.pdfName); + }); + } else { + this._openFile(pdf, $("#print"), 'pdf', this.datas.pdfName); + } }, _openFile: function(url, e, type, localname) { diff --git a/js/libs/fluidbook/fluidbook.loader.js b/js/libs/fluidbook/fluidbook.loader.js index 6b9124b0..869a87d9 100644 --- a/js/libs/fluidbook/fluidbook.loader.js +++ b/js/libs/fluidbook/fluidbook.loader.js @@ -198,9 +198,19 @@ FluidbookLoader.prototype = { if (this.backgrounds[page] != undefined) { callback(); } else { - this.backgrounds[page] = this.loadImage(this.getBackgroundURL(page), null, null, null, callback); + var $this = this; + if (window.gal != undefined) { + window.gal.downloadAndCall('content_' + page, function() { + $this.__loadBackground(page, callback); + }); + } else { + this.__loadBackground(page, callback); + } } }, + __loadBackground: function(page, callback) { + this.backgrounds[page] = this.loadImage(this.getBackgroundURL(page), null, null, null, callback); + }, loadTexts: function(pageNr, callback) { if (this.fluidbook.imagesVersion) { callback(); @@ -264,10 +274,6 @@ FluidbookLoader.prototype = { $(this.imagesErrors).each(function() { $(this).attr('src', $(this).attr('src')); }); - $("#interface img,#nav img").each(function() { - $(this).attr('src', ''); - $(this).attr('src', $(this).attr('src')); - }); this.imagesErrors = []; } }; \ No newline at end of file diff --git a/js/libs/fluidbook/fluidbook.resize.js b/js/libs/fluidbook/fluidbook.resize.js index b534f7c3..77deb90d 100644 --- a/js/libs/fluidbook/fluidbook.resize.js +++ b/js/libs/fluidbook/fluidbook.resize.js @@ -4,7 +4,7 @@ function FluidbookResize(fluidbook) { this.marginh = 20; this.corr = 0.8; this.referenceWidthLandscape = 1024; - this.referenceWidthPortrait = 600; + this.referenceWidthPortrait =400; this.referenceHeight = 600; this.orientation = ''; this.textScale = 2; @@ -56,7 +56,10 @@ FluidbookResize.prototype = { if (this.orientation == 'landscape') { interfaceScale = Math.min(1, this.ww / this.referenceWidthLandscape, this.hh / this.referenceHeight); } else if (this.orientation == 'portrait') { - interfaceScale = Math.min(1, this.ww / this.referenceWidthPortrait, this.hh / this.referenceHeight); + var nminwidth = ($("#nav a").length * 51) + 205+50; + var refWidth = Math.max(this.referenceWidthPortrait, nminwidth); + + interfaceScale = Math.min(1, this.ww / refWidth, this.hh / this.referenceHeight); } var navScale = interfaceScale * parseInt(this.fluidbook.datas.mobileNavScale) / 100; var cssInterfaceScale = [interfaceScale, interfaceScale]; diff --git a/js/libs/fluidbook/fluidbook.tooltip.js b/js/libs/fluidbook/fluidbook.tooltip.js index 42dbce84..c0fe1b55 100644 --- a/js/libs/fluidbook/fluidbook.tooltip.js +++ b/js/libs/fluidbook/fluidbook.tooltip.js @@ -6,24 +6,27 @@ function FluidbookTooltip(fluidbook) { FluidbookTooltip.prototype = { init: function() { var $this = this; - $(document).on('mouseover', 'a[data-tooltip]', function() { - var position = $(this).offset(); - position.top += $(this).outerHeight() + 20; + if (!Modernizr.ftouch) { - var text = $(this).data('tooltip'); - if (text.substr(0, 1) == '~') { - var text = $this.fluidbook.l10n.__(text.substring(1)); - $(this).data('tooltip', text); - } - var ok = $this.displayTooltip(text, position); - if (ok) { - $(this).one('mouseout', function() { - $this.hideTooltip(); - }); - } - return false; - }); - $("body").append('
'); + $(document).on('mouseover', 'a[data-tooltip]', function() { + var position = $(this).offset(); + position.top += $(this).outerHeight() + 20; + + var text = $(this).data('tooltip'); + if (text.substr(0, 1) == '~') { + var text = $this.fluidbook.l10n.__(text.substring(1)); + $(this).data('tooltip', text); + } + var ok = $this.displayTooltip(text, position); + if (ok) { + $(this).one('mouseout', function() { + $this.hideTooltip(); + }); + } + return false; + }); + $("body").append('
'); + } }, displayTooltip: function(tooltip, position) { if (tooltip == undefined || tooltip == '') { diff --git a/js/libs/gal/gal.js b/js/libs/gal/gal.js index 9569006b..e073ea2e 100644 --- a/js/libs/gal/gal.js +++ b/js/libs/gal/gal.js @@ -57,8 +57,13 @@ * Downloads assets contained in the named bundle. * @param {string} bundleName name of single bundle to download. */ - GAL.prototype.download = function(bundleName) { + GAL.prototype.download = function(bundleName, callback) { var bundle = this.bundles[bundleName]; + if (callback == undefined) { + callback = function() { + }; + } + if (!bundle) { // Attempting to download invalid bundle. @@ -76,12 +81,15 @@ cached: true, bundleName: bundleName }); + callback(); + } else { if (!that.online()) { // Otherwise, since we're offline, error out. fireCallback_(that.error, bundleName, { error: 'Missing resources cant be downloaded while offline' }); + callback(); } else { // Setup a loop via callback chaining. (function loop(index) { @@ -91,6 +99,7 @@ bundleName: bundleName, success: true }); + callback(); return; } @@ -146,6 +155,17 @@ addCallback_(this.error, opt_bundleName, callback); }; + GAL.prototype.downloadAndCall = function(bundleName, callback) { + var $this = this; + this.check(bundleName, function(info) { + if (info.success) { + callback(); + } else { + $this.download(bundleName, callback); + } + }); + }; + /** * Checks if a bundle is already downloaded. * @param {string} bundleName Name of bundle to check. @@ -231,7 +251,7 @@ ); }; - GAL.prototype.initAdapter_=function(callback) { + GAL.prototype.initAdapter_ = function(callback) { var $this = this; if (this.adapter != null) { diff --git a/js/main.js b/js/main.js index 529cd397..cc56f797 100644 --- a/js/main.js +++ b/js/main.js @@ -82,6 +82,8 @@ function onDeviceReady() { } if (navigator.onLine && manifest) { + var readyToLoad = false; + var finishedLoading = false; gal = new GameAssetLoader(JSON.parse(manifest), fsprefix); gal.init(function() { @@ -92,16 +94,26 @@ function onDeviceReady() { gal.onLoaded(function(info) { $(window).trigger('GALBundleLoaded', [info]); }); - - gal.check('content_4',function(){ - fluidbook.changeAddress(); + + gal.check('content_4', function(info) { + if (info.success) { + fluidbook.changeAddress(); + } }); - - gal.check('extras',function(){ - window.localStorage.setItem('offline.' + DATAS.id, '1'); + + gal.check('extras', function(info) { + if (info.success) { + window.localStorage.setItem('offline.' + DATAS.id, '1'); + } }) $(window).on('GALBundleLoaded', function(e, info) { + if (info.bundleName == 'content_4') { + fluidbook.changeAddress(); + } + if (info.bundleName == 'extras') { + window.localStorage.setItem('offline.' + DATAS.id, '1'); + } fluidbook.loader.retryErrorImages(); }); } else { -- 2.39.5