MDL-38661: Add keyboard support for expansion
authorAndrew Nicols <andrew@nicols.co.uk>
Tue, 10 Sep 2013 02:14:50 +0000 (03:14 +0100)
committerAndrew Nicols <andrew@nicols.co.uk>
Tue, 10 Sep 2013 02:17:13 +0000 (03:17 +0100)
course/yui/build/moodle-course-categoryexpander/moodle-course-categoryexpander-debug.js
course/yui/build/moodle-course-categoryexpander/moodle-course-categoryexpander-min.js
course/yui/build/moodle-course-categoryexpander/moodle-course-categoryexpander.js
course/yui/src/categoryexpander/js/categoryexpander.js
course/yui/src/categoryexpander/meta/categoryexpander.json

index 3bddd80..ebcec70 100644 (file)
Binary files a/course/yui/build/moodle-course-categoryexpander/moodle-course-categoryexpander-debug.js and b/course/yui/build/moodle-course-categoryexpander/moodle-course-categoryexpander-debug.js differ
index 95e4e49..5219087 100644 (file)
Binary files a/course/yui/build/moodle-course-categoryexpander/moodle-course-categoryexpander-min.js and b/course/yui/build/moodle-course-categoryexpander/moodle-course-categoryexpander-min.js differ
index 3bddd80..079ff5b 100644 (file)
Binary files a/course/yui/build/moodle-course-categoryexpander/moodle-course-categoryexpander.js and b/course/yui/build/moodle-course-categoryexpander/moodle-course-categoryexpander.js differ
index d69b123..9552b46 100644 (file)
@@ -49,9 +49,35 @@ var CSS = {
  * @method init
  */
 NS.init = function() {
-    Y.one(Y.config.doc).delegate('click', this.toggle_category_expansion, SELECTORS.CATEGORYLISTENLINK, this);
-    Y.one(Y.config.doc).delegate('click', this.toggle_coursebox_expansion, SELECTORS.COURSEBOXLISTENLINK, this);
-    Y.one(Y.config.doc).delegate('click', this.collapse_expand_all, SELECTORS.COLLAPSEEXPAND, this);
+    var doc = Y.one(Y.config.doc);
+    doc.delegate('click', this.toggle_category_expansion, SELECTORS.CATEGORYLISTENLINK, this);
+    doc.delegate('click', this.toggle_coursebox_expansion, SELECTORS.COURSEBOXLISTENLINK, this);
+    doc.delegate('click', this.collapse_expand_all, SELECTORS.COLLAPSEEXPAND, this);
+
+    // Only set up they keybaord listeners when tab is first pressed - it
+    // may never happen and modifying the DOM on a large number of nodes
+    // can be very expensive.
+    doc.once('key', this.setup_keyboard_listeners, 'tab', this);
+};
+
+/**
+ * Set up keyboard expansion for course content.
+ *
+ * This includes setting up the delegation but also adding the nodes to the
+ * tabflow.
+ *
+ * @method setup_keyboard_listeners
+ */
+NS.setup_keyboard_listeners = function() {
+    var doc = Y.one(Y.config.doc);
+
+    Y.log('Setting the tabindex for all expandable course nodes', 'info', 'moodle-course-categoryexpander');
+    doc.all(SELECTORS.CATEGORYLISTENLINK, SELECTORS.COURSEBOXLISTENLINK, SELECTORS.COLLAPSEEXPAND).setAttribute('tabindex', '0');
+
+
+    Y.one(Y.config.doc).delegate('key', this.toggle_category_expansion, 'enter', SELECTORS.CATEGORYLISTENLINK, this);
+    Y.one(Y.config.doc).delegate('key', this.toggle_coursebox_expansion, 'enter', SELECTORS.COURSEBOXLISTENLINK, this);
+    Y.one(Y.config.doc).delegate('key', this.collapse_expand_all, 'enter', SELECTORS.COLLAPSEEXPAND, this);
 };
 
 /**
index db1b328..67c51f9 100644 (file)
@@ -1,7 +1,8 @@
 {
   "moodle-course-categoryexpander": {
     "requires": [
-        "node"
+        "node",
+        "event-key"
     ]
   }
 }