diff booket.js @ 23:69552aee9993

Use custom expander instead of details element Use a custom expander instead of a details element which is not (yet) universally supported.
author Guido Berhoerster <guido+booket@berhoerster.name>
date Sun, 05 Oct 2014 19:46:32 +0200
parents b19db583b5f8
children 6cf1ec2e8955
line wrap: on
line diff
--- a/booket.js	Sat Oct 04 22:16:56 2014 +0200
+++ b/booket.js	Sun Oct 05 19:46:32 2014 +0200
@@ -1325,6 +1325,7 @@
     this.bookmarkListElement = document.querySelector('ul#bookmark-list');
     this.bookmarkListElement.addEventListener('input', this);
     this.bookmarkListElement.addEventListener('click', this);
+    this.bookmarkListElement.addEventListener('keydown', this);
     this.bookmarkListElement.addEventListener('submit', this);
     this.bookmarkListElement.addEventListener('reset', this);
 
@@ -1343,6 +1344,13 @@
 
 extend(BookmarkView, ObservableMixin);
 
+BookmarkView.prototype.getAncestorClass = function (node, className) {
+    while ((node = node.parentNode) !== null &&
+            (!node.classList || !node.classList.contains(className)));
+
+    return node;
+};
+
 BookmarkView.prototype.handleEvent = function (e) {
     var bookmarkletData;
     var parsedData;
@@ -1417,6 +1425,25 @@
             this.notify(e.target.name,
                 getAncestorElementDatasetItem(e.target, 'tag'));
             break;
+        default:
+            if ((node = this.getAncestorClass(e.target, 'expander')) !== null) {
+                if (node.dataset.expanderOpen !== undefined) {
+                    delete node.dataset.expanderOpen;
+                } else {
+                    node.dataset.expanderOpen = '';
+                }
+            }
+            break;
+        }
+        break;
+    case 'keydown':
+        if (e.keyCode === 32 &&
+                (node = this.getAncestorClass(e.target, 'expander')) !== null) {
+            if (node.dataset.expanderOpen !== undefined) {
+                delete node.dataset.expanderOpen;
+            } else {
+                node.dataset.expanderOpen = '';
+            }
         }
         break;
     case 'submit':