-
Notifications
You must be signed in to change notification settings - Fork 0
/
bean.min.js
10 lines (10 loc) · 6.06 KB
/
bean.min.js
1
2
3
4
5
6
7
8
9
10
/*!
* bean.js - copyright Jacob Thornton 2011
* https://github.com/fat/bean
* MIT License
* 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,b){typeof module!="undefined"?module.exports=b():typeof define=="function"&&typeof define.amd=="object"?define(b):this[a]=b()}("bean",function(){function L(a){var b=a.relatedTarget;return b?b!=this&&b.prefix!="xul"&&!/document/.test(this.toString())&&!r(this,b):b===null}var a=this,b=this.bean,c=window,d=1,e={},f={},g=/over|out/,h=/[^\.]*(?=\..*)\.|.*/,i=/\..*/,j="addEventListener",k="attachEvent",l="removeEventListener",m="detachEvent",n=document||{},o=n.documentElement||{},p=o[j],q=p?j:k,r=function(a,b){var c=b.parentNode;while(c!==null){if(c==a)return!0;c=c.parentNode}},s=function(a,b){return a.__uid=b&&b+"::"+d++||a.__uid||d++},t=function(a){var b=s(a);return e[b]=e[b]||{}},u=p?function(a,b,c,d){a[d?j:l](b,c,!1)}:function(a,b,c,d,e){e&&d&&a["_on"+e]===null&&(a["_on"+e]=0),a[d?k:m]("on"+b,c)},v=function(a,b,d){return function(e){return e=I(e||((this.ownerDocument||this.document||this).parentWindow||c).event),b.apply(a,[e].concat(d))}},w=function(a,b,d,e,f){return function(g){if(e?e.apply(this,arguments):p?!0:g&&g.propertyName=="_on"+d||!g)g=g?I(g||((this.ownerDocument||this.document||this).parentWindow||c).event):null,b.apply(a,Array.prototype.slice.call(arguments,g?0:1).concat(f))}},x=function(a,b){return!p&&!b&&(a===n||a===c)?o:a},y=function(a,b,c,d){var e=b.replace(i,""),g=t(a),j=g[e]||(g[e]={}),k=c,l=s(c,b.replace(h,""));if(j[l])return a;var m=M[e];m&&(c=m.condition?w(a,c,e,m.condition):c,e=m.base||e);var n=K[e];c=n?v(a,c,d):w(a,c,e,!1,d),n=p||n;if(e=="unload"){var o=c;c=function(){z(a,e,c)&&o()}}return a=x(a,n),a[q]&&u(a,n?e:"propertychange",c,!0,!n&&e),j[l]=c,c.__uid=l,c.__originalFn=k,e=="unload"?a:f[s(a)]=a},z=function(a,b,c){function n(b){c=l[m][b];if(!c)return;delete l[m][b];if(a[q]){m=M[m]?M[m].base:m;var d=p||K[m];a=x(a,d),u(a,d?m:"propertychange",c,!1,!d&&m)}}var d=a.__uid,g,j,k,l=t(a),m=b.replace(i,"");if(!l||!l[m])return a;c&&c.__one&&(c=c.__one),g=b.replace(h,""),j=g?g.split("."):[c.__uid],n(g);for(k=j.length;k--;n(j[k]));return J(l[m])&&delete l[m],J(e[d])&&(delete e[d],delete f[d]),a},A=function(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)}},B=function(a,b,c,d,e,f){if(typeof c=="object"&&!d)for(var g in c)c.hasOwnProperty(g)&&B(a,b,g,c[g]);else{var h=typeof d=="string",i=(h?d:c).split(" ");d=h?A(c,e,f):a=="one"?function(a){var d=function(){E(b,c,d),a.apply(this,arguments)};return a.__one=d}(d):d;for(var j=i.length;j--;)y(b,i[j],d,Array.prototype.slice.call(arguments,h?5:4))}return b},C=function(){return B.apply(this,["add"].concat(Array.prototype.slice.call(arguments,0)))},D=function(){return B.apply(this,["one"].concat(Array.prototype.slice.call(arguments,0)))},E=function(a,b,c){var d,e,f,g,j,k=typeof b=="string",l=k&&b.replace(h,""),m=z,n=t(a);l=l&&l.split(".");if(k&&/\s/.test(b)){b=b.split(" "),j=b.length-1;while(E(a,b[j])&&j--);return a}g=k?b.replace(i,""):b;if(!n||l||k&&!n[g]){for(d in n)if(n.hasOwnProperty(d))for(j in n[d])for(e=l.length;e--;)n[d].hasOwnProperty(j)&&(new RegExp("^"+l[e]+"::\\d*(\\..*)?$")).test(j)&&m(a,[d,j].join("."));return a}if(typeof c=="function")m(a,g,c);else if(l)m(a,b);else{m=g?m:E,f=k&&g,g=g?c||n[g]||g:n;for(d in g)g.hasOwnProperty(d)&&(m(a,f||d,g[d]),delete g[d])}return a},F=function(a,b,c){var d,e,f,g,j=b.split(" ");for(f=j.length;f--;){b=j[f].replace(i,"");var k=K[b],l=j[f].replace(h,""),m=t(a)[b];if(l){l=l.split(".");for(e=l.length;e--;)for(g in m)m.hasOwnProperty(g)&&(new RegExp("^"+l[e]+"::\\d*(\\..*)?$")).test(g)&&m[g].apply(a,[!1].concat(c))}else if(!c&&a[q])G(k,b,a);else for(e in m)m.hasOwnProperty(e)&&m[e].apply(a,[!1].concat(c))}return a},G=p?function(a,b,d){evt=document.createEvent(a?"HTMLEvents":"UIEvents"),evt[a?"initEvent":"initUIEvent"](b,!0,!0,c,1),d.dispatchEvent(evt)}:function(a,b,c){c=x(c,a),a?c.fireEvent("on"+b,document.createEventObject()):c["_on"+b]++},H=function(a,b,c){var d=t(b),e,f,g=s(a);e=c?d[c]:d;for(f in e)e.hasOwnProperty(f)&&(c?C:H)(a,c||b,c?e[f].__originalFn:f);return a},I=function(a){var b={};if(!a)return b;var c=a.type,d=a.target||a.srcElement;b.preventDefault=I.preventDefault(a),b.stopPropagation=I.stopPropagation(a),b.target=d&&d.nodeType==3?d.parentNode:d;if(~c.indexOf("key"))b.keyCode=a.which||a.keyCode;else if(/click|mouse|menu/i.test(c)){b.rightClick=a.which==3||a.button==2,b.pos={x:0,y:0};if(a.pageX||a.pageY)b.clientX=a.pageX,b.clientY=a.pageY;else if(a.clientX||a.clientY)b.clientX=a.clientX+n.body.scrollLeft+o.scrollLeft,b.clientY=a.clientY+n.body.scrollTop+o.scrollTop;g.test(c)&&(b.relatedTarget=a.relatedTarget||a[(c=="mouseover"?"from":"to")+"Element"])}for(var e in a)!(e in b)&&e!=="layerX"&&e!="layerY"&&(b[e]=a[e]);return b},J=function(a){for(var b in a)if(a.hasOwnProperty(b))return!1;return!0};I.preventDefault=function(a){return function(){a.preventDefault?a.preventDefault():a.returnValue=!1}},I.stopPropagation=function(a){return function(){a.stopPropagation?a.stopPropagation():a.cancelBubble=!0}};var K={click:1,dblclick:1,mouseup:1,mousedown:1,contextmenu:1,mousewheel:1,DOMMouseScroll:1,mouseover:1,mouseout:1,mousemove:1,selectstart:1,selectend:1,keydown:1,keypress:1,keyup:1,orientationchange:1,touchstart:1,touchmove:1,touchend:1,touchcancel:1,gesturestart:1,gesturechange:1,gestureend:1,focus:1,blur:1,change:1,reset:1,select:1,submit:1,load:1,unload:1,beforeunload:1,resize:1,move:1,DOMContentLoaded:1,readystatechange:1,error:1,abort:1,scroll:1},M={mouseenter:{base:"mouseover",condition:L},mouseleave:{base:"mouseout",condition:L},mousewheel:{base:/Firefox/.test(navigator.userAgent)?"DOMMouseScroll":"mousewheel"}},N={add:C,one:D,remove:E,clone:H,fire:F},O=function(a){var b=E(a).__uid;b&&(delete f[b],delete e[b])};return c[k]&&C(c,"unload",function(){for(var a in f)f.hasOwnProperty(a)&&O(f[a]);c.CollectGarbage&&CollectGarbage()}),N.noConflict=function(){return a.bean=b,this},N})