]> _ Git - fluidbook-html5.git/commitdiff
wait #813 @5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 19 Oct 2017 15:42:56 +0000 (17:42 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 19 Oct 2017 15:42:56 +0000 (17:42 +0200)
js/libs/fluidbook/fluidbook.js
js/libs/fluidbook/fluidbook.nav.js
js/libs/fluidbook/fluidbook.sound.js [new file with mode: 0644]

index cb09085caca62bbeeae2869e17d2bb2fc19e1519..5093584eb6149a8afededd96a6012acc5bf30c5f 100644 (file)
@@ -49,6 +49,7 @@ Fluidbook.prototype = {
         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);
@@ -82,7 +83,6 @@ Fluidbook.prototype = {
         this.stats = new FluidbookStats(this);
         this.stats.track(10);
 
-
         this.initTheme();
         this.initKeyboardShortcuts();
     },
@@ -162,6 +162,7 @@ Fluidbook.prototype = {
         this.help.displayAtStartup();
         resize();
         $(this).trigger('fluidbookready');
+        $(this).trigger('fluidbook.ready');
     },
     loadPlugins: function () {
         $.each(this.datas.plugins, function (k, plugin) {
@@ -394,7 +395,7 @@ Fluidbook.prototype = {
             $("#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;
@@ -569,7 +570,7 @@ Fluidbook.prototype = {
         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) {
@@ -595,7 +596,7 @@ Fluidbook.prototype = {
         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) {
@@ -616,16 +617,16 @@ Fluidbook.prototype = {
             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');
index 193cefc493a0121c2abe4bee56cedd0ffac8c3ce..23967d51add832a1fe0389b17a04dee48cf58dbd 100644 (file)
@@ -221,6 +221,9 @@ FluidbookNav.prototype = {
          * __('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
@@ -317,6 +320,7 @@ FluidbookNav.prototype = {
             var icon = navOrder[i];
             //var visible = hide.indexOf(icon) == -1;
             var link = null;
+            var link2 = null;
 
             if (icon == 'home' && !skipHome) {
 
@@ -419,6 +423,9 @@ FluidbookNav.prototype = {
             } 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
@@ -451,6 +458,9 @@ FluidbookNav.prototype = {
                 }
 
                 $nav.find('ul').append('<li>' + link + '</li>');
+                if (link2 !== null) {
+                    $nav.find('ul').append('<li>' + link2 + '</li>');
+                }
 
 
             }
@@ -653,7 +663,7 @@ FluidbookNav.prototype = {
 
         // Search form handler
         $(document).on('submit', '#searchForm', function () {
-           $this.fluidbook.search.submitForm();
+            $this.fluidbook.search.submitForm();
             return false;
         });
 
diff --git a/js/libs/fluidbook/fluidbook.sound.js b/js/libs/fluidbook/fluidbook.sound.js
new file mode 100644 (file)
index 0000000..4ff37f9
--- /dev/null
@@ -0,0 +1,103 @@
+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