Skip to content

Commit

Permalink
Merge pull request #8571 from Owlbertz/keyboard-enhancements
Browse files Browse the repository at this point in the history
Enhance keyboard util.
  • Loading branch information
kball committed Apr 15, 2016
2 parents 1bf035f + 878f8ac commit 5a1450d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
9 changes: 6 additions & 3 deletions js/foundation.accordionMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -158,7 +158,10 @@ class AccordionMenu {
closeAll: function() {
_this.hideAll();
},
handled: function() {
handled: function(preventDefault) {
if (preventDefault) {
e.preventDefault();
}
e.stopImmediatePropagation();
}
});
Expand Down
16 changes: 9 additions & 7 deletions js/foundation.drilldown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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();
Expand All @@ -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();
}
});
Expand Down
13 changes: 9 additions & 4 deletions js/foundation.reveal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -342,6 +342,11 @@ class Reveal {
_this.close();
_this.$anchor.focus();
}
},
handled: function(preventDefault) {
if (preventDefault) {
e.preventDefault();
}
}
});
});
Expand Down
7 changes: 5 additions & 2 deletions js/foundation.tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,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'),
Expand Down Expand Up @@ -166,6 +165,10 @@ class Tabs {
next: function() {
$nextElement.find('[role="tab"]').focus();
_this._handleTabChange($nextElement);
},
handled: function() {
e.stopPropagation();
e.preventDefault();
}
});
});
Expand Down
6 changes: 3 additions & 3 deletions js/foundation.util.keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
},
Expand Down

0 comments on commit 5a1450d

Please sign in to comment.