this.bookmarks = new FluidbookBookmarks(this);
this.tooltip = new FluidbookTooltip(this);
this.audiodescription = new FluidbookAudioDescription(this);
+ this.sound = new FluidbookSound(this);
if (this.datas.form == 'bulle') {
this.form = new FluidbookBulleForm(this);
this.stats = new FluidbookStats(this);
this.stats.track(10);
-
this.initTheme();
this.initKeyboardShortcuts();
},
this.help.displayAtStartup();
resize();
$(this).trigger('fluidbookready');
+ $(this).trigger('fluidbook.ready');
},
loadPlugins: function () {
$.each(this.datas.plugins, function (k, plugin) {
$("#pages").addClass('_3dtransition');
$this.loader.setContentsInDoublePage(currentDoublePage, turning.flat, true, function () {
$this.loader.setContentsInDoublePage(doublePage, turning.flip, true, function () {
- $this.beforeTransition(pageNr, 3);
+ $this.beforeTransition(pageNr, 3, turning.flip);
$(doublePage).addClass(turning.nextFromClass + 'end').one($this.support.getTransitionEndEvent(), function () {
if ($this.transitionning == false) {
return;
this.displayLoader();
this.loader.preloadPagesBeforeTransition(turning.end, function () {
$this.loader.setContentsInDoublePage(doublePage, turning.end, true, function () {
- $this.beforeTransition(pageNr, 2);
+ $this.beforeTransition(pageNr, 2, turning);
$("#currentDoublePage").addClass('_2d').addClass('axis_' + $this.transitionAxis).addClass(turning.currentToClass);
$(doublePage).removeClass(turning.nextFromClass).one($this.support.getTransitionEndEvent(), function (event) {
if ($this.transitionning == false) {
this.displayLoader();
this.loader.preloadPagesBeforeTransition(turning.end, function () {
$this.loader.setContentsInDoublePage(doublePage, turning.end, true, function () {
- $this.beforeTransition(pageNr, 2);
+ $this.beforeTransition(pageNr, 2, turning);
$("#currentDoublePage").addClass('axis_' + $this.transitionAxis).addClass('_2d').addClass(turning.currentToClass);
$(doublePage).removeClass(turning.nextFromClass).one($this.support.getTransitionEndEvent(), function () {
if ($this.transitionning == false) {
this.hidePage('right');
}
var turning = this.getTurningPages(pageNr);
- this.beforeTransition(pageNr);
+ this.beforeTransition(pageNr,1, turning);
this.loader.setContentsInDoublePage(doublePage, turning.end, true, function () {
$this.afterTransition(page);
});
},
- beforeTransition: function (page, d) {
+ beforeTransition: function (page, d, turning) {
if (d == undefined) {
d = 1;
}
- $(this).trigger('fluidbook.page.change.start', [page]);
+ $(this).trigger('fluidbook.page.change.start', [page, {transition: d, page: page, turningPages: turning}]);
this.tooltip.hideTooltip();
$(".axis_y").removeClass('axis_y');
$(".axis_x").removeClass('axis_x');
* __('share on twitter')
* __('home')
* __('full screen')
+ * __('switch on / switch off the sound')
+ * __('switch off the sound')
+ * __('switch on the sound')
*/
var $this = this,
navOrder = this.fluidbook.datas.navOrder; // Default desktop order, maybe be overridden later
var icon = navOrder[i];
//var visible = hide.indexOf(icon) == -1;
var link = null;
+ var link2 = null;
if (icon == 'home' && !skipHome) {
} else if (icon == 'fullscreen' && Modernizr.fullscreen && !DATAS.phonegap) {
link = this.addLink(navType, 'nav-' + icon, '#', icon, 'full screen', 'switch between fullscreen and normal');
+ } else if (icon == 'sound' && this.fluidbook.sound.enabled) {
+ link = this.addLink(navType, 'nav-sound-on', '#', 'sound-on', 'switch off the sound', 'switch on / switch off the sound');
+ link2 = this.addLink(navType, 'nav-sound-off', '#', 'sound-off', 'switch on the sound', 'switch on / switch off the sound');
} else if (icon == 'search') {
// Only the horizontal icon menu has the search icon, which opens the main menu
}
$nav.find('ul').append('<li>' + link + '</li>');
+ if (link2 !== null) {
+ $nav.find('ul').append('<li>' + link2 + '</li>');
+ }
}
// Search form handler
$(document).on('submit', '#searchForm', function () {
- $this.fluidbook.search.submitForm();
+ $this.fluidbook.search.submitForm();
return false;
});
--- /dev/null
+function FluidbookSound(fluidbook) {
+ this.fluidbook = fluidbook;
+
+ if (this.fluidbook.datas.soundTheme == '' || !Modernizr.audio || this.fluidbook.support.iOS || this.fluidbook.support.android) {
+ this.enabled = false;
+ this.on = false;
+ return;
+ }
+
+ this.enabled = true;
+ this.on = !!this.fluidbook.datas.soundOn;
+ this.audios = [];
+ this.initEvents();
+}
+
+FluidbookSound.prototype = {
+ initEvents: function () {
+ var $this = this;
+ $(this.fluidbook).on('fluidbook.ready', function () {
+ $this.init();
+ });
+ $(document).on('click touchend', '.icon-sound-off,.icon-sound-on', function () {
+ $this.toggle();
+ return false;
+ });
+
+ $(this.fluidbook).on('fluidbook.page.change.start', function (e, page, data) {
+ $this.playSoundForPage(data);
+ });
+ },
+
+ init: function () {
+ if (!this.on) {
+ this.disable();
+ } else {
+ this.enable();
+ }
+ },
+
+ toggle: function () {
+ if (this.on) {
+ this.disable();
+ } else {
+ this.enable();
+ }
+ },
+
+ enable: function () {
+ this.on = true;
+ $(".icon-sound-off").hide();
+ $(".icon-sound-on").show();
+ },
+
+ disable: function () {
+ this.on = false;
+ $(".icon-sound-on").hide();
+ $(".icon-sound-off").show();
+ this.stopAllSounds();
+ },
+
+ playSoundForPage: function (data) {
+ if (!this.enabled || !this.on || data.transition < 3) {
+ return;
+ }
+
+ this.stopAllSounds();
+
+ var page = data.page;
+ if (page % 2 == 1) {
+ page--;
+ }
+
+ var last = this.fluidbook.datas.pages;
+ if (last % 2 == 1) {
+ last++;
+ }
+
+ var sound = '';
+ if (data.turningPages.indexOf(1) >= 0 || data.turningPages.indexOf(last) >= 0) {
+ sound = 'cover-flip';
+ } else {
+ sound = 'page-flip-' + (Math.round(Math.random() + 1));
+ }
+
+ var audio = new Audio('data/sounds/' + sound + '.mp3');
+ audio.volume = 1;
+ audio.play();
+
+ this.audios.push(audio);
+ },
+
+ stopAllSounds: function () {
+ $.each(this.audios, function (k, audio) {
+ try {
+ audio.pause();
+ } catch (err) {
+
+ }
+ audio = null;
+ });
+ this.audios = [];
+ },
+};
\ No newline at end of file