]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
docs: move javascript logic into a standalone file
authorDaniel P. Berrangé <berrange@redhat.com>
Fri, 5 Apr 2019 12:59:31 +0000 (13:59 +0100)
committerDaniel P. Berrangé <berrange@redhat.com>
Thu, 11 Apr 2019 14:20:17 +0000 (15:20 +0100)
Instead of duplicating javascript in every single page, put it in a
standalone file which can be cached by the browser.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
docs/Makefile.am
docs/js/main.js [new file with mode: 0644]
docs/page.xsl

index 2a9d99071ca7a47d89e6e6d9bc197b2f676651a0..29b0761a2beffb4c73fe383cbd9a9e011618c625 100644 (file)
@@ -56,6 +56,7 @@ css = \
   main.css
 
 javascript = \
+  js/main.js \
   js/jquery-3.1.1.min.js \
   js/jquery.rss.min.js \
   js/moment.min.js
diff --git a/docs/js/main.js b/docs/js/main.js
new file mode 100644 (file)
index 0000000..723e2fb
--- /dev/null
@@ -0,0 +1,25 @@
+function pageload() {
+    window.addEventListener('scroll', function(e){
+        var distanceY = window.pageYOffset || document.documentElement.scrollTop
+        var shrinkOn = 94
+        home = document.getElementById("home");
+        links = document.getElementById("jumplinks");
+        search = document.getElementById("search");
+        body = document.getElementById("body");
+        if (distanceY > shrinkOn) {
+            if (home.className != "navhide") {
+                body.className = "navhide"
+                home.className = "navhide"
+                links.className = "navhide"
+                search.className = "navhide"
+            }
+        } else {
+            if (home.className == "navhide") {
+                body.className = ""
+                home.className = ""
+                links.className = ""
+                search.className = ""
+            }
+        }
+    });
+}
index beb864f26b8709b9649bcac11eecefe020e61c0f..136f3106e482b942212d5e7b8db975797606a92a 100644 (file)
         <meta name="description" content="libvirt, virtualization, virtualization API"/>
         <xsl:apply-templates select="/html:html/html:head/*" mode="content"/>
 
-        <script type="text/javascript">
-          <xsl:comment>
-          <![CDATA[
-      function init() {
-          window.addEventListener('scroll', function(e){
-              var distanceY = window.pageYOffset || document.documentElement.scrollTop,
-              shrinkOn = 94
-              home = document.getElementById("home");
-              links = document.getElementById("jumplinks");
-              search = document.getElementById("search");
-              body = document.getElementById("body");
-              if (distanceY > shrinkOn) {
-                  if (home.className != "navhide") {
-                      body.className = "navhide"
-                      home.className = "navhide"
-                      links.className = "navhide"
-                      search.className = "navhide"
-                  }
-              } else {
-                  if (home.className == "navhide") {
-                      body.className = ""
-                      home.className = ""
-                      links.className = ""
-                      search.className = ""
-                  }
-              }
-          });
-      }
-      window.onload = init();
-           ]]>
-          </xsl:comment>
+        <script type="text/javascript" src="{$href_base}js/main.js">
+          <xsl:comment>// forces non-empty element</xsl:comment>
         </script>
       </head>
-      <body>
+      <body onload="pageload()">
         <xsl:if test="html:html/html:body/@class">
           <xsl:attribute name="class">
             <xsl:value-of select="html:html/html:body/@class"/>