]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Enhance keyboard util. 8571/head
authorMarius Olbertz <marius.olbertz@gmail.com>
Mon, 11 Apr 2016 14:27:41 +0000 (16:27 +0200)
committerMarius Olbertz <marius.olbertz@gmail.com>
Mon, 11 Apr 2016 14:27:41 +0000 (16:27 +0200)
Enhanced keyboard util by adding a parameter that is passed to the `handled` function based on the evaluation of the function that was handled.
It is now easier to only do certain actions (e.g. calling `preventDefaul()`) in the `handled` handler by letting the other function (e.g. `next`, `up`, ...) return some value, which is directly passed into `handled` as the first parameter.
I also adjusted the calls to the keyboard util for some plugins to fix issues and prevent bad behavior.

js/foundation.accordionMenu.js
js/foundation.drilldown.js
js/foundation.reveal.js
js/foundation.tabs.js
js/foundation.util.keyboard.js

index 39cc9fd9b594d196b3aa2df35f72cfb2726ab6d6..212e4584f2e82821f2a694aec5e07f0dbf151a11 100644 (file)
@@ -144,11 +144,11 @@ class AccordionMenu {
         },
         up: function() {
           $prevElement.attr('tabindex', -1).focus();
-          e.preventDefault();
+          return true;
         },
         down: function() {
           $nextElement.attr('tabindex', -1).focus();
-          e.preventDefault();
+          return true;
         },
         toggle: function() {
           if ($element.children('[data-submenu]').length) {
@@ -158,7 +158,10 @@ class AccordionMenu {
         closeAll: function() {
           _this.hideAll();
         },
-        handled: function() {
+        handled: function(preventDefault) {
+          if (preventDefault) {
+            e.preventDefault();
+          }
           e.stopImmediatePropagation();
         }
       });
index f716f7efe4f720aafa5367fa6f6dc1b0addd2e06..da36d13cfca7d909998891eb3061bba096c3ee2c 100644 (file)
@@ -155,7 +155,7 @@ class Drilldown {
             $element.parent('li').one(Foundation.transitionend($element), function(){
               $element.parent('li').find('ul li a').filter(_this.$menuItems).first().focus();
             });
-            e.preventDefault();
+            return true;
           }
         },
         previous: function() {
@@ -165,15 +165,15 @@ class Drilldown {
               $element.parent('li').parent('ul').parent('li').children('a').first().focus();
             }, 1);
           });
-          e.preventDefault();
+          return true;
         },
         up: function() {
           $prevElement.focus();
-          e.preventDefault();
+          return true;
         },
         down: function() {
           $nextElement.focus();
-          e.preventDefault();
+          return true;
         },
         close: function() {
           _this._back();
@@ -187,16 +187,18 @@ class Drilldown {
                 $element.parent('li').parent('ul').parent('li').children('a').first().focus();
               }, 1);
             });            
-            e.preventDefault();
           } else if ($element.is(_this.$submenuAnchors)) {
             _this._show($element.parent('li'));
             $element.parent('li').one(Foundation.transitionend($element), function(){
               $element.parent('li').find('ul li a').filter(_this.$menuItems).first().focus();
             });            
-            e.preventDefault();
           }
+          return true;
         },
-        handled: function() {
+        handled: function(preventDefault) {
+          if (preventDefault) {
+            e.preventDefault();
+          }
           e.stopImmediatePropagation();
         }
       });
index 29bd3571dcb9e2b30c6c9cd3f35ab9cf00f6b0bb..660970144647054dc5819954c82acf3010b2bccb 100644 (file)
@@ -313,19 +313,19 @@ class Reveal {
         tab_forward: function() {
           if (_this.$element.find(':focus').is(_this.focusableElements.eq(-1))) { // left modal downwards, setting focus to first element
             _this.focusableElements.eq(0).focus();
-            e.preventDefault();
+            return true;
           }
           if (_this.focusableElements.length === 0) { // no focusable elements inside the modal at all, prevent tabbing in general
-            e.preventDefault();
+            return true;
           }
         },
         tab_backward: function() {
           if (_this.$element.find(':focus').is(_this.focusableElements.eq(0)) || _this.$element.is(':focus')) { // left modal upwards, setting focus to last element
             _this.focusableElements.eq(-1).focus();
-            e.preventDefault();
+            return true;
           }
           if (_this.focusableElements.length === 0) { // no focusable elements inside the modal at all, prevent tabbing in general
-            e.preventDefault();
+            return true;
           }
         },
         open: function() {
@@ -342,6 +342,11 @@ class Reveal {
             _this.close();
             _this.$anchor.focus();
           }
+        },
+        handled: function(preventDefault) {
+          if (preventDefault) {
+            e.preventDefault();
+          }
         }
       });
     });
index 48bebc9bf4fad52e8abd7e238babaa0352d5b806..d5d7e53e8344278f807eec68e376135b25dbc3c1 100644 (file)
@@ -129,8 +129,7 @@ class Tabs {
 
     this.$tabTitles.off('keydown.zf.tabs').on('keydown.zf.tabs', function(e){
       if (e.which === 9) return;
-      e.stopPropagation();
-      e.preventDefault();
+      
 
       var $element = $(this),
         $elements = $element.parent('ul').children('li'),
@@ -163,6 +162,10 @@ class Tabs {
         next: function() {
           $nextElement.find('[role="tab"]').focus();
           _this._handleTabChange($nextElement);
+        },
+        handled: function() {
+          e.stopPropagation();
+          e.preventDefault();
         }
       });
     });
index 75dc16aa290c84a5f27d8ad6fc329e1a170efcee..290e743829291abb17f4caf91f8ee6419a542d99 100644 (file)
@@ -66,13 +66,13 @@ var Keyboard = {
 
     fn = functions[command];
     if (fn && typeof fn === 'function') { // execute function  if exists
-      fn.apply();
+      var returnValue = fn.apply();
       if (functions.handled || typeof functions.handled === 'function') { // execute function when event was handled
-          functions.handled.apply();
+          functions.handled(returnValue);
       }
     } else {
       if (functions.unhandled || typeof functions.unhandled === 'function') { // execute function when event was not handled
-          functions.unhandled.apply();
+          functions.unhandled();
       }
     }
   },