Fossil SCM
Converted JS hamburger button menu code to use standard JS only, no jQuery. Not sure how portable it is yet; I wouldn't be surprised if it broke on old IE, since we're using xhr.onload instead of the horrid mess that is xhr.onreadystatechange.
Commit
113ba3d9deb2e77d200a00c341869c5f70beb8d7247395f23fd88d9c2f350baf
Parent
96b1a9ca4d4ffd5…
2 files changed
+31
-19
+1
-1
+31
-19
| --- skins/default/footer.txt | ||
| +++ skins/default/footer.txt | ||
| @@ -2,42 +2,54 @@ | ||
| 2 | 2 | This page was generated in about |
| 3 | 3 | <th1>puts [expr {([utime]+[stime]+1000)/1000*0.001}]</th1>s by |
| 4 | 4 | Fossil $release_version $manifest_version $manifest_date |
| 5 | 5 | </div> |
| 6 | 6 | |
| 7 | -<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | |
| 8 | 7 | <th1> |
| 9 | 8 | html "<script nonce='$nonce'>" |
| 10 | 9 | html " (function() { var home='$home'; " |
| 11 | 10 | </th1> |
| 12 | - var panel = $("div#hbdrop"); | |
| 11 | + var panel = document.getElementById("hbdrop"); | |
| 13 | 12 | |
| 14 | - function hidePanel() { panel.slideUp() } | |
| 15 | - function showPanel() { panel.slideDown() } | |
| 16 | - | |
| 17 | - panel.on('click', hidePanel); | |
| 13 | + panel.onclick = panel.hide = function() { | |
| 14 | + panel.style.display = 'none'; | |
| 15 | + } | |
| 16 | + panel.show = function() { | |
| 17 | + panel.style.display = 'block'; | |
| 18 | + } | |
| 18 | 19 | |
| 19 | 20 | var needSitemapHTML = true; |
| 20 | - $("div.mainmenu > a").first().on('click', function() { | |
| 21 | - if (panel.is(":visible")) { | |
| 21 | + document.querySelector("div.mainmenu > a").onclick = function() { | |
| 22 | + if (panel.style.display == 'block') { | |
| 22 | 23 | // Hamburger button clicked a second time. |
| 23 | - hidePanel(); | |
| 24 | + panel.hide(); | |
| 24 | 25 | } |
| 25 | 26 | else if (needSitemapHTML) { |
| 26 | 27 | // Only get it once per page load: it isn't likely to |
| 27 | 28 | // change on us. |
| 28 | - $.get(home + '/sitemap', function(reply) { | |
| 29 | - panel.html($("ul#sitemap", reply)); | |
| 30 | - needSitemapHTML = false; | |
| 31 | - if (window.setAllHrefs) { | |
| 32 | - setAllHrefs(); // don't need anti-robot defense here | |
| 33 | - } | |
| 34 | - showPanel(); | |
| 35 | - }); | |
| 29 | + var xhr = new XMLHttpRequest(); | |
| 30 | + xhr.onload = function() { | |
| 31 | + var doc = xhr.responseXML; | |
| 32 | + if (doc) { | |
| 33 | + var sm = doc.querySelector("ul#sitemap"); | |
| 34 | + if (sm && xhr.status == 200) { | |
| 35 | + needSitemapHTML = false; | |
| 36 | + panel.innerHTML = sm.outerHTML; | |
| 37 | + if (window.setAllHrefs) { | |
| 38 | + setAllHrefs(); // don't need anti-robot defense here | |
| 39 | + } | |
| 40 | + panel.show(); | |
| 41 | + } | |
| 42 | + } | |
| 43 | + // else, can't parse response as HTML or XML | |
| 44 | + } | |
| 45 | + xhr.open("GET", home + "/sitemap"); | |
| 46 | + xhr.responseType = "document"; | |
| 47 | + xhr.send(); | |
| 36 | 48 | } |
| 37 | 49 | else { |
| 38 | - showPanel(); // just show what we built above | |
| 50 | + panel.show(); // just show what we built above | |
| 39 | 51 | } |
| 40 | 52 | return false; // prevent browser from acting on <a> click |
| 41 | - }); | |
| 53 | + } | |
| 42 | 54 | })(); |
| 43 | 55 | </script> |
| 44 | 56 |
| --- skins/default/footer.txt | |
| +++ skins/default/footer.txt | |
| @@ -2,42 +2,54 @@ | |
| 2 | This page was generated in about |
| 3 | <th1>puts [expr {([utime]+[stime]+1000)/1000*0.001}]</th1>s by |
| 4 | Fossil $release_version $manifest_version $manifest_date |
| 5 | </div> |
| 6 | |
| 7 | <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> |
| 8 | <th1> |
| 9 | html "<script nonce='$nonce'>" |
| 10 | html " (function() { var home='$home'; " |
| 11 | </th1> |
| 12 | var panel = $("div#hbdrop"); |
| 13 | |
| 14 | function hidePanel() { panel.slideUp() } |
| 15 | function showPanel() { panel.slideDown() } |
| 16 | |
| 17 | panel.on('click', hidePanel); |
| 18 | |
| 19 | var needSitemapHTML = true; |
| 20 | $("div.mainmenu > a").first().on('click', function() { |
| 21 | if (panel.is(":visible")) { |
| 22 | // Hamburger button clicked a second time. |
| 23 | hidePanel(); |
| 24 | } |
| 25 | else if (needSitemapHTML) { |
| 26 | // Only get it once per page load: it isn't likely to |
| 27 | // change on us. |
| 28 | $.get(home + '/sitemap', function(reply) { |
| 29 | panel.html($("ul#sitemap", reply)); |
| 30 | needSitemapHTML = false; |
| 31 | if (window.setAllHrefs) { |
| 32 | setAllHrefs(); // don't need anti-robot defense here |
| 33 | } |
| 34 | showPanel(); |
| 35 | }); |
| 36 | } |
| 37 | else { |
| 38 | showPanel(); // just show what we built above |
| 39 | } |
| 40 | return false; // prevent browser from acting on <a> click |
| 41 | }); |
| 42 | })(); |
| 43 | </script> |
| 44 |
| --- skins/default/footer.txt | |
| +++ skins/default/footer.txt | |
| @@ -2,42 +2,54 @@ | |
| 2 | This page was generated in about |
| 3 | <th1>puts [expr {([utime]+[stime]+1000)/1000*0.001}]</th1>s by |
| 4 | Fossil $release_version $manifest_version $manifest_date |
| 5 | </div> |
| 6 | |
| 7 | <th1> |
| 8 | html "<script nonce='$nonce'>" |
| 9 | html " (function() { var home='$home'; " |
| 10 | </th1> |
| 11 | var panel = document.getElementById("hbdrop"); |
| 12 | |
| 13 | panel.onclick = panel.hide = function() { |
| 14 | panel.style.display = 'none'; |
| 15 | } |
| 16 | panel.show = function() { |
| 17 | panel.style.display = 'block'; |
| 18 | } |
| 19 | |
| 20 | var needSitemapHTML = true; |
| 21 | document.querySelector("div.mainmenu > a").onclick = function() { |
| 22 | if (panel.style.display == 'block') { |
| 23 | // Hamburger button clicked a second time. |
| 24 | panel.hide(); |
| 25 | } |
| 26 | else if (needSitemapHTML) { |
| 27 | // Only get it once per page load: it isn't likely to |
| 28 | // change on us. |
| 29 | var xhr = new XMLHttpRequest(); |
| 30 | xhr.onload = function() { |
| 31 | var doc = xhr.responseXML; |
| 32 | if (doc) { |
| 33 | var sm = doc.querySelector("ul#sitemap"); |
| 34 | if (sm && xhr.status == 200) { |
| 35 | needSitemapHTML = false; |
| 36 | panel.innerHTML = sm.outerHTML; |
| 37 | if (window.setAllHrefs) { |
| 38 | setAllHrefs(); // don't need anti-robot defense here |
| 39 | } |
| 40 | panel.show(); |
| 41 | } |
| 42 | } |
| 43 | // else, can't parse response as HTML or XML |
| 44 | } |
| 45 | xhr.open("GET", home + "/sitemap"); |
| 46 | xhr.responseType = "document"; |
| 47 | xhr.send(); |
| 48 | } |
| 49 | else { |
| 50 | panel.show(); // just show what we built above |
| 51 | } |
| 52 | return false; // prevent browser from acting on <a> click |
| 53 | } |
| 54 | })(); |
| 55 | </script> |
| 56 |
+1
-1
| --- src/style.c | ||
| +++ src/style.c | ||
| @@ -391,11 +391,11 @@ | ||
| 391 | 391 | @ <html> |
| 392 | 392 | @ <head> |
| 393 | 393 | @ <base href="$baseurl/$current_page" /> |
| 394 | 394 | @ <meta http-equiv="Content-Security-Policy" \ |
| 395 | 395 | @ content="default-src 'self' data: ; \ |
| 396 | -@ script-src 'self' 'nonce-$<nonce>' ajax.googleapis.com ;\ | |
| 396 | +@ script-src 'self' 'nonce-$<nonce>' ;\ | |
| 397 | 397 | @ style-src 'self' 'unsafe-inline'" /> |
| 398 | 398 | @ <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 399 | 399 | @ <title>$<project_name>: $<title></title> |
| 400 | 400 | @ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \ |
| 401 | 401 | @ href="$home/timeline.rss" /> |
| 402 | 402 |
| --- src/style.c | |
| +++ src/style.c | |
| @@ -391,11 +391,11 @@ | |
| 391 | @ <html> |
| 392 | @ <head> |
| 393 | @ <base href="$baseurl/$current_page" /> |
| 394 | @ <meta http-equiv="Content-Security-Policy" \ |
| 395 | @ content="default-src 'self' data: ; \ |
| 396 | @ script-src 'self' 'nonce-$<nonce>' ajax.googleapis.com ;\ |
| 397 | @ style-src 'self' 'unsafe-inline'" /> |
| 398 | @ <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 399 | @ <title>$<project_name>: $<title></title> |
| 400 | @ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \ |
| 401 | @ href="$home/timeline.rss" /> |
| 402 |
| --- src/style.c | |
| +++ src/style.c | |
| @@ -391,11 +391,11 @@ | |
| 391 | @ <html> |
| 392 | @ <head> |
| 393 | @ <base href="$baseurl/$current_page" /> |
| 394 | @ <meta http-equiv="Content-Security-Policy" \ |
| 395 | @ content="default-src 'self' data: ; \ |
| 396 | @ script-src 'self' 'nonce-$<nonce>' ;\ |
| 397 | @ style-src 'self' 'unsafe-inline'" /> |
| 398 | @ <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 399 | @ <title>$<project_name>: $<title></title> |
| 400 | @ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \ |
| 401 | @ href="$home/timeline.rss" /> |
| 402 |