angular-hotkeys
angular-hotkeys copied to clipboard
return false within a callBack does not prevent event
function _fireCallback(callback, e, combo, sequence) {
// if this event should not happen stop here
if (Mousetrap.stopCallback(e, e.target || e.srcElement, combo, sequence)) {
return;
}
if (callback(e, combo) === false) {
_preventDefault(e);
_stopPropagation(e);
}
}
I saw that if my callBack returns false event is prevented. But the wrapper never return my result :
/**
* All callbacks sent to Mousetrap are wrapped using this function
* so that we can force a $scope.$apply()
*
* @param {Function} callback [description]
* @return {[type]} [description]
*/
function wrapApply (callback) {
// return mousetrap a function to call
return function (event, combo) {
// if this is an array, it means we provided a route object
// because the scope wasn't available yet, so rewrap the callback
// now that the scope is available:
if (callback instanceof Array) {
var funcString = callback[0];
var route = callback[1];
callback = function (event) {
route.scope.$eval(funcString);
};
}
// this takes place outside angular, so we'll have to call
// $apply() to make sure angular's digest happens
$rootScope.$apply(function() {
// call the original hotkey callback with the keyboard event
callback(event, _get(combo));
});
};
}
I'm wondering how I can manage this ? Thank you
See #39 for a patch for this (though it may be outdated by now). I never got around to adding any tests, so Wes never merged it. (Sorry.)