Fix for carousel management.
[wolnelektury.git] / src / catalogue / static / player / 2022_player.js
index 0efe2fc..c727261 100644 (file)
@@ -4,7 +4,6 @@
         $.jPlayer.timeFormat.showHour = true;
 
         $(".jp-jplayer").each(function() {
-            console.log('starting player')
             var $self = $(this);
             var $root = $self.parent();
             var $currentMedia = null
@@ -15,7 +14,6 @@
             var player = null;
 
             var setMedia = function(elem, time=0) {
-                console.log('setMedia', elem, time);
                 var media = {}
 
                 media['mp3'] = elem.attr('data-mp3');
@@ -37,7 +35,6 @@
                 player.jPlayer("pause", time);
 
                 $currentMedia = elem;
-                $(".play-prev", $root).prop("disabled", !elem.prev().length);
                 $(".play-next", $root).prop("disabled", !elem.next().length);
 
                 let du = elem.data('duration');
@@ -60,7 +57,6 @@
 
             ready: function() {
                 player = $(this);
-                console.log(1);
 
                 let selectItem = $('.c-select li');
                 selectItem.on('click', function() {
                     speed = parseFloat(speedStr);
                     player.jPlayer("option", "playbackRate", speed);
                     localStorage['audiobook-speed'] = speedStr;
+                    _paq.push(['trackEvent', 'audiobook', 'speed', speedStr]);
                 });
                 
+                $('.jp-play', $root).click(function() {
+                    _paq.push(['trackEvent', 'audiobook', 'play']);
+                });
+                $('.jp-seek-bar', $root).click(function() {
+                    _paq.push(['trackEvent', 'audiobook', 'seek']);
+                });
+                $('.jp-mute', $root).click(function() {
+                    _paq.push(['trackEvent', 'audiobook', 'mute']);
+                });
+                $('.jp-volume-bar', $root).click(function() {
+                    _paq.push(['trackEvent', 'audiobook', 'volume']);
+                });
+
                 $('.play-next', $root).click(function() {
                     let p = $currentMedia.next();
                     if (p.length) {
                         setMedia(p).jPlayer("play");
+                        _paq.push(['trackEvent', 'audiobook', 'next']);
                     }
                 });
                 $('.play-prev', $root).click(function() {
                     let p = $currentMedia.prev();
                     if (p.length) {
                         setMedia(p).jPlayer("play");
+                        _paq.push(['trackEvent', 'audiobook', 'prev']);
+                    } else {
+                        // If in first part, restart it.
+                        setMedia($currentMedia).jPlayer("play");
+                        _paq.push(['trackEvent', 'audiobook', 'rewind']);
                     }
                 });
 
                 $('.jp-playlist li', $root).click(function() {
                     setMedia($(this)).jPlayer("play");
                     $('.c-player__chapters').removeClass('is-active');
+                    _paq.push(['trackEvent', 'audiobook', 'chapter']);
                 });
 
                 var initialElem = $('.jp-playlist li', $root).first();
                         audiobooks = {};
                     }
                     if (t && event.jPlayer.status.duration - t > 10) {
-                        console.log('writer');
                         audiobooks[$root.attr("data-book-slug")] = [
                             Date.now(),
                             event.jPlayer.status.media.id,