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.
},
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) {
closeAll: function() {
_this.hideAll();
},
- handled: function() {
+ handled: function(preventDefault) {
+ if (preventDefault) {
+ e.preventDefault();
+ }
e.stopImmediatePropagation();
}
});
$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() {
$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();
$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();
}
});
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() {
_this.close();
_this.$anchor.focus();
}
+ },
+ handled: function(preventDefault) {
+ if (preventDefault) {
+ e.preventDefault();
+ }
}
});
});
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'),
next: function() {
$nextElement.find('[role="tab"]').focus();
_this._handleTabChange($nextElement);
+ },
+ handled: function() {
+ e.stopPropagation();
+ e.preventDefault();
}
});
});
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();
}
}
},