]> _ Git - fluidbook-html5.git/commitdiff
wip #4129 @4
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 28 Dec 2020 16:00:43 +0000 (17:00 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 28 Dec 2020 16:00:43 +0000 (17:00 +0100)
images/interface.svg
js/libs/fluidbook/fluidbook.audioplayer.js [new file with mode: 0644]
js/libs/fluidbook/fluidbook.js
js/libs/fluidbook/fluidbook.links.js
style/audioplayer.less [new file with mode: 0644]
style/fluidbook.less

index 99cce02bf61f3b13c83240e8243ffba0776edda2..3ba8551a3445a38d76a46cad0fac457d1a62f9f9 100644 (file)
     <symbol id="chevron-bold" viewBox="0 0 2.5 3.5">
         <polygon points="0.7,0 2.5,1.8 0.7,3.5 0,2.8 1.1,1.8 0,0.7"/>
     </symbol>
+    <symbol id="play" viewBox="0 0 18 18">
+        <path d="M16,8.6c0.3,0.2,0.3,0.7,0,0.9l-6.7,3.8l-6.7,3.8c-0.3,0.2-0.8,0-0.8-0.4V9V1.5c0-0.4,0.4-0.6,0.8-0.4l6.7,3.8L16,8.6z"/>
+    </symbol>
 </svg>
diff --git a/js/libs/fluidbook/fluidbook.audioplayer.js b/js/libs/fluidbook/fluidbook.audioplayer.js
new file mode 100644 (file)
index 0000000..0a5fcb8
--- /dev/null
@@ -0,0 +1,102 @@
+function FluidbookAudioPlayer(fluidbook) {
+    this.fluidbook = fluidbook;
+    this.init();
+}
+
+FluidbookAudioPlayer.prototype = {
+    init: function () {
+        var $this = this;
+        $(document).on('click', "audio:not([controls])", function () {
+            console.log(this);
+            if (this.paused) {
+                this.play();
+                $(this).addClass('playing');
+            } else {
+                this.pause();
+                $(this).removeClass('playing');
+            }
+            return false;
+        });
+        requestAnimationFrame(function () {
+            $this.updatePlayers();
+        });
+
+    },
+
+
+    initAudios() {
+        var $this = this;
+        $('audio.redbull').each(function () {
+            $this.initRedbullPlayer(this);
+        });
+    },
+
+
+    updatePlayers: function () {
+        var $this = this;
+        $('audio.playing.redbull').each(function () {
+            $this.updateRedbullPlayer(this);
+        });
+        requestAnimationFrame(function () {
+            $this.updatePlayers();
+        });
+    },
+
+    /**
+     *
+     * @param player Audio
+     */
+    updateRedbullPlayer: function (player) {
+        var paper = $(player).data(paper);
+        var halfw = $(player).data('halfw');
+        var sw = 3;
+        paper.clear();
+        var p = Math.max(0, Math.min(1, player.currentTime / player.duration));
+        var arc = paper.path(this.arc([halfw, halfw], halfw - sw, 270, 270 + (p * 360)));
+        arc.attr('stroke', "#d7104e");
+        arc.attr('stroke-width', sw);
+    },
+
+
+    initRedbullPlayer: function (player) {
+        var vp = $(player).next('.visualPlayer');
+
+        vp.append('<div class="back"></div>');
+        vp.append('<div class="icon">' + getSpriteIcon('play') + '</div>');
+        vp.append('<div class="arc"></div>');
+
+        var vpw = Math.max($(vp).outerWidth(), $(vp).outerHeight());
+        $(player).data('halfw', vpw / 2);
+
+        var paper = Raphael(vp.find('.arc').get(0), vpw, vpw);
+        $(player).data(paper);
+    },
+
+
+    arc: function (center, radius, startAngle, endAngle) {
+        angle = startAngle;
+        coords = this.toCoords(center, radius, angle);
+        path = "M " + coords[0] + " " + coords[1];
+        while (angle <= endAngle) {
+            coords = this.toCoords(center, radius, angle);
+            path += " L " + coords[0] + " " + coords[1];
+            angle += 1;
+        }
+        return path;
+    },
+
+    toCoords: function (center, radius, angle) {
+        var radians = (angle / 180) * Math.PI;
+        var x = center[0] + Math.cos(radians) * radius;
+        var y = center[1] + Math.sin(radians) * radius;
+        return [x, y];
+    },
+
+    // draw an arc
+    // centered at (100, 100),
+    // radius 80, starting at degree 0,
+    // beginning at coordinate (80, 0)
+    //   which is relative to the center
+    //   of the circle,
+    // going clockwise, until 270 degree
+}
\ No newline at end of file
index b194e73f95af3ecfa9d01c64de639c180320fa04..cd48936f432c0b5218dcac4b6c8b68ebaf2bc560 100644 (file)
@@ -79,6 +79,7 @@ Fluidbook.prototype = {
         }
         this.background = new FluidbookBackground(this);
         this.video = new FluidbookVideo(this);
+        this.audioplayer = new FluidbookAudioPlayer(this);
         this.bookmarks = new FluidbookBookmarks(this);
         this.tooltip = new FluidbookTooltip(this);
         this.accessibility = new FluidbookAccessibility(this);
index 970f857683f0e2837afbbb5c0af057d8f74b91bd..f1132967003aa74d400ab88d4706b36607663e83 100644 (file)
@@ -348,6 +348,7 @@ FluidbookLinks.prototype = {
 
         setTimeout(function () {
             $this.fluidbook.initVideos();
+            $this.fluidbook.audioplayer.initAudios();
             $this.initInlineSlideshows();
             $this.fluidbook.l10n.translateAttributes();
         }, 200);
diff --git a/style/audioplayer.less b/style/audioplayer.less
new file mode 100644 (file)
index 0000000..a340e52
--- /dev/null
@@ -0,0 +1,50 @@
+audio {
+  &.invisible, &.redbull {
+    opacity: 0;
+    cursor: pointer;
+  }
+
+  &.redbull {
+    + .visualPlayer {
+      pointer-events: none;
+      position: absolute;
+      top: 0;
+      left: 0;
+      width: 100%;
+      height: 100%;
+
+      .icon {
+        position: absolute;
+        top: 0;
+        left: 0;
+        width: 100%;
+        height: 100%;
+        color: #fff;
+        padding: 30%;
+      }
+
+      .back {
+        position: absolute;
+        top: 7px;
+        left: 7px;
+        width: ~"calc(100% - 14px)";
+        height:  ~"calc(100% - 14px)";
+        background-color: #224d8d;
+        border-radius: 50% 50%;
+      }
+
+      .arc {
+        position: absolute;
+        top: 0;
+        left: 0;
+        width: 100%;
+        height: 100%;
+
+        svg {
+          width: 100%;
+          height: 100%;
+        }
+      }
+    }
+  }
+}
\ No newline at end of file
index 1ed72caf0f3e9c63870330786bf62856b2a67fca..88237963462ec550fa274531bb7a0197741aaa07 100644 (file)
@@ -3022,3 +3022,4 @@ body > input {
 @import "posad.less";
 @import "notes.less";
 @import "cart.less";
+@import "audioplayer.less";
\ No newline at end of file