[libvirt] [PATCH v2 2/3] docs: move javascript logic into a standalone file

Daniel P. Berrangé posted 3 patches 6 years, 10 months ago
[libvirt] [PATCH v2 2/3] docs: move javascript logic into a standalone file
Posted by Daniel P. Berrangé 6 years, 10 months ago
Instead of duplicating javascript in every single page, put it in a
standalone file which can be cached by the browser.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 docs/Makefile.am |  1 +
 docs/main.js     | 25 +++++++++++++++++++++++++
 docs/page.xsl    | 35 +++--------------------------------
 3 files changed, 29 insertions(+), 32 deletions(-)
 create mode 100644 docs/main.js

diff --git a/docs/Makefile.am b/docs/Makefile.am
index 2a9d99071c..29b0761a2b 100644
--- a/docs/Makefile.am
+++ b/docs/Makefile.am
@@ -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/main.js b/docs/main.js
new file mode 100644
index 0000000000..723e2fb16d
--- /dev/null
+++ b/docs/main.js
@@ -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 = ""
+            }
+        }
+    });
+}
diff --git a/docs/page.xsl b/docs/page.xsl
index beb864f26b..136f3106e4 100644
--- a/docs/page.xsl
+++ b/docs/page.xsl
@@ -99,40 +99,11 @@
         <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"/>
-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 2/3] docs: move javascript logic into a standalone file
Posted by Andrea Bolognani 6 years, 10 months ago
On Fri, 2019-04-05 at 16:12 +0100, Daniel P. Berrangé wrote:
> Instead of duplicating javascript in every single page, put it in a
> standalone file which can be cached by the browser.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  docs/Makefile.am |  1 +
>  docs/main.js     | 25 +++++++++++++++++++++++++
>  docs/page.xsl    | 35 +++--------------------------------
>  3 files changed, 29 insertions(+), 32 deletions(-)
>  create mode 100644 docs/main.js

Reviewed-by: Andrea Bolognani <abologna@redhat.com>

-- 
Andrea Bolognani / Red Hat / Virtualization

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 2/3] docs: move javascript logic into a standalone file
Posted by Andrea Bolognani 6 years, 10 months ago
On Fri, 2019-04-05 at 17:38 +0200, Andrea Bolognani wrote:
> On Fri, 2019-04-05 at 16:12 +0100, Daniel P. Berrangé wrote:
> > Instead of duplicating javascript in every single page, put it in a
> > standalone file which can be cached by the browser.
> > 
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > ---
> >  docs/Makefile.am |  1 +
> >  docs/main.js     | 25 +++++++++++++++++++++++++
> >  docs/page.xsl    | 35 +++--------------------------------
> >  3 files changed, 29 insertions(+), 32 deletions(-)
> >  create mode 100644 docs/main.js
> 
> Reviewed-by: Andrea Bolognani <abologna@redhat.com>

Actually, not so fast: you've moved the existing JavaScript code
to docs/main.js instead of js/docs/main.js, which is of course
completely wrong. Please fix that before pushing.

-- 
Andrea Bolognani / Red Hat / Virtualization

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 2/3] docs: move javascript logic into a standalone file
Posted by Daniel P. Berrangé 6 years, 10 months ago
On Fri, Apr 05, 2019 at 05:45:10PM +0200, Andrea Bolognani wrote:
> On Fri, 2019-04-05 at 17:38 +0200, Andrea Bolognani wrote:
> > On Fri, 2019-04-05 at 16:12 +0100, Daniel P. Berrangé wrote:
> > > Instead of duplicating javascript in every single page, put it in a
> > > standalone file which can be cached by the browser.
> > > 
> > > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > > ---
> > >  docs/Makefile.am |  1 +
> > >  docs/main.js     | 25 +++++++++++++++++++++++++
> > >  docs/page.xsl    | 35 +++--------------------------------
> > >  3 files changed, 29 insertions(+), 32 deletions(-)
> > >  create mode 100644 docs/main.js
> > 
> > Reviewed-by: Andrea Bolognani <abologna@redhat.com>
> 
> Actually, not so fast: you've moved the existing JavaScript code
> to docs/main.js instead of js/docs/main.js, which is of course
> completely wrong. Please fix that before pushing.

Opps, squashed that into the 3rd patch by mistake.


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list