summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlmari Lauhakangas <ilmari.lauhakangas@libreoffice.org>2019-03-12 23:36:46 +0200
committerOlivier Hallot <olivier.hallot@libreoffice.org>2019-03-13 20:11:32 +0100
commit3d0fcf7a37859e0e8b61d4a560042dfef6b3c99b (patch)
treed841577c702391701d5671640b44975f2b11c290
parent669ede5358fc7aa63420bd61b62548f2d0b54519 (diff)
New approach to switch cases
My previous JS patch broke the sys and appl switch behaviour. This patch removes the inline function calls from online_transform.xsl. Instead, help2.js now finds the relevant spans and calls the functions for them. Change-Id: I45d5b75bdb70a7c18eaa0b215beb57e3e1b6719a Reviewed-on: https://gerrit.libreoffice.org/69137 Tested-by: Jenkins Reviewed-by: Olivier Hallot <olivier.hallot@libreoffice.org>
-rw-r--r--help3xsl/help2.js16
-rw-r--r--help3xsl/online_transform.xsl145
2 files changed, 82 insertions, 79 deletions
diff --git a/help3xsl/help2.js b/help3xsl/help2.js
index 5a48c394fe..0003b72d82 100644
--- a/help3xsl/help2.js
+++ b/help3xsl/help2.js
@@ -65,6 +65,20 @@ function setSystemSpan(spanID) {
}
}
}
+// 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(id);
+ } else {
+ setApplSpan(id);
+ }
+}
/* add &DbPAR= and &System= to the links in DisplayArea div */
/* skip for object files */
function fixURL(module, system) {
@@ -168,7 +182,7 @@ function setupLanguages(target, page) {
}
// Test, if we are online
-if (document.body.getElementsByTagName('meta')[0].getAttribute('itemprop') === 'version') {
+if (document.body.getElementsByTagName('meta')) {
var _paq = _paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['disableCookies']);
diff --git a/help3xsl/online_transform.xsl b/help3xsl/online_transform.xsl
index 33a9537d34..f3b71bac9c 100644
--- a/help3xsl/online_transform.xsl
+++ b/help3xsl/online_transform.xsl
@@ -162,7 +162,8 @@
</head>
<body itemscope="true" itemtype="http://schema.org/TechArticle">
<xsl:if test="$online">
- <meta itemprop="version" content="{$productversion}"/><!-- This is used by help2.js to test, if we are online -->
+ <!-- help2.js checks, if meta elements exist in the body -->
+ <meta itemprop="version" content="{$productversion}"/>
<meta itemprop="inLanguage" content="{$lang}"/>
<meta itemprop="datePublished" content="2017"/>
<meta itemprop="headline" content="{$titleL10N}"/>
@@ -615,94 +616,82 @@
<!-- SWITCH -->
<xsl:template match="switch">
- <xsl:variable name="idsw" select="concat('swln',generate-id())"/>
- <span id="{$idsw}" class="switch">
- <xsl:choose>
- <xsl:when test ="@select = 'sys'">
- <xsl:apply-templates />
- <script type="text/javascript">
- <![CDATA[setSystemSpan("]]><xsl:value-of select="$idsw"/><![CDATA[");]]>
- </script>
- </xsl:when>
- <xsl:when test ="@select = 'appl'">
+ <xsl:choose>
+ <xsl:when test ="@select = 'sys'">
+ <xsl:variable name="idsw" select="concat('swlnsys',generate-id())"/>
+ <span id="{$idsw}" class="switch">
<xsl:apply-templates />
- <script type="text/javascript">
- <![CDATA[setApplSpan("]]><xsl:value-of select="$idsw"/><![CDATA[");]]>
- </script>
- </xsl:when>
- <xsl:otherwise>
+ </span>
+ </xsl:when>
+ <xsl:when test ="@select = 'appl'">
+ <xsl:variable name="idsw" select="concat('swlnappl',generate-id())"/>
+ <span id="{$idsw}" class="switch">
<xsl:apply-templates />
- </xsl:otherwise>
- </xsl:choose>
- </span>
+ </span>
+ </xsl:when>
+ <xsl:otherwise>
+ <p class="debug">Unsupported switch condition.</p>
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:template>
<xsl:template match="switch" mode="embedded">
- <xsl:variable name="idsw" select="concat('swln',generate-id())"/>
- <span id="{$idsw}" class="switch">
- <xsl:choose>
- <xsl:when test ="@select = 'sys'">
+ <xsl:choose>
+ <xsl:when test ="@select = 'sys'">
+ <xsl:variable name="idsw" select="concat('swlnsys',generate-id())"/>
+ <span id="{$idsw}" class="switch">
<xsl:apply-templates mode="embedded"/>
- <script type="text/javascript">
- <![CDATA[setSystemSpan("]]><xsl:value-of select="$idsw"/><![CDATA[");]]>
- </script>
- </xsl:when>
- <xsl:when test ="@select = 'appl'">
- <xsl:apply-templates />
- <script type="text/javascript">
- <![CDATA[setApplSpan("]]><xsl:value-of select="$idsw"/><![CDATA[");]]>
- </script>
- </xsl:when>
- <xsl:otherwise>
- <xsl:apply-templates />
- </xsl:otherwise>
- </xsl:choose>
- </span>
+ </span>
+ </xsl:when>
+ <xsl:when test ="@select = 'appl'">
+ <xsl:variable name="idsw" select="concat('swlnappl',generate-id())"/>
+ <span id="{$idsw}" class="switch">
+ <xsl:apply-templates mode="embedded"/>
+ </span>
+ </xsl:when>
+ <xsl:otherwise>
+ <p class="debug">Unsupported switch condition.</p>
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:template>
<!-- SWITCHINLINE -->
<xsl:template match="switchinline">
- <xsl:variable name="idsw" select="concat('swln',generate-id())"/>
- <span id="{$idsw}" class="switchinline">
- <xsl:choose>
- <xsl:when test ="@select = 'sys'">
+ <xsl:choose>
+ <xsl:when test ="@select = 'sys'">
+ <xsl:variable name="idsw" select="concat('swlnsys',generate-id())"/>
+ <span id="{$idsw}" class="switchinline">
<xsl:apply-templates />
- <script type="text/javascript">
- <![CDATA[setSystemSpan("]]><xsl:value-of select="$idsw"/><![CDATA[");]]>
- </script>
- </xsl:when>
- <xsl:when test ="@select = 'appl'">
+ </span>
+ </xsl:when>
+ <xsl:when test ="@select = 'appl'">
+ <xsl:variable name="idsw" select="concat('swlnappl',generate-id())"/>
+ <span id="{$idsw}" class="switchinline">
<xsl:apply-templates />
- <script type="text/javascript">
- <![CDATA[setApplSpan("]]><xsl:value-of select="$idsw"/><![CDATA[");]]>
- </script>
- </xsl:when>
- <xsl:otherwise>
- <xsl:apply-templates />
- </xsl:otherwise>
- </xsl:choose>
- </span>
+ </span>
+ </xsl:when>
+ <xsl:otherwise>
+ <p class="debug">Unsupported switch condition.</p>
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:template>
<xsl:template match="switchinline" mode="embedded">
- <xsl:variable name="idsw" select="concat('swln',generate-id())"/>
- <span id="{$idsw}" class="switchinline">
- <xsl:choose>
- <xsl:when test ="@select = 'sys'">
- <xsl:apply-templates />
- <script type="text/javascript">
- <![CDATA[setSystemSpan("]]><xsl:value-of select="$idsw"/><![CDATA[");]]>
- </script>
- </xsl:when>
- <xsl:when test ="@select = 'appl'">
- <xsl:apply-templates />
- <script type="text/javascript">
- <![CDATA[setApplSpan("]]><xsl:value-of select="$idsw"/><![CDATA[");]]>
- </script>
- </xsl:when>
- <xsl:otherwise>
- <xsl:apply-templates />
- </xsl:otherwise>
- </xsl:choose>
- </span>
+ <xsl:choose>
+ <xsl:when test ="@select = 'sys'">
+ <xsl:variable name="idsw" select="concat('swlnsys',generate-id())"/>
+ <span id="{$idsw}" class="switchinline">
+ <xsl:apply-templates mode="embedded"/>
+ </span>
+ </xsl:when>
+ <xsl:when test ="@select = 'appl'">
+ <xsl:variable name="idsw" select="concat('swlnappl',generate-id())"/>
+ <span id="{$idsw}" class="switchinline">
+ <xsl:apply-templates mode="embedded"/>
+ </span>
+ </xsl:when>
+ <xsl:otherwise>
+ <p class="debug">Unsupported switch condition.</p>
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:template>
<!-- TABLE -->
@@ -1017,10 +1006,10 @@
<xsl:variable name="auxID" select="concat(@select,generate-id())"/>
<xsl:choose>
<xsl:when test="$embedded = 'yes'">
- <span hidden="true" id="{$auxID}"><xsl:apply-templates mode="embedded"/></span>
+ <span hidden="true" id="{$auxID}" class="{@select}"><xsl:apply-templates mode="embedded"/></span>
</xsl:when>
<xsl:otherwise>
- <span hidden="true" id="{$auxID}"><xsl:apply-templates/></span>
+ <span hidden="true" id="{$auxID}" class="{@select}"><xsl:apply-templates/></span>
</xsl:otherwise>
</xsl:choose>
</xsl:template>