Comparing version 0.4.2 to 0.4.3
18
bean.js
@@ -140,3 +140,3 @@ /*! | ||
result.keyCode = event.which || event.keyCode | ||
} else if ((/click|mouse|menu/i).test(type)) { | ||
} else if ((/click|mouse|menu|drag|drop/i).test(type)) { | ||
props = mouseProps | ||
@@ -212,3 +212,3 @@ result.rightClick = event.which === 3 || event.button === 2 | ||
// our map stores arrays by event type, just because it's better than storing | ||
// everything in a single array | ||
// everything in a single array. uses '$' as a prefix for the keys for safety | ||
var map = {} | ||
@@ -222,7 +222,7 @@ | ||
for (var t in map) { | ||
if (map.hasOwnProperty(t)) | ||
forAll(element, t, original, handler, fn) | ||
if (t.charAt(0) === '$') | ||
forAll(element, t.substr(1), original, handler, fn) | ||
} | ||
} else { | ||
var i = 0, l, list = map[type], all = element === '*' | ||
var i = 0, l, list = map['$' + type], all = element === '*' | ||
if (!list) | ||
@@ -241,3 +241,3 @@ return | ||
// needs to be fast | ||
var i, list = map[type] | ||
var i, list = map['$' + type] | ||
if (list) { | ||
@@ -259,3 +259,3 @@ for (i = list.length; i--;) { | ||
, put = function (entry) { | ||
(map[entry.type] || (map[entry.type] = [])).push(entry) | ||
(map['$' + entry.type] || (map['$' + entry.type] = [])).push(entry) | ||
return entry | ||
@@ -267,2 +267,4 @@ } | ||
list.splice(i, 1) | ||
if (list.length === 0) | ||
delete map['$' + entry.type] | ||
return false | ||
@@ -276,3 +278,3 @@ }) | ||
for (t in map) { | ||
if (map.hasOwnProperty(t)) | ||
if (t.charAt(0) === '$') | ||
entries = entries.concat(map[t]) | ||
@@ -279,0 +281,0 @@ } |
@@ -10,2 +10,2 @@ /*! | ||
*//*global module:true, define:true*/ | ||
!function(a,b,c){typeof module!="undefined"?module.exports=c(a,b):typeof define=="function"&&typeof define.amd=="object"?define(c):b[a]=c(a,b)}("bean",this,function(a,b){var c=window,d=b[a],e=/over|out/,f=/[^\.]*(?=\..*)\.|.*/,g=/\..*/,h="addEventListener",i="attachEvent",j="removeEventListener",k="detachEvent",l=document||{},m=l.documentElement||{},n=m[h],o=n?h:i,p=Array.prototype.slice,q={one:1},r=function(a,b,c){for(c=0;c<b.length;c++)a[b[c]]=1;return a}({},("click dblclick mouseup mousedown contextmenu mousewheel DOMMouseScroll mouseover mouseout mousemove selectstart selectend keydown keypress keyup orientationchange touchstart touchmove touchend touchcancel gesturestart gesturechange gestureend focus blur change reset select submit load unload beforeunload resize move DOMContentLoaded readystatechange error abort scroll "+(n?"show input invalid message readystatechange pageshow pagehide popstate hashchange offline online afterprint beforeprint dragstart dragenter dragover dragleave drag drop dragend loadstart progress suspend emptied stalled loadmetadata loadeddata canplay canplaythrough playing waiting seeking seeked ended durationchange timeupdate play pause ratechange volumechange cuechange checking noupdate downloading cached updateready obsolete ":"")).split(" ")),s=function(){function a(a,b){while((b=b.parentNode)!==null)if(b===a)return!0;return!1}function b(b){var c=b.relatedTarget;return c?c!==this&&c.prefix!=="xul"&&!/document/.test(this.toString())&&!a(this,c):c===null}return{mouseenter:{base:"mouseover",condition:b},mouseleave:{base:"mouseout",condition:b},mousewheel:{base:/Firefox/.test(navigator.userAgent)?"DOMMouseScroll":"mousewheel"}}}(),t=function(){var a="altKey attrChange attrName bubbles cancelable ctrlKey currentTarget detail eventPhase getModifierState isTrusted metaKey relatedNode relatedTarget shiftKey srcElement target timeStamp type view which".split(" "),b=a.concat("button buttons clientX clientY dataTransfer fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" ")),c=a.concat("char charCode key keyCode".split(" ")),d="preventDefault",f=function(a){return function(){a[d]?a[d]():a.returnValue=!1}},g="stopPropagation",h=function(a){return function(){a[g]?a[g]():a.cancelBubble=!0}},i=function(a){return function(){a[d](),a[g](),a.stopped=!0}},j=function(a,b,c){var d,e;for(d=c.length;d--;)e=c[d],!(e in b)&&e in a&&(b[e]=a[e])};return function(k,n){var o={originalEvent:k,isNative:n};if(!k)return o;var p,q=k.type,r=k.target||k.srcElement;o[d]=f(k),o[g]=h(k),o.stop=i(o),o.target=r&&r.nodeType===3?r.parentNode:r;if(n){if(q.indexOf("key")!==-1)p=c,o.keyCode=k.which||k.keyCode;else if(/click|mouse|menu/i.test(q)){p=b,o.rightClick=k.which===3||k.button===2,o.pos={x:0,y:0};if(k.pageX||k.pageY)o.clientX=k.pageX,o.clientY=k.pageY;else if(k.clientX||k.clientY)o.clientX=k.clientX+l.body.scrollLeft+m.scrollLeft,o.clientY=k.clientY+l.body.scrollTop+m.scrollTop;e.test(q)&&(o.relatedTarget=k.relatedTarget||k[(q==="mouseover"?"from":"to")+"Element"])}j(k,o,p||a)}return o}}(),u=function(a,b){return!n&&!b&&(a===l||a===c)?m:a},v=function(){function a(a,b,c,d,e){this.element=a,this.type=b,this.handler=c,this.original=d,this.namespaces=e,this.custom=s[b],this.isNative=r[b]&&a[o],this.eventType=n||this.isNative?b:"propertychange",this.customType=!n&&!this.isNative&&b,this.target=u(a,this.isNative),this.eventSupport=this.target[o]}return a.prototype={inNamespaces:function(a){var b,c;if(!a)return!0;if(!this.namespaces)return!1;for(b=a.length;b--;)for(c=this.namespaces.length;c--;)if(a[b]===this.namespaces[c])return!0;return!1},matches:function(a,b,c){return this.element===a&&(!b||this.original===b)&&(!c||this.handler===c)}},a}(),w=function(){var a={},b=function(c,d,e,f,g){if(!d||d==="*")for(var h in a)a.hasOwnProperty(h)&&b(c,h,e,f,g);else{var i=0,j,k=a[d],l=c==="*";if(!k)return;for(j=k.length;i<j;i++)if(l||k[i].matches(c,e,f))if(!g(k[i],k,i,d))return}},c=function(b,c,d){var e,f=a[c];if(f)for(e=f.length;e--;)if(f[e].matches(b,d,null))return!0;return!1},d=function(a,c,d){var e=[];return b(a,c,d,null,function(a){return e.push(a)}),e},e=function(b){return(a[b.type]||(a[b.type]=[])).push(b),b},f=function(a){b(a.element,a.type,null,a.handler,function(a,b,c){return b.splice(c,1),!1})},g=function(){var b,c=[];for(b in a)a.hasOwnProperty(b)&&(c=c.concat(a[b]));return c};return{has:c,get:d,put:e,del:f,entries:g}}(),x=n?function(a,b,c,d){a[d?h:j](b,c,!1)}:function(a,b,c,d,e){e&&d&&a["_on"+e]===null&&(a["_on"+e]=0),a[d?i:k]("on"+b,c)},y=function(a,b,d){return function(e){return e=t(e||((this.ownerDocument||this.document||this).parentWindow||c).event,!0),b.apply(a,[e].concat(d))}},z=function(a,b,d,e,f,g){return function(h){if(e?e.apply(this,arguments):n?!0:h&&h.propertyName==="_on"+d||!h)h&&(h=t(h||((this.ownerDocument||this.document||this).parentWindow||c).event,g)),b.apply(a,h&&(!f||f.length===0)?arguments:p.call(arguments,h?0:1).concat(f))}},A=function(a,b,c,d,e){return function(){a(b,c,e),d.apply(this,arguments)}},B=function(a,b,c,d){var e,f,h,i=b&&b.replace(g,""),j=w.get(a,i,c);for(e=0,f=j.length;e<f;e++)j[e].inNamespaces(d)&&((h=j[e]).eventSupport&&x(h.target,h.eventType,h.handler,!1,h.type),w.del(h))},C=function(a,b,c,d,e){var h,i=b.replace(g,""),j=b.replace(f,"").split(".");if(w.has(a,i,c))return a;i==="unload"&&(c=A(B,a,i,c,d)),s[i]&&(s[i].condition&&(c=z(a,c,i,s[i].condition,!0)),i=s[i].base||i),h=w.put(new v(a,i,c,d,j[0]&&j)),h.handler=h.isNative?y(a,h.handler,e):z(a,h.handler,i,!1,e,!1),h.eventSupport&&x(h.target,h.eventType,h.handler,!0,h.customType)},D=function(a,b,c){return function(d){var e,f,g=typeof a=="string"?c(a,this):a;for(e=d.target;e&&e!==this;e=e.parentNode)for(f=g.length;f--;)if(g[f]===e)return b.apply(e,arguments)}},E=function(a,b,c){var d,e,h,i,j,k=B,l=b&&typeof b=="string";if(l&&b.indexOf(" ")>0){b=b.split(" ");for(j=b.length;j--;)E(a,b[j],c);return a}h=l&&b.replace(g,""),h&&s[h]&&(h=s[h].type);if(!b||l){if(i=l&&b.replace(f,""))i=i.split(".");k(a,h,c,i)}else if(typeof b=="function")k(a,null,b);else for(d in b)b.hasOwnProperty(d)&&E(a,d,b[d]);return a},F=function(a,b,c,d,e){var f,g,h,i,j=c,k=c&&typeof c=="string";if(b&&!c&&typeof b=="object")for(f in b)b.hasOwnProperty(f)&&F.apply(this,[a,f,b[f]]);else{i=arguments.length>3?p.call(arguments,3):[],g=(k?c:b).split(" "),k&&(c=D(b,j=d,e))&&(i=p.call(i,1)),this===q&&(c=A(E,a,b,c,j));for(h=g.length;h--;)C(a,g[h],c,j,i)}return a},G=function(){return F.apply(q,arguments)},H=n?function(a,b,d){var e=l.createEvent(a?"HTMLEvents":"UIEvents");e[a?"initEvent":"initUIEvent"](b,!0,!0,c,1),d.dispatchEvent(e)}:function(a,b,c){c=u(c,a),a?c.fireEvent("on"+b,l.createEventObject()):c["_on"+b]++},I=function(a,b,c){var d,e,h,i,j,k=b.split(" ");for(d=k.length;d--;){b=k[d].replace(g,"");if(i=k[d].replace(f,""))i=i.split(".");if(!i&&!c&&a[o])H(r[b],b,a);else{j=w.get(a,b),c=[!1].concat(c);for(e=0,h=j.length;e<h;e++)j[e].inNamespaces(i)&&j[e].handler.apply(a,c)}}return a},J=function(a,b,c){var d=0,e=w.get(b,c),f=e.length;for(;d<f;d++)e[d].original&&F(a,e[d].type,e[d].original);return a},K={add:F,one:G,remove:E,clone:J,fire:I,noConflict:function(){return b[a]=d,this}};if(c[i]){var L=function(){var a,b=w.entries();for(a in b)b[a].type&&b[a].type!=="unload"&&E(b[a].element,b[a].type);c[k]("onunload",L),c.CollectGarbage&&c.CollectGarbage()};c[i]("onunload",L)}return K}) | ||
!function(a,b,c){typeof module!="undefined"?module.exports=c(a,b):typeof define=="function"&&typeof define.amd=="object"?define(c):b[a]=c(a,b)}("bean",this,function(a,b){var c=window,d=b[a],e=/over|out/,f=/[^\.]*(?=\..*)\.|.*/,g=/\..*/,h="addEventListener",i="attachEvent",j="removeEventListener",k="detachEvent",l=document||{},m=l.documentElement||{},n=m[h],o=n?h:i,p=Array.prototype.slice,q={one:1},r=function(a,b,c){for(c=0;c<b.length;c++)a[b[c]]=1;return a}({},("click dblclick mouseup mousedown contextmenu mousewheel DOMMouseScroll mouseover mouseout mousemove selectstart selectend keydown keypress keyup orientationchange touchstart touchmove touchend touchcancel gesturestart gesturechange gestureend focus blur change reset select submit load unload beforeunload resize move DOMContentLoaded readystatechange error abort scroll "+(n?"show input invalid message readystatechange pageshow pagehide popstate hashchange offline online afterprint beforeprint dragstart dragenter dragover dragleave drag drop dragend loadstart progress suspend emptied stalled loadmetadata loadeddata canplay canplaythrough playing waiting seeking seeked ended durationchange timeupdate play pause ratechange volumechange cuechange checking noupdate downloading cached updateready obsolete ":"")).split(" ")),s=function(){function a(a,b){while((b=b.parentNode)!==null)if(b===a)return!0;return!1}function b(b){var c=b.relatedTarget;return c?c!==this&&c.prefix!=="xul"&&!/document/.test(this.toString())&&!a(this,c):c===null}return{mouseenter:{base:"mouseover",condition:b},mouseleave:{base:"mouseout",condition:b},mousewheel:{base:/Firefox/.test(navigator.userAgent)?"DOMMouseScroll":"mousewheel"}}}(),t=function(){var a="altKey attrChange attrName bubbles cancelable ctrlKey currentTarget detail eventPhase getModifierState isTrusted metaKey relatedNode relatedTarget shiftKey srcElement target timeStamp type view which".split(" "),b=a.concat("button buttons clientX clientY dataTransfer fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" ")),c=a.concat("char charCode key keyCode".split(" ")),d="preventDefault",f=function(a){return function(){a[d]?a[d]():a.returnValue=!1}},g="stopPropagation",h=function(a){return function(){a[g]?a[g]():a.cancelBubble=!0}},i=function(a){return function(){a[d](),a[g](),a.stopped=!0}},j=function(a,b,c){var d,e;for(d=c.length;d--;)e=c[d],!(e in b)&&e in a&&(b[e]=a[e])};return function(k,n){var o={originalEvent:k,isNative:n};if(!k)return o;var p,q=k.type,r=k.target||k.srcElement;o[d]=f(k),o[g]=h(k),o.stop=i(o),o.target=r&&r.nodeType===3?r.parentNode:r;if(n){if(q.indexOf("key")!==-1)p=c,o.keyCode=k.which||k.keyCode;else if(/click|mouse|menu|drag|drop/i.test(q)){p=b,o.rightClick=k.which===3||k.button===2,o.pos={x:0,y:0};if(k.pageX||k.pageY)o.clientX=k.pageX,o.clientY=k.pageY;else if(k.clientX||k.clientY)o.clientX=k.clientX+l.body.scrollLeft+m.scrollLeft,o.clientY=k.clientY+l.body.scrollTop+m.scrollTop;e.test(q)&&(o.relatedTarget=k.relatedTarget||k[(q==="mouseover"?"from":"to")+"Element"])}j(k,o,p||a)}return o}}(),u=function(a,b){return!n&&!b&&(a===l||a===c)?m:a},v=function(){function a(a,b,c,d,e){this.element=a,this.type=b,this.handler=c,this.original=d,this.namespaces=e,this.custom=s[b],this.isNative=r[b]&&a[o],this.eventType=n||this.isNative?b:"propertychange",this.customType=!n&&!this.isNative&&b,this.target=u(a,this.isNative),this.eventSupport=this.target[o]}return a.prototype={inNamespaces:function(a){var b,c;if(!a)return!0;if(!this.namespaces)return!1;for(b=a.length;b--;)for(c=this.namespaces.length;c--;)if(a[b]===this.namespaces[c])return!0;return!1},matches:function(a,b,c){return this.element===a&&(!b||this.original===b)&&(!c||this.handler===c)}},a}(),w=function(){var a={},b=function(c,d,e,f,g){if(!d||d==="*")for(var h in a)h.charAt(0)==="$"&&b(c,h.substr(1),e,f,g);else{var i=0,j,k=a["$"+d],l=c==="*";if(!k)return;for(j=k.length;i<j;i++)if(l||k[i].matches(c,e,f))if(!g(k[i],k,i,d))return}},c=function(b,c,d){var e,f=a["$"+c];if(f)for(e=f.length;e--;)if(f[e].matches(b,d,null))return!0;return!1},d=function(a,c,d){var e=[];return b(a,c,d,null,function(a){return e.push(a)}),e},e=function(b){return(a["$"+b.type]||(a["$"+b.type]=[])).push(b),b},f=function(c){b(c.element,c.type,null,c.handler,function(b,c,d){return c.splice(d,1),c.length===0&&delete a["$"+b.type],!1})},g=function(){var b,c=[];for(b in a)b.charAt(0)==="$"&&(c=c.concat(a[b]));return c};return{has:c,get:d,put:e,del:f,entries:g}}(),x=n?function(a,b,c,d){a[d?h:j](b,c,!1)}:function(a,b,c,d,e){e&&d&&a["_on"+e]===null&&(a["_on"+e]=0),a[d?i:k]("on"+b,c)},y=function(a,b,d){return function(e){return e=t(e||((this.ownerDocument||this.document||this).parentWindow||c).event,!0),b.apply(a,[e].concat(d))}},z=function(a,b,d,e,f,g){return function(h){if(e?e.apply(this,arguments):n?!0:h&&h.propertyName==="_on"+d||!h)h&&(h=t(h||((this.ownerDocument||this.document||this).parentWindow||c).event,g)),b.apply(a,h&&(!f||f.length===0)?arguments:p.call(arguments,h?0:1).concat(f))}},A=function(a,b,c,d,e){return function(){a(b,c,e),d.apply(this,arguments)}},B=function(a,b,c,d){var e,f,h,i=b&&b.replace(g,""),j=w.get(a,i,c);for(e=0,f=j.length;e<f;e++)j[e].inNamespaces(d)&&((h=j[e]).eventSupport&&x(h.target,h.eventType,h.handler,!1,h.type),w.del(h))},C=function(a,b,c,d,e){var h,i=b.replace(g,""),j=b.replace(f,"").split(".");if(w.has(a,i,c))return a;i==="unload"&&(c=A(B,a,i,c,d)),s[i]&&(s[i].condition&&(c=z(a,c,i,s[i].condition,!0)),i=s[i].base||i),h=w.put(new v(a,i,c,d,j[0]&&j)),h.handler=h.isNative?y(a,h.handler,e):z(a,h.handler,i,!1,e,!1),h.eventSupport&&x(h.target,h.eventType,h.handler,!0,h.customType)},D=function(a,b,c){return function(d){var e,f,g=typeof a=="string"?c(a,this):a;for(e=d.target;e&&e!==this;e=e.parentNode)for(f=g.length;f--;)if(g[f]===e)return b.apply(e,arguments)}},E=function(a,b,c){var d,e,h,i,j,k=B,l=b&&typeof b=="string";if(l&&b.indexOf(" ")>0){b=b.split(" ");for(j=b.length;j--;)E(a,b[j],c);return a}h=l&&b.replace(g,""),h&&s[h]&&(h=s[h].type);if(!b||l){if(i=l&&b.replace(f,""))i=i.split(".");k(a,h,c,i)}else if(typeof b=="function")k(a,null,b);else for(d in b)b.hasOwnProperty(d)&&E(a,d,b[d]);return a},F=function(a,b,c,d,e){var f,g,h,i,j=c,k=c&&typeof c=="string";if(b&&!c&&typeof b=="object")for(f in b)b.hasOwnProperty(f)&&F.apply(this,[a,f,b[f]]);else{i=arguments.length>3?p.call(arguments,3):[],g=(k?c:b).split(" "),k&&(c=D(b,j=d,e))&&(i=p.call(i,1)),this===q&&(c=A(E,a,b,c,j));for(h=g.length;h--;)C(a,g[h],c,j,i)}return a},G=function(){return F.apply(q,arguments)},H=n?function(a,b,d){var e=l.createEvent(a?"HTMLEvents":"UIEvents");e[a?"initEvent":"initUIEvent"](b,!0,!0,c,1),d.dispatchEvent(e)}:function(a,b,c){c=u(c,a),a?c.fireEvent("on"+b,l.createEventObject()):c["_on"+b]++},I=function(a,b,c){var d,e,h,i,j,k=b.split(" ");for(d=k.length;d--;){b=k[d].replace(g,"");if(i=k[d].replace(f,""))i=i.split(".");if(!i&&!c&&a[o])H(r[b],b,a);else{j=w.get(a,b),c=[!1].concat(c);for(e=0,h=j.length;e<h;e++)j[e].inNamespaces(i)&&j[e].handler.apply(a,c)}}return a},J=function(a,b,c){var d=0,e=w.get(b,c),f=e.length;for(;d<f;d++)e[d].original&&F(a,e[d].type,e[d].original);return a},K={add:F,one:G,remove:E,clone:J,fire:I,noConflict:function(){return b[a]=d,this}};if(c[i]){var L=function(){var a,b=w.entries();for(a in b)b[a].type&&b[a].type!=="unload"&&E(b[a].element,b[a].type);c[k]("onunload",L),c.CollectGarbage&&c.CollectGarbage()};c[i]("onunload",L)}return K}) |
{ | ||
"name": "bean", | ||
"description": "an events api for javascript", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"homepage": "https://github.com/fat/bean", | ||
@@ -6,0 +6,0 @@ "authors": ["Jacob Thornton <@fat>", "Dustin Diaz <@ded>", "Rod Vagg <@rvagg>"], |
@@ -131,3 +131,3 @@ /*global module:true, define:true*/ | ||
result.keyCode = event.which || event.keyCode | ||
} else if ((/click|mouse|menu/i).test(type)) { | ||
} else if ((/click|mouse|menu|drag|drop/i).test(type)) { | ||
props = mouseProps | ||
@@ -203,3 +203,3 @@ result.rightClick = event.which === 3 || event.button === 2 | ||
// our map stores arrays by event type, just because it's better than storing | ||
// everything in a single array | ||
// everything in a single array. uses '$' as a prefix for the keys for safety | ||
var map = {} | ||
@@ -213,7 +213,7 @@ | ||
for (var t in map) { | ||
if (map.hasOwnProperty(t)) | ||
forAll(element, t, original, handler, fn) | ||
if (t.charAt(0) === '$') | ||
forAll(element, t.substr(1), original, handler, fn) | ||
} | ||
} else { | ||
var i = 0, l, list = map[type], all = element === '*' | ||
var i = 0, l, list = map['$' + type], all = element === '*' | ||
if (!list) | ||
@@ -232,3 +232,3 @@ return | ||
// needs to be fast | ||
var i, list = map[type] | ||
var i, list = map['$' + type] | ||
if (list) { | ||
@@ -250,3 +250,3 @@ for (i = list.length; i--;) { | ||
, put = function (entry) { | ||
(map[entry.type] || (map[entry.type] = [])).push(entry) | ||
(map['$' + entry.type] || (map['$' + entry.type] = [])).push(entry) | ||
return entry | ||
@@ -258,2 +258,4 @@ } | ||
list.splice(i, 1) | ||
if (list.length === 0) | ||
delete map['$' + entry.type] | ||
return false | ||
@@ -267,3 +269,3 @@ }) | ||
for (t in map) { | ||
if (map.hasOwnProperty(t)) | ||
if (t.charAt(0) === '$') | ||
entries = entries.concat(map[t]) | ||
@@ -270,0 +272,0 @@ } |
1062575
26833