CustomTarget_html.mk          |    6 +++
 Package_html_dynamic.mk       |    1 
 help3xsl/help2.js             |   79 +++++++++++++++++-------------------------
 help3xsl/online_transform.xsl |    3 +
 help3xsl/tdf_matomo.js        |   24 ++++++++++++
 5 files changed, 67 insertions(+), 46 deletions(-)

New commits:
commit 0c24f409c31e4ca8a85b6a1486e2c6eaf26942d6
Author:     Olivier Hallot <olivier.hal...@libreoffice.org>
AuthorDate: Mon Sep 25 13:55:57 2023 -0300
Commit:     Olivier Hallot <olivier.hal...@libreoffice.org>
CommitDate: Tue Sep 26 09:05:22 2023 +0200

    tdf#157360 Local help should not phone home
    
    + Remove call to matomo TDF server instance when help is local
    + Keep when Help is online.
    + refactor javascript
    
    Change-Id: I285b426531c91ff558c01798f803bf3f89720b1f
    Reviewed-on: https://gerrit.libreoffice.org/c/help/+/157255
    Tested-by: Jenkins
    Reviewed-by: Olivier Hallot <olivier.hal...@libreoffice.org>

diff --git a/CustomTarget_html.mk b/CustomTarget_html.mk
index e73ea160e0..ac3f21956a 100644
--- a/CustomTarget_html.mk
+++ b/CustomTarget_html.mk
@@ -27,6 +27,7 @@ $(eval $(call 
gb_CustomTarget_register_targets,helpcontent2/help3xsl,\
        languages.js \
        default.css \
        help2.js \
+       $(if $(HELP_ONLINE),tdf_matomo.js) \
        $(foreach lang,$(gb_HELP_LANGS),\
                $(lang)/bookmarks.js \
                $(lang)/contents.js \
@@ -331,4 +332,9 @@ $(call 
gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/help2.js : \
                 $(BUILDDIR)/config_host.mk
        sed -e "s/%PRODUCTNAME/$(gb_PRODUCTNAME_JS)/g" $< > $@
 
+$(call gb_CustomTarget_get_workdir,helpcontent2/help3xsl)/tdf_matomo.js : \
+                $(SRCDIR)/helpcontent2/help3xsl/tdf_matomo.js 
+       mkdir -p $(dir $@)
+       cp $(SRCDIR)/helpcontent2/help3xsl/tdf_matomo.js $@
+
 # vim: set noet sw=4 ts=4:
diff --git a/Package_html_dynamic.mk b/Package_html_dynamic.mk
index 6e23cf892e..b7d3e8082f 100644
--- a/Package_html_dynamic.mk
+++ b/Package_html_dynamic.mk
@@ -16,6 +16,7 @@ $(eval $(call 
gb_Package_add_files,helpcontent2_html_dynamic,$(LIBO_SHARE_HELP_F
     languages.js \
     default.css \
     help2.js \
+    $(if $(HELP_ONLINE),tdf_matomo.js) \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/help3xsl/help2.js b/help3xsl/help2.js
index 8bf2810293..df11cb5210 100644
--- a/help3xsl/help2.js
+++ b/help3xsl/help2.js
@@ -98,20 +98,6 @@ function moduleColor (module) {
     }
 }
 
-// Find spans that need the switch treatment and give it to them
-var spans = document.querySelectorAll("[class^=switch]");
-var n = spans.length;
-for (z = 0; z < n; z++) {
-    var id = spans[z].getAttribute("id");
-    if (id === null) {
-        continue;
-    }
-    else if (id.startsWith("swlnsys")) {
-        setSystemSpan(spans[z]);
-    } else {
-        setApplSpan(spans[z]);
-    }
-}
 /* add &DbPAR= and &System= to the links in DisplayArea div */
 /* skip for object files */
 function fixURL(module, system) {
@@ -216,33 +202,6 @@ function setupLanguages(page) {
     }
 }
 
-// Test, if we are online
-if (document.body.getElementsByTagName('meta')) {
-    var _paq = _paq || [];
-    /* tracker methods like "setCustomDimension" should be called before 
"trackPageView" */
-    _paq.push(['disableCookies']);
-    _paq.push(['trackPageView']);
-    _paq.push(['enableLinkTracking']);
-    (function() {
-    var u="//piwik.documentfoundation.org/";
-    _paq.push(['setTrackerUrl', u+'piwik.php']);
-    _paq.push(['setSiteId', '68']);
-    var d=document, g=d.createElement('script'), 
s=d.getElementsByTagName('script')[0];
-    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; 
s.parentNode.insertBefore(g,s);
-    })();
-    var system = getParameterByName("System");
-} else {
-    var system = getSystem();
-}
-
-var module = getParameterByName("DbPAR");
-fixURL(module,system);
-moduleColor(module);
-var helpID = getParameterByName("HID");
-// only used in xhp pages with <help-id-missing/> tags
-var missingElement = document.getElementById("bm_HID2");
-if(missingElement != null){missingElement.innerHTML = helpID;}
-
 function debugInfo(dbg) {
     if (dbg == null) return;
     document.getElementById("DEBUG").style.display = "block";
@@ -251,15 +210,43 @@ function debugInfo(dbg) {
     document.getElementById("bm_HID").innerHTML = "HID is: "+helpID;
 }
 
+// Find spans that need the switch treatment and give it to them
+function impl_Switches(){
+
+    let spans = document.querySelectorAll("[class^=switch]");
+    let n = spans.length;
+    for (let z = 0; z < n; z++) {
+        let id = spans[z].getAttribute("id");
+        if (id === null) {
+            continue;
+        }
+        else if (id.startsWith("swlnsys")) {
+            setSystemSpan(spans[z]);
+        } else {
+        setApplSpan(spans[z]);
+        }
+    }
+}
+// Main
+let module = getParameterByName("DbPAR");
+let system = getParameterByName("System");
+let helpID = getParameterByName("HID");
+impl_Switches();
+fixURL(module,system);
+moduleColor(module);
+// only used in xhp pages with <help-id-missing/> tags
+let missingElement = document.getElementById("bm_HID2");
+if(missingElement != null){missingElement.innerHTML = helpID;}
+
 debugInfo(getParameterByName("Debug"));
 
 // Mobile devices need the modules and langs on page load
 if (Math.max(document.documentElement.clientWidth, window.innerWidth || 0) < 
960) {
-    var e = new Event('click');
-    var modulesBtn = document.getElementById('modules');
-    var langsBtn = document.getElementById('langs');
-    var modules = document.getElementById('modules-nav');
-    var langs = document.getElementById('langs-nav');
+    let e = new Event('click');
+    let modulesBtn = document.getElementById('modules');
+    let langsBtn = document.getElementById('langs');
+    let modules = document.getElementById('modules-nav');
+    let langs = document.getElementById('langs-nav');
     modules.setAttribute('data-a11y-toggle-open', '');
     modulesBtn.dispatchEvent(e);
     if (langs) {
diff --git a/help3xsl/online_transform.xsl b/help3xsl/online_transform.xsl
index 856dccbde0..aaa56175d8 100644
--- a/help3xsl/online_transform.xsl
+++ b/help3xsl/online_transform.xsl
@@ -164,6 +164,9 @@
         <script type="text/javascript" src="flexsearch.debug.js"></script>
         <script type="text/javascript" src="prism.js"></script>
         <script type="text/javascript" src="help2.js" defer=""></script>
+        <xsl:if test="$online">
+            <script type="text/javascript" src="tdf_matomo.js" 
defer=""></script>
+        </xsl:if>
         <script type="text/javascript" src="a11y-toggle.js" defer=""></script>
         <script type="text/javascript" src="paginathing.js" defer=""></script>
         <script type="text/javascript" src="{$lang}/bookmarks.js" 
defer=""></script>
diff --git a/help3xsl/tdf_matomo.js b/help3xsl/tdf_matomo.js
new file mode 100644
index 0000000000..fb05d9e188
--- /dev/null
+++ b/help3xsl/tdf_matomo.js
@@ -0,0 +1,24 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+// Test, if we are online
+if (document.body.getElementsByTagName('meta')) {
+    var _paq = _paq || [];
+    /* tracker methods like "setCustomDimension" should be called before 
"trackPageView" */
+    _paq.push(['disableCookies']);
+    _paq.push(['trackPageView']);
+    _paq.push(['enableLinkTracking']);
+    (function() {
+    var u="//piwik.documentfoundation.org/";
+    _paq.push(['setTrackerUrl', u+'piwik.php']);
+    _paq.push(['setSiteId', '68']);
+    var d=document, g=d.createElement('script'), 
s=d.getElementsByTagName('script')[0];
+    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; 
s.parentNode.insertBefore(g,s);
+    })();
+}
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */

Reply via email to