]> _ Git - fluidbook-html5.git/commitdiff
wait #5933 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 17 May 2023 08:58:10 +0000 (10:58 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 17 May 2023 08:58:10 +0000 (10:58 +0200)
js/libs/fluidbook/fluidbook.stats.js

index 088e4bff1a139836fbac1dfb632beb17a2d1e844..5221580da467f3e1afd3e40bf1ad0aa14d90c5e2 100644 (file)
@@ -71,6 +71,9 @@ FluidbookStats.prototype = {
         if (this.fluidbook.settings.tagcommander_id) {
             this.initTagCommander();
         }
+        if (this.fluidbook.settings.xiti) {
+            this.initPianoAnalytics();
+        }
     },
 
     initTagCommander: function () {
@@ -140,6 +143,57 @@ FluidbookStats.prototype = {
         });
     },
 
+
+    initPianoAnalytics: function () {
+        var $this = this;
+        $(this.fluidbook).on('fluidbook.hashchange', function (e, data) {
+            if (window.location.hash === this.lastTCHash) {
+                return;
+            }
+            this.lastTCHash = window.location.hash;
+            data.shift();
+            var hashes = [];
+            if (!$this.fluidbook.displayOnePage && data[0] === 'page') {
+                var p = parseInt(data[1]);
+                if (!isNaN(p)) {
+                    var even, odd;
+                    if (p % 2 === 0) {
+                        even = p;
+                        odd = p + 1;
+                    } else {
+                        odd = p;
+                        even = p - 1;
+                    }
+                    if ($this.fluidbook.settings.piano_plan['page/' + even] !== undefined) {
+                        data[1] = even;
+                        hashes.push(data.join('/'));
+                    }
+
+                    if ($this.fluidbook.settings.piano_plan['page/' + odd] !== undefined) {
+                        data[1] = odd;
+                        hashes.push(data.join('/'));
+                    }
+                }
+            } else {
+                hashes.push(data.join('/'));
+            }
+
+            $.each(hashes, function (k, hash) {
+                if ($this.fluidbook.settings.piano_plan[hash]) {
+                    setTimeout(function () {
+                        var pianoData = $this.fluidbook.settings.piano_plan[hash];
+                        console.info('Piano Data', pianoData);
+                        try {
+                            pa.sendEvent('page.display', pianoData);
+                        } catch (e) {
+                            console.error(e);
+                        }
+                    }, 500 * k)
+                }
+            });
+        });
+    },
+
     track: function (type, page, extra) {
         if (!this.fluidbook.support.hasNetwork() || this.fluidbook.nointerface) {
             return;