Skip to content

Commit

Permalink
fixing custom events which could incorrectly have matched as natives
Browse files Browse the repository at this point in the history
  • Loading branch information
fat committed May 3, 2011
1 parent 86529a1 commit 7f08151
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
28 changes: 14 additions & 14 deletions bean.js
Expand Up @@ -76,7 +76,7 @@
fn = custom.condition ? customHandler(element, fn, type, custom.condition) : fn;
type = custom.base || type;
}
var isNative = W3C_MODEL || nativeEvents.indexOf(type) > -1;
var isNative = W3C_MODEL || !~nativeEvents.indexOf('|' + type + '|');
fn = isNative ? nativeHandler(element, fn, args) : customHandler(element, fn, type, false, args);
if (type == 'unload') {
var org = fn;
Expand All @@ -103,7 +103,7 @@
delete events[type][uid];
if (element[eventSupport]) {
type = customEvents[type] ? customEvents[type].base : type;
var isNative = element[addEvent] || nativeEvents.indexOf(type) > -1;
var isNative = W3C_MODEL || !~nativeEvents.indexOf('|' + type + '|');
listener(element, isNative ? type : 'propertychange', handler, false, !isNative && type);
}
}
Expand Down Expand Up @@ -173,7 +173,7 @@
var evt, k, i, types = type.split(' ');
for (i = types.length; i--;) {
type = types[i].replace(stripName, '');
var isNative = nativeEvents.indexOf(type) > -1,
var isNative = !~nativeEvents.indexOf('|' + type + '|'),
isNamespace = types[i].replace(namespace, ''),
handlers = retrieveEvents(element)[type];
if (isNamespace) {
Expand Down Expand Up @@ -218,7 +218,7 @@
result.preventDefault = fixEvent.preventDefault(e);
result.stopPropagation = fixEvent.stopPropagation(e);
result.target = target && target.nodeType == 3 ? target.parentNode : target;
if (type.indexOf('key') != -1) {
if (!~type.indexOf('key')) {
result.keyCode = e.which || e.keyCode;
} else if ((/click|mouse|menu/i).test(type)) {
result.rightClick = e.which == 3 || e.button == 2;
Expand Down Expand Up @@ -261,16 +261,16 @@
};
};

var nativeEvents = 'click,dblclick,mouseup,mousedown,contextmenu,' + //mouse buttons
'mousewheel,DOMMouseScroll,' + //mouse wheel
'mouseover,mouseout,mousemove,selectstart,selectend,' + //mouse movement
'keydown,keypress,keyup,' + //keyboard
'orientationchange,' + // mobile
'touchstart,touchmove,touchend,touchcancel,' + // touch
'gesturestart,gesturechange,gestureend,' + // gesture
'focus,blur,change,reset,select,submit,' + //form elements
'load,unload,beforeunload,resize,move,DOMContentLoaded,readystatechange,' + //window
'error,abort,scroll'.split(','); //misc
var nativeEvents = '|click|dblclick|mouseup|mousedown|contextmenu|' + //mouse buttons
'mousewheel|DOMMouseScroll|' + //mouse wheel
'mouseover|mouseout|mousemove|selectstart|selectend|' + //mouse movement
'keydown|keypress|keyup|' + //keyboard
'orientationchange|' + // mobile
'touchstart|touchmove|touchend|touchcancel|' + // touch
'gesturestart|gesturechange|gestureend|' + // gesture
'focus|blur|change|reset|select|submit|' + //form elements
'load|unload|beforeunload|resize|move|DOMContentLoaded|readystatechange|' + //window
'error|abort|scroll|'; //misc

function check(event) {
var related = event.relatedTarget;
Expand Down
2 changes: 1 addition & 1 deletion bean.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions src/bean.js
Expand Up @@ -66,7 +66,7 @@
fn = custom.condition ? customHandler(element, fn, type, custom.condition) : fn;
type = custom.base || type;
}
var isNative = W3C_MODEL || nativeEvents.indexOf(type) > -1;
var isNative = W3C_MODEL || !~nativeEvents.indexOf('|' + type + '|');
fn = isNative ? nativeHandler(element, fn, args) : customHandler(element, fn, type, false, args);
if (type == 'unload') {
var org = fn;
Expand All @@ -93,7 +93,7 @@
delete events[type][uid];
if (element[eventSupport]) {
type = customEvents[type] ? customEvents[type].base : type;
var isNative = element[addEvent] || nativeEvents.indexOf(type) > -1;
var isNative = W3C_MODEL || !~nativeEvents.indexOf('|' + type + '|');
listener(element, isNative ? type : 'propertychange', handler, false, !isNative && type);
}
}
Expand Down Expand Up @@ -163,7 +163,7 @@
var evt, k, i, types = type.split(' ');
for (i = types.length; i--;) {
type = types[i].replace(stripName, '');
var isNative = nativeEvents.indexOf(type) > -1,
var isNative = !~nativeEvents.indexOf('|' + type + '|'),
isNamespace = types[i].replace(namespace, ''),
handlers = retrieveEvents(element)[type];
if (isNamespace) {
Expand Down Expand Up @@ -208,7 +208,7 @@
result.preventDefault = fixEvent.preventDefault(e);
result.stopPropagation = fixEvent.stopPropagation(e);
result.target = target && target.nodeType == 3 ? target.parentNode : target;
if (type.indexOf('key') != -1) {
if (!~type.indexOf('key')) {
result.keyCode = e.which || e.keyCode;
} else if ((/click|mouse|menu/i).test(type)) {
result.rightClick = e.which == 3 || e.button == 2;
Expand Down Expand Up @@ -251,16 +251,16 @@
};
};

var nativeEvents = 'click,dblclick,mouseup,mousedown,contextmenu,' + //mouse buttons
'mousewheel,DOMMouseScroll,' + //mouse wheel
'mouseover,mouseout,mousemove,selectstart,selectend,' + //mouse movement
'keydown,keypress,keyup,' + //keyboard
'orientationchange,' + // mobile
'touchstart,touchmove,touchend,touchcancel,' + // touch
'gesturestart,gesturechange,gestureend,' + // gesture
'focus,blur,change,reset,select,submit,' + //form elements
'load,unload,beforeunload,resize,move,DOMContentLoaded,readystatechange,' + //window
'error,abort,scroll'.split(','); //misc
var nativeEvents = '|click|dblclick|mouseup|mousedown|contextmenu|' + //mouse buttons
'mousewheel|DOMMouseScroll|' + //mouse wheel
'mouseover|mouseout|mousemove|selectstart|selectend|' + //mouse movement
'keydown|keypress|keyup|' + //keyboard
'orientationchange|' + // mobile
'touchstart|touchmove|touchend|touchcancel|' + // touch
'gesturestart|gesturechange|gestureend|' + // gesture
'focus|blur|change|reset|select|submit|' + //form elements
'load|unload|beforeunload|resize|move|DOMContentLoaded|readystatechange|' + //window
'error|abort|scroll|'; //misc

function check(event) {
var related = event.relatedTarget;
Expand Down

0 comments on commit 7f08151

Please sign in to comment.