From 15583ded58244ded9ba7d7f4cd7ea97d5192c933 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 17 May 2023 10:58:10 +0200 Subject: [PATCH] wait #5933 @0.5 --- js/libs/fluidbook/fluidbook.stats.js | 54 ++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/js/libs/fluidbook/fluidbook.stats.js b/js/libs/fluidbook/fluidbook.stats.js index 088e4bff..5221580d 100644 --- a/js/libs/fluidbook/fluidbook.stats.js +++ b/js/libs/fluidbook/fluidbook.stats.js @@ -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; -- 2.39.5