Comparing version 0.0.1 to 0.0.2
267
bean.js
/*! | ||
* event.js - copyright @dedfat | ||
* bean.js - copyright @dedfat | ||
* https://github.com/fat/bean | ||
* Follow our software http://twitter.com/dedfat | ||
* MIT License | ||
* cheers to the entire mootools team, dean edwards, and dperini | ||
* special thanks to: | ||
* dean edwards: http://dean.edwards.name/ | ||
* dperini: https://github.com/dperini/nwevents | ||
* the entire mootools team: github.com/mootools/mootools-core | ||
*/ | ||
!function (context) { | ||
var _uid = 1, registry = {}, collected = {}, | ||
var __uid = 1, registry = {}, collected = {}, | ||
overOut = /over|out/, | ||
namespace = /[^\.]*(?=\..*)\.|.*/, | ||
stripName = /\..*/, | ||
addEvent = 'addEventListener', | ||
@@ -24,9 +29,4 @@ attachEvent = 'attachEvent', | ||
} | ||
return false; | ||
} | ||
function isElement(obj) { | ||
return !!obj.nodeName; | ||
} | ||
function retrieveEvents(element) { | ||
@@ -37,17 +37,13 @@ var uid = retrieveUid(element); | ||
function retrieveUid(obj) { | ||
return (obj._uid = obj._uid || _uid++); | ||
function retrieveUid(obj, uid) { | ||
return (obj.__uid = uid || obj.__uid || __uid++); | ||
} | ||
function listener(element, type, fn, add, custom) { | ||
if (!isElement(element)) { | ||
return; | ||
} | ||
if (element[addEvent]) { | ||
return element[add ? addEvent : removeEvent](type, fn, false); | ||
element[add ? addEvent : removeEvent](type, fn, false); | ||
} else if (element[attachEvent]) { | ||
custom && add && (element['_on' + custom] = element['_on' + custom] || 0); | ||
element[add ? attachEvent : detachEvent]('on' + type, fn); | ||
} | ||
if (custom && add) { | ||
element['_on' + custom] = element['_on' + custom] || 0; | ||
} | ||
element[add ? attachEvent : detachEvent]('on' + type, fn); | ||
} | ||
@@ -57,9 +53,4 @@ | ||
return function (event) { | ||
event = fixEvent(event || ((this.ownerDocument || this.document || this).parentWindow || window).event); | ||
if (fn.apply(element, [event].concat(args)) === false) { | ||
if (event) { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
} | ||
} | ||
event = fixEvent(event || ((this.ownerDocument || this.document || this).parentWindow || context).event); | ||
return fn.apply(element, [event].concat(args)); | ||
}; | ||
@@ -73,16 +64,9 @@ } | ||
} | ||
return true; | ||
}; | ||
} | ||
function addListener(element, type, fn, args) { | ||
var events = retrieveEvents(element), | ||
handlers = events[type]; | ||
if (!handlers) { | ||
handlers = events[type] = {}; | ||
if (element["on" + type]) { | ||
handlers[0] = element["on" + type]; | ||
} | ||
} | ||
var uid = retrieveUid(fn); | ||
function addListener(element, orgType, fn, args) { | ||
var type = orgType.replace(stripName, ''), events = retrieveEvents(element), | ||
handlers = events[type] || (events[type] = {}), | ||
uid = retrieveUid(fn, orgType.replace(namespace, '')); | ||
if (handlers[uid]) { | ||
@@ -92,39 +76,32 @@ return element; | ||
var custom = customEvents[type]; | ||
if (custom) { | ||
if (custom.condition) { | ||
fn = customHandler(element, fn, type, custom.condition); | ||
} | ||
type = custom.base || type; | ||
fn = custom && custom.condition ? customHandler(element, fn, type, custom.condition) : fn; | ||
type = custom && custom.base || type; | ||
var isNative = context[addEvent] || nativeEvents.indexOf(type) > -1; | ||
fn = isNative ? nativeHandler(element, fn, args) : customHandler(element, fn, type, false, args); | ||
if (type == 'unload') { | ||
var org = fn; | ||
fn = function () { | ||
removeListener(element, type, fn) && org(); | ||
}; | ||
} | ||
if (window[addEvent] || nativeEvents.indexOf(type) > -1) { | ||
fn = nativeHandler(element, fn, args); | ||
if (type == 'unload') { //unload only once | ||
var org = fn; | ||
fn = function () { | ||
removeListener(element, 'unload', fn); | ||
org(); | ||
}; | ||
} | ||
listener(element, type, fn, true); | ||
} else { | ||
fn = customHandler(element, fn, type, false, args); | ||
listener(element, 'propertychange', fn, true, type); | ||
} | ||
listener(element, isNative ? type : 'propertychange', fn, true, !isNative && true); | ||
handlers[uid] = fn; | ||
fn._uid = uid; | ||
fn.__uid = uid; | ||
return type == 'unload' ? element : (collected[retrieveUid(element)] = element); | ||
} | ||
function removeListener(element, type, handler) { | ||
var events = retrieveEvents(element); | ||
function removeListener(element, orgType, handler) { | ||
var uid, names, uids, i, events = retrieveEvents(element), type = orgType.replace(stripName, ''); | ||
if (!events || !events[type]) { | ||
return element; | ||
} | ||
handler = events[type][handler._uid]; | ||
delete events[type][handler._uid]; | ||
type = customEvents[type] ? customEvents[type].base : type; | ||
if (element[addEvent] || nativeEvents.indexOf(type) > -1) { | ||
listener(element, type, handler, false); | ||
} else { | ||
listener(element, 'propertychange', handler, false, type); | ||
names = orgType.replace(namespace, ''); | ||
uids = names ? names.split('.') : [handler.__uid]; | ||
for (i = uids.length; i--;) { | ||
uid = uids[i]; | ||
handler = events[type][uid]; | ||
delete events[type][uid]; | ||
type = customEvents[type] ? customEvents[type].base : type; | ||
var isNative = element[addEvent] || nativeEvents.indexOf(type) > -1; | ||
listener(element, isNative ? type : 'propertychange', handler, false, !isNative && type); | ||
} | ||
@@ -134,3 +111,3 @@ return element; | ||
function processDelegates(selector, fn, $) { | ||
function del(selector, fn, $) { | ||
return function (e) { | ||
@@ -148,19 +125,12 @@ var array = typeof selector == 'string' ? $(selector, this) : selector; | ||
function add(element, events, fn, delegatefn, $) { | ||
function add(element, events, fn, delfn, $) { | ||
if (typeof events == 'object' && !fn) { | ||
for (var type in events) { | ||
if (events.hasOwnProperty(type)) { | ||
addListener(element, type, events[type]); | ||
} | ||
events.hasOwnProperty(type) && add(element, type, events[type]); | ||
} | ||
} else { | ||
var isDelegation = typeof fn == 'string', | ||
types = (isDelegation ? fn : events).split(' '); | ||
var isDel = typeof fn == 'string', types = (isDel ? fn : events).split(' '); | ||
fn = isDel ? del(events, delfn, $) : fn; | ||
for (var i = types.length; i--;) { | ||
addListener( | ||
element, | ||
types[i], | ||
isDelegation ? processDelegates(events, delegatefn, $) : fn, | ||
Array.prototype.slice.call(arguments, isDelegation ? 4 : 3) | ||
); | ||
addListener(element, types[i], fn, Array.prototype.slice.call(arguments, isDel ? 4 : 3)); | ||
} | ||
@@ -171,11 +141,15 @@ } | ||
function remove(element, events, fn) { | ||
var k, type, isString = typeof(events) == 'string', rm = removeListener, attached = retrieveEvents(element); | ||
if (isString && /\s/.test(events)) { | ||
events = events.split(' '); | ||
for (var i = events.length; i--;) { | ||
remove(element, events[i]); | ||
} | ||
function remove(element, orgEvents, fn) { | ||
var k, type, events, | ||
isString = typeof(orgEvents) == 'string', | ||
names = isString && orgEvents.replace(namespace, ''), | ||
rm = removeListener, | ||
attached = retrieveEvents(element); | ||
if (isString && /\s/.test(orgEvents)) { | ||
orgEvents = orgEvents.split(' '); | ||
var i = orgEvents.length - 1; | ||
while (remove(element, orgEvents[i]) && i--) {} | ||
return element; | ||
} | ||
events = isString ? orgEvents.replace(stripName, '') : orgEvents; | ||
if (!attached || (isString && !attached[events])) { | ||
@@ -186,14 +160,10 @@ return element; | ||
rm(element, events, fn); | ||
} else if (names) { | ||
rm(element, orgEvents); | ||
} else { | ||
if (!events) { | ||
events = attached; | ||
rm = remove; | ||
} else { | ||
type = isString && events; | ||
events = fn || attached[events] || events; | ||
} | ||
rm = events ? rm : remove; | ||
type = isString && events; | ||
events = events ? (fn || attached[events] || events) : attached; | ||
for (k in events) { | ||
if (events.hasOwnProperty(k)) { | ||
rm(element, type || k, events[k]); | ||
} | ||
events.hasOwnProperty(k) && rm(element, type || k, events[k]); | ||
} | ||
@@ -207,27 +177,20 @@ } | ||
for (i = types.length; i--;) { | ||
type = types[i]; | ||
if (!isElement(element)) { | ||
var handlers = retrieveEvents(element)[type]; | ||
for (k in handlers) { | ||
if (handlers.hasOwnProperty(k)) { | ||
handlers[k](); | ||
} | ||
type = types[i].replace(stripName, ''); | ||
var isNative = nativeEvents.indexOf(type) > -1, | ||
isNamespace = types[i].replace(namespace, ''), | ||
handlers = retrieveEvents(element)[type]; | ||
if (isNamespace) { | ||
isNamespace = isNamespace.split('.'); | ||
for (k = isNamespace.length; k--;) { | ||
handlers[isNamespace[k]] && handlers[isNamespace[k]](); | ||
} | ||
} | ||
if (nativeEvents.indexOf(type) > -1) { | ||
if (element[addEvent]) { | ||
evt = document.createEvent("HTMLEvents"); | ||
evt.initEvent(type, true, true); | ||
element.dispatchEvent(evt); | ||
} else { | ||
evt = document.createEventObject(); | ||
element.fireEvent('on' + type, evt); | ||
} | ||
} else if (element[addEvent]) { | ||
evt = document.createEvent(isNative ? "HTMLEvents" : "UIEvents"); | ||
evt[isNative ? 'initEvent' : 'initUIEvent'](type, true, true, context, 1); | ||
element.dispatchEvent(evt); | ||
} else if (element[attachEvent]) { | ||
isNative ? element.fireEvent('on' + type, document.createEventObject()) : element['_on' + type]++; | ||
} else { | ||
if (element[addEvent]) { | ||
evt = document.createEvent("UIEvents"); | ||
evt.initUIEvent(type, true, true, window, 1); | ||
element.dispatchEvent(evt); | ||
} else { | ||
element['_on' + type]++; | ||
for (k in handlers) { | ||
handlers.hasOwnProperty(k) && handlers[k](); | ||
} | ||
@@ -240,14 +203,7 @@ } | ||
function clone(element, from, type) { | ||
var events = retrieveEvents(from), uid, obj, method, k; | ||
if (!events) { | ||
return element; | ||
} | ||
var events = retrieveEvents(from), obj, k; | ||
obj = type ? events[type] : events; | ||
method = type ? add : clone; | ||
for (k in obj) { | ||
if (obj.hasOwnProperty(k)) { | ||
method(element, type || from, type ? obj[k] : k); | ||
} | ||
obj.hasOwnProperty(k) && (type ? add : clone)(element, type || from, type ? obj[k] : k); | ||
} | ||
return element; | ||
@@ -260,15 +216,10 @@ } | ||
} | ||
var type = e.type; | ||
var type = e.type, target = e.target || e.srcElement; | ||
e.preventDefault = e.preventDefault || fixEvent.preventDefault; | ||
e.stopPropagation = e.stopPropagation || fixEvent.stopPropagation; | ||
e.target = e.target || e.srcElement; | ||
if (e.target.nodeType == 3) { | ||
e.target = e.target.parentNode; | ||
} | ||
e.target = target && target.nodeType == 3 ? target.parentNode : target; | ||
if (type.indexOf('key') != -1) { | ||
if (e.which) { | ||
e.keyCode = e.which; | ||
} | ||
e.keyCode = e.which || e.keyCode; | ||
} else if ((/click|mouse|menu/i).test(type)) { | ||
e.rightClick = (e.which == 3) || (e.button == 2); | ||
e.rightClick = e.which == 3 || e.button == 2; | ||
e.pos = { x: 0, y: 0 }; | ||
@@ -282,5 +233,3 @@ if (e.pageX || e.pageY) { | ||
} | ||
if ((overOut).test(type)) { | ||
e.relatedTarget = e.relatedTarget || e[(type == 'mouseover' ? 'from' : 'to') + 'Element']; | ||
} | ||
overOut.test(type) && (e.relatedTarget = e.relatedTarget || e[(type == 'mouseover' ? 'from' : 'to') + 'Element']); | ||
} | ||
@@ -309,7 +258,4 @@ return e; | ||
var related = event.relatedTarget; | ||
if (related == null) { | ||
return true; | ||
} | ||
if (!related) { | ||
return false; | ||
return related == null; | ||
} | ||
@@ -321,15 +267,10 @@ return (related != this && related.prefix != 'xul' && !/document/.test(this.toString()) && !isDescendant(this, related)); | ||
mouseenter: { base: 'mouseover', condition: check }, | ||
mouseleave: { base: 'mouseout', condition: check } | ||
mouseleave: { base: 'mouseout', condition: check }, | ||
mousewheel: { base: /Firefox/.test(navigator.userAgent) ? 'DOMMouseScroll' : 'mousewheel' } | ||
}; | ||
var evnt = { | ||
add: add, | ||
remove: remove, | ||
clone: clone, | ||
fire: fire | ||
}; | ||
var bean = { add: add, remove: remove, clone: clone, fire: fire }; | ||
var clean = function (el) { | ||
var uid = el._uid; | ||
remove(el); //remove all events | ||
var uid = remove(el).__uid; | ||
if (uid) { | ||
@@ -341,18 +282,14 @@ delete collected[uid]; | ||
if (window[attachEvent]) { | ||
add(window, 'unload', function () { | ||
if (context[attachEvent]) { | ||
add(context, 'unload', function () { | ||
for (var k in collected) { | ||
if (collected.hasOwnProperty(k)) { | ||
clean(collected[k]); | ||
} | ||
collected.hasOwnProperty(k) && clean(collected[k]); | ||
} | ||
if (window.CollectGarbage) { | ||
CollectGarbage(); | ||
} | ||
context.CollectGarbage && CollectGarbage(); | ||
}); | ||
} | ||
var oldEvnt = context.evnt; | ||
evnt.noConflict = function () { | ||
context.evnt = oldEvnt; | ||
var oldBean = context.bean; | ||
bean.noConflict = function () { | ||
context.bean = oldBean; | ||
return this; | ||
@@ -362,5 +299,5 @@ }; | ||
(typeof module !== 'undefined' && module.exports) ? | ||
(module.exports = evnt) : | ||
(context.evnt = evnt); | ||
(module.exports = bean) : | ||
(context.bean = bean); | ||
}(this); |
/*! | ||
* event.js - copyright @dedfat | ||
* bean.js - copyright @dedfat | ||
* https://github.com/fat/bean | ||
* Follow our software http://twitter.com/dedfat | ||
* MIT License | ||
* cheers to the entire mootools team, dean edwards, and dperini | ||
* special thanks to: | ||
* dean edwards: http://dean.edwards.name/ | ||
* dperini: https://github.com/dperini/nwevents | ||
* the entire mootools team: github.com/mootools/mootools-core | ||
*/ | ||
!function(a){function z(a){var b=a.relatedTarget;if(b==null)return!0;if(!b)return!1;return b!=this&&b.prefix!="xul"&&!/document/.test(this.toString())&&!j(this,b)}function x(a){if(!a)return{};var b=a.type;a.preventDefault=a.preventDefault||x.preventDefault,a.stopPropagation=a.stopPropagation||x.stopPropagation,a.target=a.target||a.srcElement,a.target.nodeType==3&&(a.target=a.target.parentNode);if(b.indexOf("key")!=-1)a.which&&(a.keyCode=a.which);else if(/click|mouse|menu/i.test(b)){a.rightClick=a.which==3||a.button==2,a.pos={x:0,y:0};if(a.pageX||a.pageY)a.pos.x=a.pageX,a.pos.y=a.pageY;else if(a.clientX||a.clientY)a.pos.x=a.clientX+document.body.scrollLeft+document.documentElement.scrollLeft,a.pos.y=a.clientY+document.body.scrollTop+document.documentElement.scrollTop;e.test(b)&&(a.relatedTarget=a.relatedTarget||a[(b=="mouseover"?"from":"to")+"Element"])}return a}function w(a,b,c){var d=l(b),e,f,g,h;if(!d)return a;f=c?d[c]:d,g=c?t:w;for(h in f)f.hasOwnProperty(h)&&g(a,c||b,c?f[h]:h);return a}function v(a,b){var c,d,e,g=b.split(" ");for(e=g.length;e--;){b=g[e];if(!k(a)){var h=l(a)[b];for(d in h)h.hasOwnProperty(d)&&h[d]()}y.indexOf(b)>-1?a[f]?(c=document.createEvent("HTMLEvents"),c.initEvent(b,!0,!0),a.dispatchEvent(c)):(c=document.createEventObject(),a.fireEvent("on"+b,c)):a[f]?(c=document.createEvent("UIEvents"),c.initUIEvent(b,!0,!0,window,1),a.dispatchEvent(c)):a["_on"+b]++}return a}function u(a,b,c){var d,e,f=typeof b=="string",g=r,h=l(a);if(f&&/\s/.test(b)){b=b.split(" ");for(var i=b.length;i--;)u(a,b[i]);return a}if(!h||f&&!h[b])return a;if(typeof c=="function")g(a,b,c);else{b?(e=f&&b,b=c||h[b]||b):(b=h,g=u);for(d in b)b.hasOwnProperty(d)&&g(a,e||d,b[d])}return a}function t(a,b,c,d,e){if(typeof b=="object"&&!c)for(var f in b)b.hasOwnProperty(f)&&q(a,f,b[f]);else{var g=typeof c=="string",h=(g?c:b).split(" ");for(var i=h.length;i--;)q(a,h[i],g?s(b,d,e):c,Array.prototype.slice.call(arguments,g?4:3))}return a}function s(a,b,c){return function(d){var e=typeof a=="string"?c(a,this):a;for(var f=d.target;f&&f!=this;f=f.parentNode)for(var g=e.length;g--;)if(e[g]==f)return b.apply(f,arguments)}}function r(a,b,c){var d=l(a);if(!d||!d[b])return a;c=d[b][c._uid],delete d[b][c._uid],b=A[b]?A[b].base:b,a[f]||y.indexOf(b)>-1?n(a,b,c,!1):n(a,"propertychange",c,!1,b);return a}function q(a,b,c,e){var g=l(a),h=g[b];h||(h=g[b]={},a["on"+b]&&(h[0]=a["on"+b]));var i=m(c);if(h[i])return a;var j=A[b];j&&(j.condition&&(c=p(a,c,b,j.condition)),b=j.base||b);if(window[f]||y.indexOf(b)>-1){c=o(a,c,e);if(b=="unload"){var k=c;c=function(){r(a,"unload",c),k()}}n(a,b,c,!0)}else c=p(a,c,b,!1,e),n(a,"propertychange",c,!0,b);h[i]=c,c._uid=i;return b=="unload"?a:d[m(a)]=a}function p(a,b,c,d,e){return function(f){(d?d.call(this,f):f&&f.propertyName=="_on"+c||!f)&&b.apply(a,[f].concat(e));return!0}}function o(a,b,c){return function(d){d=x(d||((this.ownerDocument||this.document||this).parentWindow||window).event),b.apply(a,[d].concat(c))===!1&&d&&(d.preventDefault(),d.stopPropagation())}}function n(a,b,c,d,e){if(!!k(a)){if(a[f])return a[d?f:h](b,c,!1);e&&d&&(a["_on"+e]=a["_on"+e]||0),a[d?g:i]("on"+b,c)}}function m(a){return a._uid=a._uid||b++}function l(a){var b=m(a);return c[b]=c[b]||{}}function k(a){return!!a.nodeName}function j(a,b){var c=b.parentNode;while(c!=null){if(c==a)return!0;c=c.parentNode}return!1}var b=1,c={},d={},e=/over|out/,f="addEventListener",g="attachEvent",h="removeEventListener",i="detachEvent";x.preventDefault=function(){this.returnValue=!1},x.stopPropagation=function(){this.cancelBubble=!0};var y="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".split(","),A={mouseenter:{base:"mouseover",condition:z},mouseleave:{base:"mouseout",condition:z}},B={add:t,remove:u,clone:w,fire:v},C=function(a){var b=a._uid;u(a),b&&(delete d[b],delete c[b])};window[g]&&t(window,"unload",function(){for(var a in d)d.hasOwnProperty(a)&&C(d[a]);window.CollectGarbage&&CollectGarbage()});var D=a.evnt;B.noConflict=function(){a.evnt=D;return this},typeof module!="undefined"&&module.exports?module.exports=B:a.evnt=B}(this) | ||
!function(a){function A(a){var b=a.relatedTarget;if(!b)return b==null;return b!=this&&b.prefix!="xul"&&!/document/.test(this.toString())&&!l(this,b)}function y(a){if(!a)return{};var b=a.type,c=a.target||a.srcElement;a.preventDefault=a.preventDefault||y.preventDefault,a.stopPropagation=a.stopPropagation||y.stopPropagation,a.target=c&&c.nodeType==3?c.parentNode:c;if(b.indexOf("key")!=-1)a.keyCode=a.which||a.keyCode;else if(/click|mouse|menu/i.test(b)){a.rightClick=a.which==3||a.button==2,a.pos={x:0,y:0};if(a.pageX||a.pageY)a.pos.x=a.pageX,a.pos.y=a.pageY;else if(a.clientX||a.clientY)a.pos.x=a.clientX+document.body.scrollLeft+document.documentElement.scrollLeft,a.pos.y=a.clientY+document.body.scrollTop+document.documentElement.scrollTop;e.test(b)&&(a.relatedTarget=a.relatedTarget||a[(b=="mouseover"?"from":"to")+"Element"])}return a}function x(a,b,c){var d=m(b),e,f;e=c?d[c]:d;for(f in e)e.hasOwnProperty(f)&&(c?u:x)(a,c||b,c?e[f]:f);return a}function w(b,c){var d,e,j,k=c.split(" ");for(j=k.length;j--;){c=k[j].replace(g,"");var l=z.indexOf(c)>-1,n=k[j].replace(f,""),o=m(b)[c];if(n){n=n.split(".");for(e=n.length;e--;)o[n[e]]&&o[n[e]]()}else if(b[h])d=document.createEvent(l?"HTMLEvents":"UIEvents"),d[l?"initEvent":"initUIEvent"](c,!0,!0,a,1),b.dispatchEvent(d);else if(b[i])l?b.fireEvent("on"+c,document.createEventObject()):b["_on"+c]++;else for(e in o)o.hasOwnProperty(e)&&o[e]()}return b}function v(a,b,c){var d,e,h,i=typeof b=="string",j=i&&b.replace(f,""),k=s,l=m(a);if(i&&/\s/.test(b)){b=b.split(" ");var n=b.length-1;while(v(a,b[n])&&n--);return a}h=i?b.replace(g,""):b;if(!l||i&&!l[h])return a;if(typeof c=="function")k(a,h,c);else if(j)k(a,b);else{k=h?k:v,e=i&&h,h=h?c||l[h]||h:l;for(d in h)h.hasOwnProperty(d)&&k(a,e||d,h[d])}return a}function u(a,b,c,d,e){if(typeof b=="object"&&!c)for(var f in b)b.hasOwnProperty(f)&&u(a,f,b[f]);else{var g=typeof c=="string",h=(g?c:b).split(" ");c=g?t(b,d,e):c;for(var i=h.length;i--;)r(a,h[i],c,Array.prototype.slice.call(arguments,g?4:3))}return a}function t(a,b,c){return function(d){var e=typeof a=="string"?c(a,this):a;for(var f=d.target;f&&f!=this;f=f.parentNode)for(var g=e.length;g--;)if(e[g]==f)return b.apply(f,arguments)}}function s(a,b,c){var d,e,i,j,k=m(a),l=b.replace(g,"");if(!k||!k[l])return a;e=b.replace(f,""),i=e?e.split("."):[c.__uid];for(j=i.length;j--;){d=i[j],c=k[l][d],delete k[l][d],l=B[l]?B[l].base:l;var n=a[h]||z.indexOf(l)>-1;o(a,n?l:"propertychange",c,!1,!n&&l)}return a}function r(b,c,e,i){var j=c.replace(g,""),k=m(b),l=k[j]||(k[j]={}),r=n(e,c.replace(f,""));if(l[r])return b;var t=B[j];e=t&&t.condition?q(b,e,j,t.condition):e,j=t&&t.base||j;var u=a[h]||z.indexOf(j)>-1;e=u?p(b,e,i):q(b,e,j,!1,i);if(j=="unload"){var v=e;e=function(){s(b,j,e)&&v()}}o(b,u?j:"propertychange",e,!0,!u&&!0),l[r]=e,e.__uid=r;return j=="unload"?b:d[n(b)]=b}function q(a,b,c,d,e){return function(f){(d?d.call(this,f):f&&f.propertyName=="_on"+c||!f)&&b.apply(a,[f].concat(e))}}function p(b,c,d){return function(e){e=y(e||((this.ownerDocument||this.document||this).parentWindow||a).event);return c.apply(b,[e].concat(d))}}function o(a,b,c,d,e){a[h]?a[d?h:j](b,c,!1):a[i]&&(e&&d&&(a["_on"+e]=a["_on"+e]||0),a[d?i:k]("on"+b,c))}function n(a,c){return a.__uid=c||a.__uid||b++}function m(a){var b=n(a);return c[b]=c[b]||{}}function l(a,b){var c=b.parentNode;while(c!=null){if(c==a)return!0;c=c.parentNode}}var b=1,c={},d={},e=/over|out/,f=/[^\.]*(?=\..*)\.|.*/,g=/\..*/,h="addEventListener",i="attachEvent",j="removeEventListener",k="detachEvent";y.preventDefault=function(){this.returnValue=!1},y.stopPropagation=function(){this.cancelBubble=!0};var z="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".split(","),B={mouseenter:{base:"mouseover",condition:A},mouseleave:{base:"mouseout",condition:A},mousewheel:{base:/Firefox/.test(navigator.userAgent)?"DOMMouseScroll":"mousewheel"}},C={add:u,remove:v,clone:x,fire:w},D=function(a){var b=v(a).__uid;b&&(delete d[b],delete c[b])};a[i]&&u(a,"unload",function(){for(var b in d)d.hasOwnProperty(b)&&D(d[b]);a.CollectGarbage&&CollectGarbage()});var E=a.bean;C.noConflict=function(){a.bean=E;return this},typeof module!="undefined"&&module.exports?module.exports=C:a.bean=C}(this) |
@@ -6,3 +6,3 @@ require('../support/smoosh').config({ | ||
"./src/copyright.js", | ||
"./src/event.js" | ||
"./src/bean.js" | ||
] | ||
@@ -9,0 +9,0 @@ }, |
{ | ||
"name": "bean", | ||
"description": "an events api for javascript", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"homepage": "https://github.com/fat/bean", | ||
@@ -13,2 +13,2 @@ "authors": ["Jacob Thornton <@fat>"], | ||
"ender": "./src/ender.js" | ||
} | ||
} |
193
README.md
@@ -1,26 +0,47 @@ | ||
Bean - Just events. | ||
------------------- | ||
Bean is a simple, new module which aims to give you all the power you've come to expect from larger libraries event systems, but in the tiniest package evar... only 2k gzipped! *(needs to be 1.5k)* | ||
Bean | ||
---- | ||
Bean is a small, slick, cross-platform, framework-agnostic event utility designed for desktop, mobile, and touch-based browsers. In its simplest form - it works like this: | ||
add | ||
bean.add(element, 'click', function (e) { | ||
console.log('hello'); | ||
}); | ||
API | ||
--- | ||
As you might expect, the add method is going to enable you to add all your event handlers. What you might not expect, is that it is crazy flexible -- adding native or custom events, to elements or objects is not a problem. | ||
Bean has four methods, each packing quite a punch. | ||
Let's start with the simplest example, adding a click event to an element: | ||
* bean.<code>add()</code> | ||
* bean.<code>remove()</code> | ||
* bean.<code>clone()</code> | ||
* bean.<code>fire()</code> | ||
evnt.add(element, 'click', handler); | ||
add() | ||
--- | ||
<code>bean.add()</code> lets you attach event listeners to both elements and objects. | ||
If you'd like, you can also include additional arguments which will be passed back to your handlers at event execution: | ||
<h3>Signature</h3> | ||
evnt.add(element, 'click', function(e, foo, bar) { | ||
//codez | ||
}, 'fat', 'ded'); | ||
* {1} element {DOM Element} an HTML DOM element | ||
* {2} event type(s) {String} an event (or multiple events) to listen to | ||
* {3} handler {Function} the callback function | ||
Also (like with jquery), you can specify multiple event types in one declaration: | ||
* {2,3} handlers {Object} a list of event keys with callback functions as the values | ||
evnt.add(element, 'keydown keyup', handler); | ||
* {4,n} optional args | ||
You might also want to pass an object with a handful of event types and handlers: | ||
<h3>Examples</h3> | ||
evnt.add(element, { | ||
// simple | ||
bean.add(element, 'click', handler); | ||
// optional arguments passed to handler | ||
bean.add(element, 'click', function(e, o1, o2) { | ||
console.log(o1, o2); | ||
}, 'fat', 'ded'); | ||
// multiple events | ||
bean.add(element, 'keydown keyup', handler); | ||
// multiple handlers | ||
bean.add(element, { | ||
click: function (e) {}, | ||
@@ -31,82 +52,91 @@ mouseover: function (e) {}, | ||
Or maybe you're into using event delegation: | ||
// event delegated events | ||
bean.add(element, '.content p', 'click', handler, queryEngine); | ||
evnt.add(element, '.myClass', 'click', handler, $); | ||
*(note: to use event delegation with a selector, you must pass bean.add a reference to a selector engine like qwery or sizzle)* | ||
Developers working on Mobile Webkit applications like iPhone or Android, you may wish to simply provide the following query selector with Bean: | ||
*(note: to use event delegation with a selector, you must pass bean.Add a reference to a selector engine like qwery or sizzle)* | ||
bean.add(element, '.content p', 'click', fn, function (selector) { | ||
return document.querySelectorAll(selector); | ||
}); | ||
Or alternatively, you can pass an array of elements (this actually cuts down on selector engine work, and is more performant means of delegation if you know your DOM won't be changing. | ||
Or alternatively, you can pass an array of elements (this actually cuts down on selector engine work, and is a more performant means of delegation if you know your DOM won't be changing: | ||
evnt.add(element, [el, el2, el3], 'click', handler); | ||
bean.add(element, [el, el2, el3], 'click', handler); | ||
//or | ||
bean.add(element, $('.myClass'), 'click', handler); | ||
evnt.add(element, $('.myClass'), 'click', handler); | ||
*(note: the focus, blur, and submit events will not delegate)* | ||
*(note: We haven't yet implemented focus, blur, submit delegation... if this is a deal breaker for you, pls let us know!)* | ||
<h3>Namespacing</h3> | ||
Bean also now supports namespacing your events! This makes it much easier to target them down the line with things like remove or fire. To name space an event just add a dot followed by your unique name identifier: | ||
remove | ||
------ | ||
Remove is how you get rid of listeners once you know longer want them. It's also a good idea to call remove on elements before you remove elements from your dom (this gives bean a chance to clean up some things.) | ||
bean.add(element, 'click.fat', fn); | ||
bean.add(element, 'click.ded', fn); | ||
bean.add(element, 'click', fn); | ||
To remove single event handlers, do something like this: | ||
//later... | ||
bean.fire(element, 'click.ded'); | ||
bean.remove(element, 'click.fat'); | ||
evnt.remove(element, 'click', handler); | ||
//alternatively you can specify mutliple remove or fire handlers at once | ||
bean.fire(element, 'click.ded.fat'); | ||
bean.remove(element, 'click.fat.ded'); | ||
Or, you can also remove all click handlers for a particular element: | ||
remove() | ||
------ | ||
<code>bean.remove()</code> is how you get rid of listeners once you no longer want them. It's also a good idea to call remove on elements before you remove elements from your dom (this gives bean a chance to clean up some things and prevents memory leaks) | ||
evnt.remove(element, 'click'); | ||
// remove a single event handlers | ||
bean.remove(element, 'click', handler); | ||
Or remove multiple event types at once like this: | ||
// remove all click handlers | ||
bean.remove(element, 'click'); | ||
evnt.remove(element, 'mousedown mouseup'); | ||
// remove multiple events | ||
bean.remove(element, 'mousedown mouseup'); | ||
Or remove all events for the element at once like this: | ||
// remove all events | ||
bean.remove(element); | ||
evnt.remove(element); | ||
clone | ||
clone() | ||
----- | ||
Clone is beans method for cloning events from one element to another. | ||
<code>bean.clone()</code> is a method for cloning events from one element to another. | ||
You can clone all events at once by doing this: | ||
// clone all events at once by doing this: | ||
bean.clone(toElement, fromElement); | ||
evnt.clone(toElement, fromElement); | ||
// clone events of a specific type | ||
bean.clone(toElement, fromElement, 'click'); | ||
Or, if you prefer, you can just clone events of a specific type by specifying something like this: | ||
evnt.clone(toElement, fromElement, 'click'); | ||
fire | ||
fire() | ||
---- | ||
Use fire to trigger events. | ||
<code>bean.fire()</code> gives you the ability to trigger events. | ||
You can fire events at anytime by doing this: | ||
// fire a single event on an element | ||
bean.fire(element, 'click'); | ||
evnt.fire(element, 'click'); | ||
// fire multiple types | ||
bean.fire(element, 'mousedown mouseup'); | ||
Also, you can specify multiple types at once like this: | ||
evnt.fire(element, 'mousedown mouseup'); | ||
custom events | ||
------------- | ||
Bean uses methods similar to Dean Edward's event model outlined (here)[http://dean.edwards.name/weblog/2009/03/callbacks-vs-events/] to ensure they behave like real events, rather than just callbacks. | ||
Bean uses methods similar to [Dean Edward's event model](http://dean.edwards.name/weblog/2009/03/callbacks-vs-events/) to ensure custom events behave like real events, rather than just callbacks. | ||
For all intents and purposes, you can just think of them as native events, which will bubble up, and everything... | ||
For all intents and purposes, you can just think of them as native events, which will bubble up, and everything else you would expect... | ||
use them like this: | ||
evnt.add(element, 'partytime', handler); | ||
evnt.fire(element, 'partytime'); | ||
bean.add(element, 'partytime', handler); | ||
bean.fire(element, 'partytime'); | ||
mouseenter, mouseleave | ||
---------------------- | ||
Bean provides you with two special events, mouseenter and mouseleave. They are essentially just helpers for making your mouseover/mouseout lives a bit easier. | ||
Bean provides you with two custom DOM events, <code>mouseenter</code> and <code>mouseleave</code>. They are essentially just helpers for making your mouseover/mouseout lives a bit easier. | ||
use them like regular events: | ||
evnt.add(element, 'mouseenter', handler); | ||
bean.add(element, 'mouseenter', handler); | ||
object support | ||
@@ -116,18 +146,44 @@ -------------- | ||
var klass = new Klass(); | ||
evnt.add(klass, 'complete', handler); | ||
var inst = new Klass(); | ||
bean.add(klass, 'complete', handler); | ||
//later on... | ||
evnt.fire(klass, 'complete'); | ||
bean.fire(inst, 'complete'); | ||
Browser Support | ||
--------------- | ||
Bean has been hand tested in these browsers... and we can personally vouch for them passing all tests. If you've found bugs in these browsers or others please let us know!! | ||
Bean passes our tests in all the following browsers. If you've found bugs in these browsers or others please let us know! | ||
- IE6, IE7, IE8, IE9 | ||
- Chrome 10 | ||
- Safari 5 | ||
- Chrome 1-10 | ||
- Safari 4-5 | ||
- Firefox 3, 4 | ||
Build | ||
----- | ||
Other important browser notes | ||
-------------- | ||
One of the great things about Bean is that it fixes a number of distinguishable browser differences and also provides proper cross-platform support for certain special events. | ||
// normalized browser event model for default behavior and propagation | ||
bean.add(el, 'click', function (e) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
}); | ||
// DOMContentLoaded | ||
bean.add(document, 'DOMContentLoaded', fn); | ||
// mousewheel | ||
bean.add(el, 'mousewheel', fn); | ||
// mobile | ||
bean.add(window, 'orientationchange', fn); | ||
// touch events | ||
bean.add(el, 'touchstart touchmove touchend touchcancel', fn); | ||
// gestures | ||
bean.add(el, 'gesturestart gesturechange gestureend', fn); | ||
Building Bean | ||
------------- | ||
Bean uses [JSHint](http://www.jshint.com/) to keep some house rules as well as [UglifyJS](https://github.com/mishoo/UglifyJS) for its compression. For those interested in building Bean yourself. Run *make* in the root of the project. | ||
@@ -137,8 +193,9 @@ | ||
----- | ||
point your browser at _bean/tests/index.html_ ... We use syn for firing events in our unit tests. | ||
point your browser at <code>bean/tests/index.html</code> | ||
Contributors | ||
------- | ||
* [Dustin Diaz](https://github.com/ded/qwery/commits/master?author=ded) | ||
* [Jacob Thornton](https://github.com/ded/qwery/commits/master?author=fat) | ||
* [Dustin Diaz](https://github.com/fat/bean/commits/master?author=ded) | ||
* [Jacob Thornton](https://github.com/fat/bean/commits/master?author=fat) | ||
* Follow our software [@dedfat](http://twitter.com/dedfat) |
/*! | ||
* event.js - copyright @dedfat | ||
* bean.js - copyright @dedfat | ||
* https://github.com/fat/bean | ||
* Follow our software http://twitter.com/dedfat | ||
* MIT License | ||
* cheers to the entire mootools team, dean edwards, and dperini | ||
* special thanks to: | ||
* dean edwards: http://dean.edwards.name/ | ||
* dperini: https://github.com/dperini/nwevents | ||
* the entire mootools team: github.com/mootools/mootools-core | ||
*/ |
@@ -1,1 +0,48 @@ | ||
$.ender(evnt); | ||
!function () { | ||
var b = bean.noConflict(), | ||
integrate = function (method, type, method2) { | ||
var _args = type ? [type] : []; | ||
return function () { | ||
for (var i = 0, l = this.elements.length; i < l; i++) { | ||
var args = [this.elements[i]].concat(_args); | ||
b[method].apply(this, args.concat(Array.prototype.slice.call(arguments, 0))); | ||
} | ||
return this; | ||
}; | ||
}; | ||
var add = integrate('add'), | ||
remove = integrate('remove'); | ||
var methods = { | ||
bind: add, | ||
listen: add, | ||
delegate: add, | ||
unbind: remove, | ||
unlisten: remove, | ||
undelegate: remove, | ||
trigger: integrate('fire'), | ||
cloneEvents: integrate('clone'), | ||
hover: function (enter, leave) { | ||
for (var i = 0, l = this.elements.length; i < l; i++) { | ||
b.add.call(this, this.elements[i], 'mouseenter', enter); | ||
b.add.call(this, this.elements[i], 'mouseleave', leave); | ||
} | ||
return this; | ||
} | ||
}; | ||
var shortcuts = [ | ||
'blur', 'change', 'click', 'dbltclick', 'error', 'focus', 'focusin', | ||
'focusout', 'keydown', 'keypress', 'keyup', 'load', 'mousedown', | ||
'mouseenter', 'mouseleave', 'mouseout', 'mouseover', 'mouseup', | ||
'resize', 'scroll', 'select', 'submit', 'unload' | ||
]; | ||
for (var i = shortcuts.length; i--;) { | ||
var shortcut = shortcuts[i]; | ||
methods[shortcut] = integrate('add', shortcut); | ||
} | ||
$.ender(methods, true); | ||
}(); |
@@ -5,8 +5,7 @@ var fs = require('fs'); | ||
var headless = fs.readFileSync('src/headless.js'); | ||
var tests = fs.readFileSync('tests.js'); | ||
var tests = fs.readFileSync('tests/tests.js'); | ||
fs.writeFileSync('make/run.js', headless + tests); | ||
exec('node make/run.js', function (err, out) { | ||
console.log(out); | ||
var fs = require('fs'); | ||
fs.unlink('make/run.js'); | ||
}); |
{ | ||
"name": "sink-test", | ||
"description": "test your javascript - headless, or in the browser", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"authors": ["Dustin Diaz <@ded>", "Jacob Thornton <@fat>"], | ||
@@ -6,0 +6,0 @@ "keywords": ["testing", "unit tests", "headless", "boosh", "luke warm"], |
@@ -39,2 +39,8 @@ Sink Test | ||
sink('another module', function (t, o, b, a) { | ||
test('a failure', 1, function () { | ||
ok(1 == 2, 'should fail'); | ||
}); | ||
}); | ||
start(); // start all test modules | ||
@@ -41,0 +47,0 @@ |
@@ -1,3 +0,3 @@ | ||
var sink = require('../src/sink'); | ||
var start = sink.start; | ||
sink = sink.sink; | ||
var o = require('../src/sink'), | ||
start = o.start, | ||
sink = o.sink; |
/*! | ||
* Sink - Browser & Headless JavaScript Unit Tester | ||
* copyright Dustin Diaz & Jacob Thornton | ||
* | ||
* https://github.com/ded/sink-test | ||
* License MIT | ||
*/ | ||
@@ -9,5 +10,7 @@ !function(context) { | ||
fail = false, | ||
modules = [], | ||
tests = [], | ||
item, | ||
setPasses = true, | ||
allPass = true, | ||
beforeMethods = [], | ||
@@ -18,4 +21,4 @@ afterMethods = [], | ||
isHeadless ? require('colors') : !function () { | ||
['red', 'green', 'magenta', 'rainbow', 'yellow'].forEach(function (color) { | ||
isHeadless ? (require('colors')) : !function () { | ||
each(['red', 'green', 'magenta', 'rainbow', 'yellow'], function (color) { | ||
String.prototype.__defineGetter__(color, function () { | ||
@@ -37,2 +40,3 @@ return this.replace(/( )/, '$1'); // stupid workaround to not log an object | ||
setPasses = false; | ||
allPass = false; | ||
if (!isHeadless) { | ||
@@ -45,2 +49,8 @@ check.innerHTML = '✗'; | ||
function each(items, fn) { | ||
for (var i = 0; i < items.length; i++) { | ||
fn(items[i]); | ||
} | ||
} | ||
function pass(li, check) { | ||
@@ -55,3 +65,3 @@ if (!isHeadless) { | ||
function before(fn) { | ||
fn ? beforeMethods.push(fn) : beforeMethods.forEach(function (f) { | ||
fn ? beforeMethods.push(fn) : each(beforeMethods, function (f) { | ||
f(); | ||
@@ -62,3 +72,3 @@ }); | ||
function after(fn) { | ||
fn ? afterMethods.push(fn) : afterMethods.forEach(function (f) { | ||
fn ? afterMethods.push(fn) : each(afterMethods, function (f) { | ||
f(); | ||
@@ -86,3 +96,3 @@ }); | ||
} else { | ||
console.log((name + '...').yellow); | ||
console && console.log((name + '...').yellow); | ||
} | ||
@@ -131,5 +141,5 @@ | ||
if (b) { | ||
console.log((message + ' ✓').green); | ||
console && console.log((message + ' ✓').green); | ||
} else { | ||
console.log((message + ' ✗').red); | ||
console && console.log((message + ' ✗').red); | ||
} | ||
@@ -149,10 +159,2 @@ } else { | ||
function expose() { | ||
for (var i=0; i < arguments.length; i++) { | ||
context[arguments[i].name] = arguments[i]; | ||
} | ||
} | ||
var modules = []; | ||
function sink(name, fn) { | ||
@@ -168,3 +170,3 @@ modules.push({ | ||
afterMethods = []; | ||
console.log(('MODULE: ' + name).magenta); | ||
console && console.log(('MODULE: ' + name).magenta); | ||
fn(test, ok, before, after); | ||
@@ -183,7 +185,7 @@ currentSetName = name; | ||
if (isHeadless) { | ||
message = message[setPasses ? 0 : 1].toUpperCase(); | ||
if (setPasses) { | ||
console.log(message.rainbow); | ||
message = message[allPass ? 0 : 1].toUpperCase(); | ||
if (allPass) { | ||
console && console.log(message.rainbow); | ||
} else { | ||
console.log(message.red); | ||
console && console.log(message.red); | ||
} | ||
@@ -198,5 +200,6 @@ } | ||
} else { | ||
expose(sink, start); | ||
context.sink = sink | ||
context.start = start; | ||
} | ||
}(this); |
@@ -10,5 +10,5 @@ //stub this for ie crap | ||
var el = document.getElementById('input'); | ||
var returned = evnt.add(el, 'click', function () {}); | ||
var returned = bean.add(el, 'click', function () {}); | ||
ok(el == returned, 'returns the element passed in'); | ||
evnt.remove(el); | ||
bean.remove(el); | ||
}); | ||
@@ -18,4 +18,4 @@ | ||
var el = document.getElementById('input'); | ||
evnt.add(el, 'click', function () { | ||
evnt.remove(el); | ||
bean.add(el, 'click', function () { | ||
bean.remove(el); | ||
ok(true, 'adds single events to elements'); | ||
@@ -28,8 +28,8 @@ }); | ||
var obj = {}; | ||
evnt.add(obj, 'complete', function () { | ||
bean.add(obj, 'complete', function () { | ||
ok(true, 'adds single events to objects'); | ||
}); | ||
evnt.fire(obj, 'complete'); | ||
evnt.remove(obj); | ||
evnt.fire(obj, 'complete'); | ||
bean.fire(obj, 'complete'); | ||
bean.remove(obj); | ||
bean.fire(obj, 'complete'); | ||
}); | ||
@@ -39,4 +39,4 @@ | ||
var el = document.getElementById('input'); | ||
evnt.add(el, 'click', function (e) { | ||
evnt.remove(el); | ||
bean.add(el, 'click', function (e) { | ||
bean.remove(el); | ||
ok(this == el, 'equal to element') | ||
@@ -49,4 +49,4 @@ }); | ||
var el = document.getElementById('input'); | ||
evnt.add(el, 'click', function (e) { | ||
evnt.remove(el); | ||
bean.add(el, 'click', function (e) { | ||
bean.remove(el); | ||
ok(e != null, 'recieves an event method') | ||
@@ -60,3 +60,3 @@ }); | ||
handler = function (e, foo, bar, baz) { | ||
evnt.remove(el); | ||
bean.remove(el); | ||
ok(e != null, 'listener was called with event'); | ||
@@ -67,3 +67,3 @@ ok(foo === 1, 'listener was called with correct argument'); | ||
}; | ||
evnt.add(el, 'click', handler, 1, 2, 3); | ||
bean.add(el, 'click', handler, 1, 2, 3); | ||
Syn.click(el); | ||
@@ -74,3 +74,3 @@ }); | ||
var el = document.getElementById('input'); | ||
evnt.add(el, 'click keypress', function () { | ||
bean.add(el, 'click keypress', function () { | ||
ok(true, 'adds multiple events by space seperating them'); | ||
@@ -83,7 +83,7 @@ }); | ||
var el = document.getElementById('input'); | ||
evnt.remove(el); | ||
bean.remove(el); | ||
var handler = function () {ok(true, 'adds same event only one time')}; | ||
evnt.add(el, 'click', handler); | ||
evnt.add(el, 'click', handler); | ||
evnt.add(el, 'click', handler); | ||
bean.add(el, 'click', handler); | ||
bean.add(el, 'click', handler); | ||
bean.add(el, 'click', handler); | ||
Syn.click(el); | ||
@@ -94,6 +94,6 @@ }); | ||
var el = document.getElementById('input'); | ||
evnt.remove(el); | ||
evnt.add(el, 'click', function () {ok(true, 'adds multiple events of the same type 1')}); | ||
evnt.add(el, 'click', function () {ok(true, 'adds multiple events of the same type 2')}); | ||
evnt.add(el, 'click', function () {ok(true, 'adds multiple events of the same type 3')}); | ||
bean.remove(el); | ||
bean.add(el, 'click', function () {ok(true, 'adds multiple events of the same type 1')}); | ||
bean.add(el, 'click', function () {ok(true, 'adds multiple events of the same type 2')}); | ||
bean.add(el, 'click', function () {ok(true, 'adds multiple events of the same type 3')}); | ||
Syn.click(el); | ||
@@ -104,4 +104,4 @@ }); | ||
var el = document.getElementById('input'); | ||
evnt.remove(el); | ||
evnt.add(el, { | ||
bean.remove(el); | ||
bean.add(el, { | ||
click: function () { | ||
@@ -112,3 +112,3 @@ ok(true, 'adds multiple events simultaneously with an object literal 1'); | ||
ok(true, 'adds multiple events simultaneously with an object literal 2'); | ||
evnt.remove(el); | ||
bean.remove(el); | ||
} | ||
@@ -122,3 +122,3 @@ }); | ||
var el2 = document.getElementById('bar'); | ||
evnt.add(el1, 'click', function () {ok(true, 'bubbles up dom')}); | ||
bean.add(el1, 'click', function () {ok(true, 'bubbles up dom')}); | ||
Syn.click(el2); | ||
@@ -129,5 +129,5 @@ }); | ||
var el = document.getElementById('input'); | ||
evnt.remove(el); | ||
evnt.add(el, 'click', function () {ok(true, 'fires an event')}); | ||
evnt.fire(el, 'click'); | ||
bean.remove(el); | ||
bean.add(el, 'click', function () {ok(true, 'fires an event')}); | ||
bean.fire(el, 'click'); | ||
}); | ||
@@ -137,6 +137,6 @@ | ||
var el = document.getElementById('input'); | ||
evnt.remove(el); | ||
evnt.add(el, 'mousedown', function () {ok(true, 'fires multiple events by space seperation 1')}); | ||
evnt.add(el, 'mouseup', function () {ok(true, 'fires multiple events by space seperation 2')}); | ||
evnt.fire(el, 'mousedown mouseup'); | ||
bean.remove(el); | ||
bean.add(el, 'mousedown', function () {ok(true, 'fires multiple events by space seperation 1')}); | ||
bean.add(el, 'mouseup', function () {ok(true, 'fires multiple events by space seperation 2')}); | ||
bean.fire(el, 'mousedown mouseup'); | ||
}); | ||
@@ -146,5 +146,5 @@ | ||
var el = document.getElementById('input'); | ||
evnt.remove(el); | ||
evnt.add(el, 'partytime', function () {ok(true, 'add single custom events')}); | ||
evnt.fire(el, 'partytime'); | ||
bean.remove(el); | ||
bean.add(el, 'partytime', function () {ok(true, 'add single custom events')}); | ||
bean.fire(el, 'partytime'); | ||
}); | ||
@@ -159,4 +159,4 @@ | ||
var el2 = document.getElementById('bar'); | ||
evnt.add(el1, 'partytime', function () {ok(true, 'bubbles up dom like traditional events')}); | ||
evnt.fire(el2, 'partytime'); | ||
bean.add(el1, 'partytime', function () {ok(true, 'bubbles up dom like traditional events')}); | ||
bean.fire(el2, 'partytime'); | ||
}); | ||
@@ -167,4 +167,4 @@ | ||
var el2 = document.getElementById('bar'); | ||
evnt.remove(el1, 'click'); | ||
evnt.add(el1, 'click', function (e) {ok(e.target == el2, 'has correct target')}); | ||
bean.remove(el1, 'click'); | ||
bean.add(el1, 'click', function (e) {ok(e.target == el2, 'has correct target')}); | ||
Syn.click(el2); | ||
@@ -175,4 +175,4 @@ }); | ||
var el = document.getElementById('foo'); | ||
evnt.remove(el); | ||
evnt.add(el, 'click', function (e) {ok(e.stopPropagation != null, 'has stop propagation')}); | ||
bean.remove(el); | ||
bean.add(el, 'click', function (e) {ok(e.stopPropagation != null, 'has stop propagation')}); | ||
Syn.click(el); | ||
@@ -183,4 +183,4 @@ }); | ||
var el = document.getElementById('foo'); | ||
evnt.remove(el); | ||
evnt.add(el, 'click', function (e) {ok(e.preventDefault != null, 'has prevent default method')}); | ||
bean.remove(el); | ||
bean.add(el, 'click', function (e) {ok(e.preventDefault != null, 'has prevent default method')}); | ||
Syn.click(el); | ||
@@ -191,4 +191,4 @@ }); | ||
var el = document.getElementById('input'); | ||
evnt.add(el, 'keypress', function (e) { | ||
evnt.remove(el); | ||
bean.add(el, 'keypress', function (e) { | ||
bean.remove(el); | ||
ok(e.keyCode != null, 'has keycode'); | ||
@@ -201,6 +201,6 @@ }); | ||
var el = document.getElementById('foo'); | ||
evnt.remove(el); | ||
bean.remove(el); | ||
var handler = function () {}; | ||
evnt.add(el, 'click', handler); | ||
var returned = evnt.remove(el, 'click', handler); | ||
bean.add(el, 'click', handler); | ||
var returned = bean.remove(el, 'click', handler); | ||
ok(el == returned, 'returns the element passed in'); | ||
@@ -211,9 +211,9 @@ }); | ||
var el = document.getElementById('foo'); | ||
evnt.remove(el); | ||
bean.remove(el); | ||
var handler = function () { | ||
ok(true, 'remove a single event'); | ||
evnt.remove(el, 'click', handler); | ||
bean.remove(el, 'click', handler); | ||
Syn.click(el); | ||
} | ||
evnt.add(el, 'click', handler); | ||
bean.add(el, 'click', handler); | ||
Syn.click(el) | ||
@@ -226,3 +226,3 @@ }); | ||
ok(true, 'remove mulitple events with an object literal1'); | ||
evnt.remove(el, { | ||
bean.remove(el, { | ||
click: handler1, | ||
@@ -236,4 +236,4 @@ keydown: handler2 | ||
}; | ||
evnt.add(el, 'click', handler1); | ||
evnt.add(el, 'keydown', handler2); | ||
bean.add(el, 'click', handler1); | ||
bean.add(el, 'keydown', handler2); | ||
Syn.click(el); | ||
@@ -244,3 +244,3 @@ }); | ||
var el = document.getElementById('input'); | ||
evnt.remove(el); | ||
bean.remove(el); | ||
var handler1 = function () { | ||
@@ -251,7 +251,7 @@ ok(true, 'removes all events of a specific type 1'); | ||
ok(true, 'removes all events of a specific type 2'); | ||
evnt.remove(el, 'click'); | ||
bean.remove(el, 'click'); | ||
Syn.click(el); | ||
}; | ||
evnt.add(el, 'click', handler1); | ||
evnt.add(el, 'click', handler2); | ||
bean.add(el, 'click', handler1); | ||
bean.add(el, 'click', handler2); | ||
Syn.click(el); | ||
@@ -262,3 +262,3 @@ }); | ||
var el = document.getElementById('input'); | ||
evnt.remove(el); | ||
bean.remove(el); | ||
var handler1 = function () { | ||
@@ -269,7 +269,7 @@ ok(true, 'removes all events of a specific type 1'); | ||
ok(true, 'remove all events of a specific type 2'); | ||
evnt.remove(el, 'mousedown mouseup'); | ||
bean.remove(el, 'mousedown mouseup'); | ||
Syn.click(el); | ||
}; | ||
evnt.add(el, 'mousedown', handler1); | ||
evnt.add(el, 'mouseup', handler2); | ||
bean.add(el, 'mousedown', handler1); | ||
bean.add(el, 'mouseup', handler2); | ||
Syn.click(el); | ||
@@ -282,3 +282,3 @@ }); | ||
ok(true, 'remove all events 1'); | ||
evnt.remove(el); | ||
bean.remove(el); | ||
Syn.click(el).key('j'); | ||
@@ -289,4 +289,4 @@ }, | ||
}; | ||
evnt.add(el, 'click', handler1); | ||
evnt.add(el, 'keydown', handler2); | ||
bean.add(el, 'click', handler1); | ||
bean.add(el, 'keydown', handler2); | ||
Syn.click(el); | ||
@@ -298,14 +298,14 @@ }); | ||
var el2 = document.getElementById('input'); | ||
evnt.remove(el1); | ||
evnt.remove(el2); | ||
evnt.add(el1, 'click', function () {ok(true, 'clones events of a specific type from one element to another 1')}); | ||
evnt.add(el1, 'click', function () { | ||
bean.remove(el1); | ||
bean.remove(el2); | ||
bean.add(el1, 'click', function () {ok(true, 'clones events of a specific type from one element to another 1')}); | ||
bean.add(el1, 'click', function () { | ||
ok(true, 'clone events of a specific type from one element to another 2'); | ||
evnt.remove(el2); | ||
bean.remove(el2); | ||
}); | ||
evnt.add(el1, 'keydown', function () { | ||
bean.add(el1, 'keydown', function () { | ||
ok(true, 'clone events of a specific type from one element to another 3'); | ||
evnt.remove(el2); | ||
bean.remove(el2); | ||
}); | ||
evnt.clone(el2, el1, 'click'); | ||
bean.clone(el2, el1, 'click'); | ||
Syn.click(el2).key('j'); | ||
@@ -317,8 +317,8 @@ }); | ||
var el2 = document.getElementById('input'); | ||
evnt.remove(el1); | ||
evnt.remove(el2); | ||
evnt.add(el1, 'keypress', function () {ok(true, 'clones all events from one element to another 1');}); | ||
evnt.add(el1, 'click', function () {ok(true, 'clones all events from one element to another 2');}); | ||
evnt.add(el1, 'click', function () {ok(true, 'clonesall events from one element to another 3');}); | ||
evnt.clone(el2, el1); | ||
bean.remove(el1); | ||
bean.remove(el2); | ||
bean.add(el1, 'keypress', function () {ok(true, 'clones all events from one element to another 1');}); | ||
bean.add(el1, 'click', function () {ok(true, 'clones all events from one element to another 2');}); | ||
bean.add(el1, 'click', function () {ok(true, 'clonesall events from one element to another 3');}); | ||
bean.clone(el2, el1); | ||
Syn.click(el2).key('j'); | ||
@@ -332,6 +332,6 @@ }); | ||
var el4 = document.getElementById('bang'); | ||
evnt.remove(el1); | ||
evnt.remove(el2); | ||
evnt.remove(el3); | ||
evnt.add(el1, '.bar', 'click', function () { | ||
bean.remove(el1); | ||
bean.remove(el2); | ||
bean.remove(el3); | ||
bean.add(el1, '.bar', 'click', function () { | ||
ok(true, 'delegation on selectors 1'); | ||
@@ -350,6 +350,6 @@ ok(this == el2, 'delegation on selectors, context was set to delegated element 2'); | ||
var el4 = document.getElementById('bang'); | ||
evnt.remove(el1); | ||
evnt.remove(el2); | ||
evnt.remove(el3); | ||
evnt.add(el1, [el2], 'click', function () { | ||
bean.remove(el1); | ||
bean.remove(el2); | ||
bean.remove(el3); | ||
bean.add(el1, [el2], 'click', function () { | ||
ok(true, 'delegation on arary 1'); | ||
@@ -363,4 +363,47 @@ ok(this == el2, 'delegation on arary, context was set to delegated element 1'); | ||
test('namespace: should be able to name handlers', 1, function () { | ||
var el1 = document.getElementById('foo'); | ||
bean.remove(el1); | ||
bean.add(el1, 'click.fat', function () {ok(true, 'bubbles up dom')}); | ||
Syn.click(el1); | ||
}); | ||
test('namespace: should be able to target namespaced event handlers with fire', 1, function () { | ||
var el1 = document.getElementById('foo'); | ||
bean.remove(el1); | ||
bean.add(el1, 'click.fat', function () {ok(true, 'targets namespaced event handlers with fire')}); | ||
bean.add(el1, 'click', function () {ok(true, 'targets namespaced event handlers with fire')}); | ||
bean.fire(el1, 'click.fat'); | ||
}); | ||
test('namespace: should be able to target multiple namespaced event handlers with fire', 2, function () { | ||
var el1 = document.getElementById('foo'); | ||
bean.remove(el1); | ||
bean.add(el1, 'click.fat', function () {ok(true, 'target multiple namespaced event handlers with fire')}); | ||
bean.add(el1, 'click.ded', function () {ok(true, 'targets multiple namespaced event handlers with fire')}); | ||
bean.add(el1, 'click', function () {ok(true, 'targets multiple namespaced event handlers with fire')}); | ||
bean.fire(el1, 'click.fat.ded'); | ||
}); | ||
test('namespace: should be able to remove handlers based on name', 1, function () { | ||
var el1 = document.getElementById('foo'); | ||
bean.remove(el1); | ||
bean.add(el1, 'click.ded', function () {ok(true, 'removes handlers based on name')}); | ||
bean.add(el1, 'click', function () {ok(true, 'removes handlers based on name')}); | ||
bean.remove(el1, 'click.ded'); | ||
Syn.click(el1); | ||
}); | ||
test('namespace: should be able to remove multiple handlers based on name', 1, function () { | ||
var el1 = document.getElementById('foo'); | ||
bean.remove(el1); | ||
bean.add(el1, 'click.fat', function () {ok(true, 'removes multiple handlers based on name')}); | ||
bean.add(el1, 'click.ded', function () {ok(true, 'removes multiple handlers based on name')}); | ||
bean.add(el1, 'click', function () {ok(true, 'removes multiple handlers based on name')}); | ||
bean.remove(el1, 'click.ded.fat'); | ||
Syn.click(el1); | ||
}); | ||
}); | ||
window.onload = start; |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
608020
103
16849
198
2