[Libreoffice-commits] dev-tools.git: help3/xhpeditor
Olivier Hallot (via logerrit)
logerrit at kemper.freedesktop.org
Mon Dec 9 14:59:05 UTC 2019
help3/xhpeditor/DisplayArea.js | 69 +++++++++++++++++
help3/xhpeditor/ed_transform.xsl | 156 ++++++++++++++++-----------------------
help3/xhpeditor/index.php | 9 +-
3 files changed, 141 insertions(+), 93 deletions(-)
New commits:
commit dc6fc0c304f1db83c6ab788191bdabf52a2d07d9
Author: Olivier Hallot <olivier.hallot at libreoffice.org>
AuthorDate: Mon Dec 9 11:42:37 2019 -0300
Commit: Olivier Hallot <olivier.hallot at libreoffice.org>
CommitDate: Mon Dec 9 15:58:46 2019 +0100
XHP Editor: add 'system' switches
* Add buttons to select computer system on rendered page
* Mute links to prevent clicking on href's
* cleanup on scripts
Change-Id: I90de6a2ce84b59df9764f0bdd123579177ff7016
Reviewed-on: https://gerrit.libreoffice.org/84757
Reviewed-by: Olivier Hallot <olivier.hallot at libreoffice.org>
Tested-by: Olivier Hallot <olivier.hallot at libreoffice.org>
diff --git a/help3/xhpeditor/DisplayArea.js b/help3/xhpeditor/DisplayArea.js
new file mode 100644
index 0000000..cd2d83f
--- /dev/null
+++ b/help3/xhpeditor/DisplayArea.js
@@ -0,0 +1,69 @@
+/*
+ * 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/.
+ *
+ */
+
+// scripts for rendered DisplayArea
+
+// Used to set system in case, caseinline=SYSTEM
+
+function setSystemSpan(system) {
+ hideSystemSpan();
+ var spans = document.querySelectorAll("[class^=switch]");
+ for (z = 0; z < spans.length; z++) {
+ var id = spans[z].getAttribute("id");
+ if (id === null) {
+ continue;
+ }
+ else if (id.startsWith("swlnsys")) {
+ var y = spans[z].getElementsByTagName("SPAN");
+ var n = y.length;
+ var foundSystem = false;
+ // unhide selectively
+ for (i = 0; i < n; i++) {
+ if (y[i].getAttribute("id") === null){
+ continue;
+ }
+ else if( y[i].getAttribute("id").startsWith(system)){
+ y[i].removeAttribute("hidden");
+ foundSystem=true;
+ }
+ }
+ for (i = 0; i < n; i++) {
+ if (y[i].getAttribute("id") === null){
+ continue;
+ }
+ else if( y[i].getAttribute("id").startsWith("default")){
+ if(!foundSystem){
+ y[i].removeAttribute("hidden");
+ }
+ }
+ }
+ }
+ }
+}
+function hideSystemSpan(){
+ var spans = document.querySelectorAll("[class^=switch]");
+ for (z = 0; z < spans.length; z++) {
+ var id = spans[z].getAttribute("id");
+ if (id === null) {
+ continue;
+ }else if(id.startsWith("swlnsys")) {
+ var y = spans[z].getElementsByTagName("SPAN");
+ var n = y.length;
+ for (i = 0; i < n; i++) {
+ if (y[i].getAttribute("id") === null){
+ continue;
+ }
+ else if( y[i].getAttribute("id").startsWith("MAC")){y[i].setAttribute("hidden","true");}
+ else if( y[i].getAttribute("id").startsWith("WIN")){y[i].setAttribute("hidden","true");}
+ else if( y[i].getAttribute("id").startsWith("UNIX")){y[i].setAttribute("hidden","true");}
+ else if( y[i].getAttribute("id").startsWith("default")){y[i].setAttribute("hidden","true");}
+ }
+ }
+ }
+}
diff --git a/help3/xhpeditor/ed_transform.xsl b/help3/xhpeditor/ed_transform.xsl
index f07aed5..d4c742f 100644
--- a/help3/xhpeditor/ed_transform.xsl
+++ b/help3/xhpeditor/ed_transform.xsl
@@ -467,94 +467,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 -->
@@ -803,21 +791,9 @@
</xsl:template>
<!-- Create a link -->
+<!-- Modified for editor -->
<xsl:template name="createlink">
- <xsl:choose>
- <xsl:when test="starts-with(@href,'http://') or starts-with(@href,'https://')"> <!-- web links -->
- <a target ="_blank" href="{@href}"><xsl:apply-templates /></a>
- </xsl:when>
- <xsl:when test="contains(@href,'#')"> <!-- internal links with bookmark -->
- <xsl:variable name="anchor"><xsl:value-of select="concat('#',substring-after(@href,'#'))"/></xsl:variable>
- <xsl:variable name="href"><xsl:value-of select="concat($linkprefix,substring-before(@href, 'xhp'),'html',$anchor,$linkpostfix)"/></xsl:variable>
- <a target ="_top" href="{$href}"><xsl:apply-templates /></a>
- </xsl:when>
- <xsl:otherwise>
- <xsl:variable name="href"><xsl:value-of select="concat($linkprefix,substring-before(@href, 'xhp'),'html',$linkpostfix)"/></xsl:variable>
- <a target ="_top" href="{$href}"><xsl:apply-templates /></a>
- </xsl:otherwise>
- </xsl:choose>
+ <span style="color: blue;" data-tooltip="{@href}"><xsl:apply-templates /></span>
</xsl:template>
<!-- Insert Note, Warning, or Tip -->
@@ -1175,11 +1151,11 @@
<xsl:variable name="href"><xsl:value-of select="concat($urlpre,substring-before(@href,'#'))"/></xsl:variable>
<xsl:variable name="anc"><xsl:value-of select="substring-after(@href,'#')"/></xsl:variable>
<xsl:variable name="docum" select="document($href)"/>
+ <p class="debugembed">Embed href: <xsl:value-of select="@href"/></p>
<xsl:call-template name="insertembed">
<xsl:with-param name="doc" select="$docum" />
<xsl:with-param name="anchor" select="$anc" />
</xsl:call-template>
- <p class="debugembed">Embed href: <xsl:value-of select="$href"/>#<xsl:value-of select="$anc"/></p>
</div>
</xsl:template>
diff --git a/help3/xhpeditor/index.php b/help3/xhpeditor/index.php
index 295b948..dd9e5bf 100644
--- a/help3/xhpeditor/index.php
+++ b/help3/xhpeditor/index.php
@@ -26,11 +26,10 @@ $xhp = $_POST["xhpdoc"];
<script type="text/javascript" src="addon/hint/xml-hint.js"></script>
<script type="text/javascript" src="mode/xml/xml.js"></script>
<script type="text/javascript" src="xhp2html.js" defer=""></script>
- <script type="text/javascript" src="helpcontent2/help3xsl/help2.js"></script>
<script type="text/javascript" src="helpcontent2/help3xsl/prism.js"></script>
- <script type="text/javascript" src="helpcontent2/help3xsl/help.js" defer=""></script>
<script type="text/javascript" src="autocomplete.js" defer=""></script>
<script type="text/javascript" src="snippets.js" defer=""></script>
+ <script type="text/javascript" src="DisplayArea.js"></script>
</head>
<body style="font-family:sans-serif;">
@@ -134,7 +133,11 @@ echo $xhp;
<?php
$xhp = $_POST["xhpdoc"];
if (isset($_POST["render_page"])) {
- echo '<h2>Rendered page</h2><div id="renderedpage">';
+ echo '<h2>Rendered page</h2>';
+ echo '<button onclick="setSystemSpan(\'MAC\')" class="snip_buttons">MAC</button>';
+ echo '<button onclick="setSystemSpan(\'WIN\')" class="snip_buttons">WIN</button>';
+ echo '<button onclick="setSystemSpan(\'UNIX\')" class="snip_buttons">UNIX</button>';
+ echo '<div id="renderedpage">';
$xml = new DOMDocument();
$xml->loadXML($xhp);
$xsl = new DOMDocument;
More information about the Libreoffice-commits
mailing list