add JavaScript for page version selector
authorDan Allen <dan@opendevise.com>
Sat, 18 Nov 2017 23:41:34 +0000 (16:41 -0700)
committerDan Allen <dan@opendevise.com>
Mon, 20 Nov 2017 23:41:36 +0000 (16:41 -0700)
src/js/03-page-versions.js [new file with mode: 0644]
src/partials/page-versions.hbs

diff --git a/src/js/03-page-versions.js b/src/js/03-page-versions.js
new file mode 100644 (file)
index 0000000..672bda1
--- /dev/null
@@ -0,0 +1,18 @@
+;(function () {
+  'use strict'
+
+  var toggle = document.querySelector('.page-versions .versions-menu-toggle')
+  if (!toggle) return
+
+  var selector = document.querySelector('.page-versions')
+
+  toggle.addEventListener('click', function (e) {
+    selector.classList.toggle('is-active')
+    // don't let this event get smothered
+    e.stopPropagation()
+  })
+
+  window.addEventListener('click', function () {
+    selector.classList.remove('is-active')
+  })
+})()
index de57d1b..ef46f1c 100644 (file)
@@ -1,6 +1,6 @@
 {{#if (has-versions domain)}}
 <div class="page-versions">
-  <button class="versions-menu-toggle" title="Other versions of page">{{domain.version.string}}</button>
+  <button class="versions-menu-toggle" title="Show other versions of page">{{domain.version.string}}</button>
   <div class="versions-menu">
     {{#each (page-versions site.domains domain.name versions)}}
     <a class="version{{#if (eq ./string ../domain.version.string)}} is-current{{/if}}{{#if ./missing}} is-missing{{/if}}" href="{{{./url}}}">{{./string}}</a>