]> _ Git - fluidbook-html5.git/commitdiff
wip #6316 @2.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 14 Nov 2023 12:53:13 +0000 (13:53 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 14 Nov 2023 12:53:13 +0000 (13:53 +0100)
js/libs/fluidbook/fluidbook.stats.js
js/libs/fluidbook/stats/fluidbook.stats.esm.js [new file with mode: 0644]

index 169a81ba0bb6892e5161caa8169017c5164d8cec..b8a7e2f4b627a6455db819f9382d70384b12c52a 100644 (file)
@@ -14,9 +14,13 @@ function FluidbookStats(fluidbook) {
         this.fluidbook.settings.statsMatomo = false;
         this.fluidbook.settings.tagcommander_id = '';
         this.fluidbook.settings.xiti = '';
+        this.fluidbook.settings.tagcommander_plan_type = '';
     }
 
 
+    if (this.fluidbook.settings.tagcommander_plan_type === 'esm') {
+        this.esm = new FluidbookStatsEsm(this.fluidbook);
+    }
     if (this.fluidbook.settings.stats) {
         this.worker = new Worker('js/libs/fluidbook/workers/stats.js');
     }
@@ -79,7 +83,7 @@ FluidbookStats.prototype = {
             return true;
         });
 
-        if (this.fluidbook.settings.tagcommander_id) {
+        if (this.fluidbook.settings.tagcommander_id && this.fluidbook.settings.tagcommander_plan_type==='file') {
             this.initTagCommander();
         }
         if (this.fluidbook.settings.xiti) {
diff --git a/js/libs/fluidbook/stats/fluidbook.stats.esm.js b/js/libs/fluidbook/stats/fluidbook.stats.esm.js
new file mode 100644 (file)
index 0000000..fc8301a
--- /dev/null
@@ -0,0 +1,153 @@
+function FluidbookStatsEsm(fluidbook) {
+    this.fluidbook = fluidbook;
+    this.init();
+}
+
+FluidbookStatsEsm.prototype = {
+    init: function () {
+        let $this = this;
+
+        // Page change
+        $(this.fluidbook).on('fluidbook.page.change.end', function (e, page) {
+            $this.changePage(page);
+            return true;
+        });
+
+        // Menus (horizontal et mobile)
+        $(document).on('click', '#horizontalNav a, #menuList a', function () {
+            $this.clickNav($(this).attr('id'));
+            return true;
+        });
+
+        // Donner avis
+        $(document).on('click', '#afterSearch a', function () {
+            $this.event('donner_avis');
+            return true;
+        });
+
+        // index page
+        $(document).on('click', '.indexView a', function () {
+            $this.event('index_page');
+            return true;
+        });
+        // logo
+        $(document).on('click', '#logo', function () {
+            $this.event('logo_esm');
+            return true;
+        });
+        // Activer / Désactiver bookmark
+        $(document).on('click', 'a.bookmark', function () {
+            let a = this;
+            setTimeout(function () {
+                if ($(a).attr('data-enabled') !== 'enabled') {
+                    $this.event('retrait_marque_page')
+                } else {
+                    $this.event('ajout_marque_page')
+                }
+            }, 250);
+            return true;
+        });
+
+        // Mode article
+        $(document).on('click', 'a[href^="#/article"]', function () {
+            $this.event('mode_article');
+            return true;
+        });
+
+        // Recherche mot
+        $(document).on('click', 'a.hint', function () {
+            $this.event('recherche_terme');
+            return true;
+        });
+
+        // Audiodescription
+        $(document).on('click', 'a.audio-description-button', function () {
+            let a = this;
+            setTimeout(function () {
+                if ($(a).hasClass('playing')) {
+                    $this.event('activer_ecoute')
+                } else {
+                    $this.event('desactiver_ecoute')
+                }
+            }, 250);
+            return true;
+        });
+
+        // Télécharger et imprimer
+        $(document).on('click', 'a#confirmChoice', function () {
+            if ($(this).attr('data-mode') === 'download') {
+                $this.event('telecharger_validation')
+            } else {
+                $this.event('imprimer_validation')
+            }
+            return true;
+        });
+
+        // Partage
+        $(document).on('click', '.shareList a[data-service]', function () {
+            $this.event('partager_validation_' + $(this).attr('data-service'));
+            return true;
+        });
+
+    },
+
+    changePage: function (page) {
+        window.tc_vars.magazine_page = page;
+        window.tc_vars.env_url = window.tc_vars.magazine_name + '/' + window.tc_vars.magazine_region + '/' + window.tc_vars.magazine_page;
+        tC.container.reload({events: {page: [{}, {}]}});
+    },
+
+    clickNav: function (id) {
+        if (id === undefined) {
+            return;
+        }
+        let e = id.split('_', 2);
+        if (e.length !== 2) {
+            return;
+        }
+        id = e[1];
+        let name = this.getClickName(id);
+        if (name !== false) {
+            this.event(name);
+        }
+    },
+
+    getClickName: function (id) {
+        if (id === 'fullscreen') {
+            if (screenfull.isFullscreen) {
+                return 'reduire_ecran';
+            } else {
+                return 'plein_ecran';
+            }
+        }
+
+        let map = {
+            'index': 'index',
+            'chapters': 'sommaire',
+            'searchIcon': 'recherche',
+            'share': 'partager',
+            'print': 'imprimer',
+            'bookmarks': 'liste_marque_page',
+            'download': 'telecharger',
+            'sound-off': 'activer_son',
+            'sound-on': 'desactiver_son',
+            'help': 'aide',
+        };
+
+        if (map[id] !== undefined && map[id] !== null) {
+            return map[id];
+        }
+        return false;
+    },
+
+    event: function (name, type) {
+        if (type === undefined) {
+            type = 'navigation';
+        }
+
+        console.log('esm event', name);
+        tC.event.click(this, {
+            'click_name': name, 'click_type': type,
+        });
+    }
+}
\ No newline at end of file