init: function (datas) {
this.flags = {};
- this.networkPauseDate = null;
- this.networkPauseQueue = [];
- this.networkPausePriorityQueue = [];
- this.initNetworkPause();
this.canNavigate = false;
this.initSettings(datas);
this.singleMode = (this.datas.mobileNavigationType === 'portrait');
this.junk = datas.cacheDate;
+ this.networkControl = new FluidbookNetworkControl(this);
this.input = new FluidbookInput(this);
if (this.datas.landingPage != undefined && this.datas.landingPage != '') {
this.landingpage = new FluidbookLandingPage(this);
if (this.support.transitions3dacc && this.datas.mobileTransitions === 'flip3d') {
$("#main,#viewOverlay,#view").css('visibility', 'visible');
resize();
- this.pauseNetwork(4000);
+ this.networkControl.pause(4000);
setTimeout(function () {
this.fluidbook.pagetransitions.flip3d.performancesTest(function () {
- $this.pauseNetwork(-1);
+ $this.networkControl.resume();
$this._hideSplash();
})
}, 500);
}
},
+
_hideSplash: function () {
var $this = this;
var timeout = 1200;
,
showAllButtons: function () {
$("#next,#previous").addClass('help').show();
- }
- ,
+ },
setPageNumbers: function () {
$("#pagesnumbers .left").html(this.getPageNumberOfSide('left'));
$("#pagesnumbers .right").html(this.getPageNumberOfSide('right'));
$("#pagesnumbers").removeClass('hidden');
- }
- ,
+ },
getPhysicalPageNumberOfSide: function (side) { // Side should be 'left' or 'right'
var pageSide = $("#currentDoublePage").find('.' + side);
if (pageSide.length == 0) {
}
return $(pageSide).data('page');
- }
- ,
+ },
getPageNumberOfSide: function (side) {
var physical = this.getPhysicalPageNumberOfSide(side);
if (!physical || physical === 1) {
return '';
}
return this.physicalToVirtual(physical);
- }
- ,
+ },
clickLogo: function () {
if (this.datas.url_link == '' || this.datas.url_link == 'http://') {
return;
} else {
this.wopen(this.datas.url_link, '_blank');
}
- }
- ,
+ },
addWaiter: function (reset) {
if (reset == undefined) {
var rand = Math.round(Math.random() * 100000);
this.waiters.push(rand);
return rand;
- }
- ,
+ },
waiterActive: function (id) {
return this.waiters.indexOf(id) > -1;
- }
- ,
+ },
resetWaiters: function () {
this.waiters = [];
- }
- ,
+ },
physicalToVirtual: function (page) {
return this.datas.numerotation[page - 1];
- }
- ,
+ },
virtualToPhysical: function (page) {
if (page === undefined) {
return false;
return false;
}
return i + 1;
- }
- ,
+ },
hideMenuItems: function () {
$('#menuList > ul > li, #shareLinks').fadeOut(100);
- }
- ,
+ },
showMenuItems: function () {
$('#menuList > ul > li, #shareLinks').fadeIn(300);
- }
- ,
+ },
print: function (button) {
this.stats.track(3);
return this.openPDF(button, true);
- }
- ,
+ },
downloadPDF: function (button) {
this.stats.track(7);
return this.openPDF(button, false)
- }
- ,
+ },
openPDF: function (button, print) {
var $this = this;
pdfName = e.pop();
this._openFile(pdf, button, 'pdf', pdfName, print);
- }
- ,
+ },
_openFile: function (url, e, type, localname, print) {
if (print === undefined) {
}, function () {
});
- }
- ,
+ },
_openFilePhonegap: function (url, e, type) {
var $this = this;
return true;
}
return false;
- }
- ,
+ },
relativeToAbsolute: function (relative) {
var a = document.createElement('a');
a.href = relative;
return a.cloneNode(false).href;
- }
- ,
+ },
alertInternetRequired: function () {
navigator.notification.alert('', function () {
}, this.l10n.__('an internet connection is required for this action'));
- }
- ,
+ },
touchOffset: function (offset) {
offset *= $("#currentDoublePage").width();
$("#currentDoublePage").css({
translateX: offset
});
- }
- ,
+ },
displayLoader: function () {
$("#loader").addClass('show');
if (!this.support.isMobile) {
$('body').addClass('loading');
}
- }
- ,
+ },
hideLoader: function (delay, force) {
if (force == undefined) {
setTimeout(function () {
$this._hideLoader(force);
}, delay * 1000);
- }
- ,
+ },
_hideLoader: function (force) {
if (force == undefined) {
if (!this.support.isMobile) {
$('body').removeClass('loading');
}
- }
- ,
+ },
wopen: function (url, target, options, print) {
var win;
}
return w;
- }
- ,
+ },
setFlag: function (name, value) {
if (value === undefined) {
value = true;
}
this.flags[name] = value;
- }
- ,
+ },
hasFlag: function (name) {
return this.flags[name] === true;
- }
- ,
+ },
hasFlags: function (names) {
var res = true;
return true;
});
return res;
- }
- ,
-
- initNetworkPause: function () {
- var $this = this;
- setInterval(function () {
-
- if ($this.networkPauseDate != null && $this.networkPauseDate < Date.now()) {
- $this.networkPauseDate = null;
- $this.flushNetworkQueue();
- }
- }, 1000);
- },
-
- pauseNetwork: function (during, reset) {
- if (reset === undefined) {
- reset = false;
- }
- if (during === -1) {
- this.networkPauseDate = null;
- this.flushNetworkQueue();
- return;
- }
-
- var date = Date.now() + during + 500;
- if (this.networkPauseDate == null || reset) {
- this.networkPauseDate = date;
- } else {
- this.networkPauseDate = Math.max(this.networkPauseDate, date);
- }
- },
-
- executeWhenNetwork: function (f,highPriority) {
- if (highPriority === undefined) {
- highPriority = false;
- }
- if (this.networkPauseDate != null) {
- if (highPriority) {
- this.networkPausePriorityQueue.push([f]);
- } else {
- this.networkPauseQueue.push([f]);
- }
- return;
- }
- f();
},
unlockCurrentPage: function () {
this.contentlock.unlockCurrentPage();
},
- flushNetworkQueue: function () {
- if ((this.networkPausePriorityQueue.length === 0 && this.networkPauseQueue.length === 0) || this.networkPauseDate != null) {
- return;
- }
-
- var f;
- if (this.networkPausePriorityQueue.length > 0) {
- f = this.networkPausePriorityQueue.shift();
- } else {
- f = this.networkPauseQueue.shift();
- }
- f();
-
- var $this = this;
- setTimeout(function () {
- $this.flushNetworkQueue();
- }, 100);
- }
- ,
-
bugreport: function (e) {
if (window.confirm('An error occured: ' + e.name + '. Do you want to send a report ?')) {
var subject = '[Fluidbook error report] ' + e.message;
--- /dev/null
+function FluidbookNetworkControl(fluidbook) {
+ this.fluidbook = fluidbook;
+ this.pauseDate = null;
+ this.pauseQueue = [];
+ this.pausePriorityQueue = [];
+ this.afterProcessingQueue = [];
+ this.processing = true;
+ this.init();
+}
+
+FluidbookNetworkControl.prototype = {
+ init: function () {
+ var $this = this;
+ setInterval(function () {
+ if ($this.pauseDate != null && $this.pauseDate < Date.now()) {
+ $this.resume();
+ }
+ }, 1000);
+ },
+
+ pause: function (during, reset) {
+ if (reset === undefined) {
+ reset = false;
+ }
+
+ var date = Date.now() + during + 500;
+ if (this.pauseDate == null || reset) {
+ this.pauseDate = date;
+ } else {
+ this.pauseDate = Math.max(this.pauseDate, date);
+ }
+ },
+
+ resume: function () {
+ this.pauseDate = null;
+ this.flushQueue();
+ return;
+ },
+
+ executeWhenNetwork: function (f, highPriority) {
+ if (highPriority === undefined) {
+ highPriority = false;
+ }
+
+ if (highPriority) {
+ this.pausePriorityQueue.push(f);
+ } else {
+ this.pauseQueue.push(f);
+ }
+
+ if (this.pauseDate == null) {
+ this.flushQueue();
+ }
+ },
+
+ executeAfterProcessing: function (f, loader) {
+ this.afterProcessingQueue = [f];
+ if (!this.processing) {
+ this.flushAfterProcessingQueue();
+ } else {
+ if (loader !== undefined && loader === true) {
+ this.fluidbook.displayLoader();
+ }
+ }
+ },
+
+ flushAfterProcessingQueue: function () {
+ $.each(this.afterProcessingQueue, function (k, f) {
+ f();
+ });
+ this.afterProcessingQueue = [];
+ },
+
+ flushQueue: function () {
+ if ((this.pausePriorityQueue.length === 0 && this.pauseQueue.length === 0) || this.pauseDate != null) {
+ this.processing = false;
+ return;
+ }
+
+ this.processing = true;
+ var f;
+ if (this.pausePriorityQueue.length > 0) {
+ f = this.pausePriorityQueue.shift();
+ } else {
+ f = this.pauseQueue.shift();
+ }
+ var $this = this;
+ f(function () {
+ setTimeout(function () {
+ $this.flushAfterProcessingQueue();
+ $this.processing = false;
+ $this.flushQueue();
+ }, 100);
+ });
+ },
+};
\ No newline at end of file
},
pauseNetworkDuringTransition: function (pageNr) {
- this.fluidbook.pauseNetwork((this.getTransitionDuration(pageNr)) * 1000, true);
+ this.fluidbook.networkControl.pause((this.getTransitionDuration(pageNr) + 0.5) * 1000, true);
},
pauseNetworkDuringPagesPreload: function () {
- this.fluidbook.pauseNetwork(30000);
+ this.fluidbook.networkControl.pause(30000);
},
pageTransition3D: function (pageNr) {
setTimeout(function () {
$this.fluidbook.loader.setContentsInDoublePage(currentDoublePage, turning.flat, true, function () {
$this.fluidbook.loader.setContentsInDoublePage(doublePage, turning.end, true, function () {
- $this.pauseNetworkDuringTransition(pageNr);
- $this.flip3d.playTurn(turning.dir, function () {
- if ($this.transitionning === false) {
- return;
- }
- // Remove former part
- $("#currentDoublePage").remove();
- $(doublePage).attr('id', 'currentDoublePage').removeClass('_3dflip').removeClass('fwd').removeClass('bwd');
- $this.afterTransition(pageNr);
- });
+ $this.fluidbook.networkControl.executeAfterProcessing(function () {
+ $this.pauseNetworkDuringTransition(pageNr);
+ $this.fluidbook.hideLoader();
+ $this.flip3d.playTurn(turning.dir, function () {
+ if ($this.transitionning === false) {
+ return;
+ }
+ // Remove former part
+ $("#currentDoublePage").remove();
+ $(doublePage).attr('id', 'currentDoublePage').removeClass('_3dflip').removeClass('fwd').removeClass('bwd');
+ $this.afterTransition(pageNr);
+ });
+ }, true);
});
});
}, 10);