From 8b0a884b5c145761012bb1f26a621dbff3fa2fad Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 11 May 2022 18:34:26 +0200 Subject: [PATCH] wip #5112 @2 --- js/libs/fluidbook/fluidbook.stats.js | 52 +++++++++++++++++++++------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/js/libs/fluidbook/fluidbook.stats.js b/js/libs/fluidbook/fluidbook.stats.js index d7ba2fe3..4e10e74a 100644 --- a/js/libs/fluidbook/fluidbook.stats.js +++ b/js/libs/fluidbook/fluidbook.stats.js @@ -73,7 +73,13 @@ FluidbookStats.prototype = { initTagCommander: 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)) { @@ -87,27 +93,47 @@ FluidbookStats.prototype = { } if ($this.fluidbook.settings.tagcommander_plan['page/' + even] !== undefined) { data[1] = even; - } else if ($this.fluidbook.settings.tagcommander_plan['page/' + odd] !== undefined) { + hashes.push(data.join('/')); + } + + if ($this.fluidbook.settings.tagcommander_plan['page/' + odd] !== undefined) { data[1] = odd; + hashes.push(data.join('/')); } } + } else { + hashes.push(data.join('/')); } - var hash = data.join('/'); - if (hash === this.lastTCHash) { - return; + + var custom_vars = {}; + if (window.location.toString().indexOf('workshop.fluidbook.com') >= 0) { + custom_vars.env_work = 'pre-prod'; } - this.lastTCHash = hash; - if ($this.fluidbook.settings.tagcommander_plan[hash]) { - window.tc_vars = {}; - $.extend(window.tc_vars, $this.fluidbook.settings.tagcommander_default_vars, $this.fluidbook.settings.tagcommander_plan[hash]); - console.info('Tag commander', window.tc_vars); - try { - tC.container.reload({events: {page: [{}, {}]}}); - } catch (e) { + + $.each(hashes, function (k, hash) { + if ($this.fluidbook.settings.tagcommander_plan[hash]) { + setTimeout(function () { + window.tc_vars = {}; + var location = window.location.toString().split("#")[0]; + location += '#/' + hash; + custom_vars.url = location; + + + $.extend(window.tc_vars, $this.fluidbook.settings.tagcommander_default_vars, custom_vars, $this.fluidbook.settings.tagcommander_plan[hash]); + console.log(custom_vars); + console.info('Tag commander', window.tc_vars); + try { + tC.container.reload({events: {page: [{}, {}]}}); + } catch (e) { + console.error(e); + } + }, 500 * k) } - } + }); + + }); }, -- 2.39.5