Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

passing JSHint

  • Loading branch information...
commit 004906447c38782d7d07875a14a74e0494b2bd5e 1 parent 3ff7b46
@ded ded authored
View
2  Makefile
@@ -0,0 +1,2 @@
+boosh:
+ node make/build.js
View
314 ender.js
@@ -0,0 +1,314 @@
+/*!
+ * event.js - copyright @dedfat
+ * https://github.com/fat/bean
+ * Follow our software http://twitter.com/dedfat
+ * MIT License
+ */
+//smooshing mootools eventy stuff and dean edwards eventy stuff
+!function (context) {
+
+ var _uid = 1,
+ overOut = /over|out/;
+
+ function isDescendant(parent, child) {
+ var node = child.parentNode;
+ while (node != null) {
+ if (node == parent) {
+ return true;
+ }
+ node = node.parentNode;
+ }
+ return false;
+ }
+
+ function retrieveEvents(element) {
+ return (element._events = element._events) || {};
+ }
+
+ function retrieveUid(handler) {
+ return (handler._uid = handler._uid) || _uid++;
+ }
+
+ function addNativeListener(element, type, fn) {
+ if (element.addEventListener) {
+ element.addEventListener(type, fn, false);
+ } else {
+ element.attachEvent('on' + type, fn);
+ }
+ }
+
+ function removeNativeListener(element, type, fn) {
+ if (element.removeEventListener) {
+ element.removeEventListener(type, fn, false);
+ } else {
+ element.detachEvent('on' + type, fn);
+ }
+ }
+
+ function fireNativeEvent(element, type) {
+ var evt;
+ if (document.createEventObject) {
+ evt = document.createEventObject();
+ return element.fireEvent('on' + type, evt);
+ }
+ else {
+ evt = document.createEvent("HTMLEvents");
+ evt.initEvent(type, true, true);
+ return !element.dispatchEvent(evt);
+ }
+ }
+
+ function nativeHandler(element, fn) {
+ return function (event) {
+ event = event || fixEvent(((this.ownerDocument || this.document || this).parentWindow || window).event);
+ if (fn.call(element, event) === false) {
+ event.preventDefault();
+ event.stopPropagation();
+ }
+ };
+ }
+
+ function addCustomListener(element, type, fn) {
+ if (element.addEventListener) {
+ element.addEventListener(type, fn, false);
+ } else {
+ element['_on' + type] = 0;
+ element.attachEvent("onpropertychange", function (event) {
+ if (event.propertyName == '_on' + type) {
+ fn.apply(element, arguments);
+ }
+ });
+ }
+ }
+
+ function removeCustomListener(element, type, fn) {
+ if (element.addEventListener) {
+ element.removeEventListener(type, fn, false);
+ } else {
+ element.detachEvent("onpropertychange", fn);
+ }
+ }
+
+ function fireCustomEvent(element, type) {
+ if (element.addEventListener) {
+ var customeEvent = document.createEvent("UIEvents");
+ customeEvent.initEvent(type, false, false);
+ element.dispatchEvent(fakeEvent);
+ } else {
+ element['_on' + type]++;
+ }
+ }
+
+ function customHandler(custom, fn) {
+ return function (event) {
+ if (custom.condition.call(this, event)) {
+ return fn.call(this, event);
+ }
+ return true;
+ };
+ }
+
+ function addEvent(element, type, fn) {
+ 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);
+ if (handlers[uid]) {
+ return element;
+ }
+ var custom = customEvents[type];
+ if (custom) {
+ if (custom.condition) {
+ fn = customHandler(custom, fn);
+ }
+ type = custom.base || type;
+ }
+ if (nativeEvents.indexOf(type) != -1) {
+ fn = nativeHandler(element, fn);
+ addNativeListener(element, type, fn);
+ } else {
+ addCustomListener(element, type, fn);
+ }
+ handlers[uid] = fn;
+ fn._uid = uid;
+ return element;
+ }
+
+ function addEvents(element, events, fn) {
+ if (typeof events == 'object') {
+ for (var type in events) {
+ if (events.hasOwnProperty(type)) {
+ addEvent(element, type, events[type]);
+ }
+ }
+ } else {
+ addEvent(element, events, fn);
+ }
+ return element;
+ }
+
+ function removeEvent(element, type, handler) {
+ var events = retrieveEvents(element);
+ if (!events || !events[type]) {
+ return element;
+ }
+ delete events[type][handler._uid];
+ if (customEvents[type] && !nativeEvents[customEvents[type].base]) {
+ removeCustomListener(element, type, handler, arguments[3]);
+ } else {
+ removeNativeListener(element, type, handler, arguments[3]);
+ }
+ return element;
+ }
+
+ function removeEvents(element, events, fn) {
+ var type, uid, attached, typeEvents, event;
+ if (typeof events == 'object') {
+ for (event in events) {
+ if (events.hasOwnProperty(event)) {
+ removeEvent(element, event, events[event]);
+ }
+ }
+ return element;
+ }
+ attached = retrieveEvents(element);
+ if (!attached) {
+ return element;
+ }
+ if (!events) {
+ for (type in attached) {
+ removeEvents(element, type);
+ }
+ attached = null;
+ } else if (attached[events]) {
+ if (fn) {
+ removeEvent(element, events, fn);
+ } else {
+ typeEvents = attached[events];
+ for (uid in typeEvents) {
+ removeEvent(element, events, typeEvents[uid]);
+ }
+ delete attached[events];
+ }
+ }
+ return element;
+ }
+
+ function fireEvent(element, type, args) {
+ if (customEvents[type]) {
+ fireCustomEvent(element, type, args);
+ } else {
+ fireNativeEvent(element, type);
+ }
+ }
+
+ function cloneEvents(element, from, type) {
+ var events = retrieveEvents(from), eventType, typeEvents, k;
+ if (!events) {
+ return element;
+ }
+ if (!type) {
+ for (eventType in events) {
+ cloneEvents(element, from, eventType);
+ }
+ } else if (events[type]) {
+ typeEvents = events[type];
+ for (k in typeEvents) {
+ addEvent(element, type, typeEvents[k]);
+ }
+ }
+ return element;
+ }
+
+ function fixEvent(e) {
+ var type = e.type;
+ e = e || {};
+ e.preventDefault = fixEvent.preventDefault;
+ e.stopPropagation = fixEvent.stopPropagation;
+ e.target = e.target || e.srcElement;
+ if (e.target.nodeType == 3) {
+ e.target = e.target.parentNode;
+ }
+ if (type.indexOf('key') != -1) {
+ if (e.which) {
+ e.keyCode = e.which;
+ }
+ } else if ((/click|mouse|menu/i).test(type)) {
+ e.rightClick = (e.which == 3) || (e.button == 2);
+ e.pos = { x: 0, y: 0 };
+ if (e.pageX || e.pageY) {
+ e.pos.x = e.pageX;
+ e.pos.y = e.pageY;
+ } else if (e.clientX || e.clientY) {
+ e.pos.x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
+ e.pos.y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
+ }
+ if ((overOut).test(type)) {
+ e.relatedTarget = e.relatedTarget || e[(type == 'mouseover' ? 'from' : 'to') + 'Element'];
+ }
+ }
+ }
+ fixEvent.preventDefault = function () {
+ this.returnValue = false;
+ };
+ fixEvent.stopPropagation = function () {
+ this.cancelBubble = true;
+ };
+
+ 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;
+ if (related == null) {
+ return true;
+ }
+ if (!related) {
+ return false;
+ }
+ return (related != this && related.prefix != 'xul' && !/document/.test(this.toString()) && !isDescendant(this, related));
+ }
+
+ var customEvents = {
+ mouseenter: {
+ base: 'mouseover',
+ condition: check
+ },
+ mouseleave: {
+ base: 'mouseout',
+ condition: check
+ },
+ mousewheel: {
+ base: (navigator.userAgent.indexOf("Firefox") != -1) ? 'DOMMouseScroll' : 'mousewheel'
+ }
+ };
+
+ var evnt = {
+ add: addEvents,
+ remove: removeEvents,
+ clone: cloneEvents,
+ fire: fireEvent
+ };
+
+ var oldEvnt = context.evnt;
+ evnt.noConflict = function () {
+ context.evnt = oldEvnt;
+ return this;
+ };
+ context.evnt = evnt;
+
+}(this);
View
8 ender.min.js
@@ -0,0 +1,8 @@
+/*!
+ * event.js - copyright @dedfat
+ * https://github.com/fat/bean
+ * Follow our software http://twitter.com/dedfat
+ * MIT License
+ *///smooshing mootools eventy stuff and dean edwards eventy stuff
+
+!function(a){function w(a){var b=a.relatedTarget;if(b==null)return!0;if(!b)return!1;return b!=this&&b.prefix!="xul"&&!/document/.test(this.toString())&&!d(this,b)}function u(a){var b=a.type;a=a||{},a.preventDefault=u.preventDefault,a.stopPropagation=u.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;c.test(b)&&(a.relatedTarget=a.relatedTarget||a[(b=="mouseover"?"from":"to")+"Element"])}}function t(a,b,c){var d=e(b),f,g,h;if(!d)return a;if(!c)for(f in d)t(a,b,f);else if(d[c]){g=d[c];for(h in g)o(a,c,g[h])}return a}function s(a,b,c){x[b]?m(a,b,c):i(a,b)}function r(a,b,c){var d,f,g,h,i;if(typeof b=="object"){for(i in b)b.hasOwnProperty(i)&&q(a,i,b[i]);return a}g=e(a);if(!g)return a;if(!b){for(d in g)r(a,d);g=null}else if(g[b])if(c)q(a,b,c);else{h=g[b];for(f in h)q(a,b,h[f]);delete g[b]}return a}function q(a,b,c){var d=e(a);if(!d||!d[b])return a;delete d[b][c._uid],x[b]&&!v[x[b].base]?l(a,b,c,arguments[3]):h(a,b,c,arguments[3]);return a}function p(a,b,c){if(typeof b=="object")for(var d in b)b.hasOwnProperty(d)&&o(a,d,b[d]);else o(a,b,c);return a}function o(a,b,c){var d=e(a),h=d[b];h||(h=d[b]={},a["on"+b]&&(h[0]=a["on"+b]));var i=f(c);if(h[i])return a;var l=x[b];l&&(l.condition&&(c=n(l,c)),b=l.base||b),v.indexOf(b)!=-1?(c=j(a,c),g(a,b,c)):k(a,b,c),h[i]=c,c._uid=i;return a}function n(a,b){return function(c){if(a.condition.call(this,c))return b.call(this,c);return!0}}function m(a,b){if(a.addEventListener){var c=document.createEvent("UIEvents");c.initEvent(b,!1,!1),a.dispatchEvent(fakeEvent)}else a["_on"+b]++}function l(a,b,c){a.addEventListener?a.removeEventListener(b,c,!1):a.detachEvent("onpropertychange",c)}function k(a,b,c){a.addEventListener?a.addEventListener(b,c,!1):(a["_on"+b]=0,a.attachEvent("onpropertychange",function(d){d.propertyName=="_on"+b&&c.apply(a,arguments)}))}function j(a,b){return function(c){c=c||u(((this.ownerDocument||this.document||this).parentWindow||window).event),b.call(a,c)===!1&&(c.preventDefault(),c.stopPropagation())}}function i(a,b){var c;if(document.createEventObject){c=document.createEventObject();return a.fireEvent("on"+b,c)}c=document.createEvent("HTMLEvents"),c.initEvent(b,!0,!0);return!a.dispatchEvent(c)}function h(a,b,c){a.removeEventListener?a.removeEventListener(b,c,!1):a.detachEvent("on"+b,c)}function g(a,b,c){a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent("on"+b,c)}function f(a){return(a._uid=a._uid)||b++}function e(a){return(a._events=a._events)||{}}function d(a,b){var c=b.parentNode;while(c!=null){if(c==a)return!0;c=c.parentNode}return!1}var b=1,c=/over|out/;u.preventDefault=function(){this.returnValue=!1},u.stopPropagation=function(){this.cancelBubble=!0};var v=["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"],x={mouseenter:{base:"mouseover",condition:w},mouseleave:{base:"mouseout",condition:w},mousewheel:{base:navigator.userAgent.indexOf("Firefox")!=-1?"DOMMouseScroll":"mousewheel"}},y={add:p,remove:r,clone:t,fire:s},z=a.evnt;y.noConflict=function(){a.evnt=z;return this},a.evnt=y}(this)
View
24 make/build.js
@@ -0,0 +1,24 @@
+require('../support/smoosh').config({
+ "JAVASCRIPT": {
+ "DIST_DIR": "./",
+ "ender": [
+ "./src/copyright.js",
+ "./src/event.js"
+ ]
+ },
+ "JSHINT_OPTS": {
+ "boss": true,
+ "forin": true,
+ "curly": true,
+ "debug": false,
+ "devel": false,
+ "evil": false,
+ "regexp": false,
+ "undef": false,
+ "sub": false,
+ "white": true,
+ "indent": 2,
+ "whitespace": true,
+ "asi": false
+ }
+}).run().build().analyze();
View
2  src/copyright.js
@@ -1,6 +1,6 @@
/*!
* event.js - copyright @dedfat
- * https://github.com/fat/event-js
+ * https://github.com/fat/bean
* Follow our software http://twitter.com/dedfat
* MIT License
*/
View
140 src/event.js
@@ -1,28 +1,29 @@
//smooshing mootools eventy stuff and dean edwards eventy stuff
!function (context) {
- var _uid = 1;
+ var _uid = 1,
+ overOut = /over|out/;
function isDescendant(parent, child) {
- var node = child.parentNode;
- while (node != null) {
- if (node == parent) {
- return true;
- }
- node = node.parentNode;
- }
- return false;
+ var node = child.parentNode;
+ while (node != null) {
+ if (node == parent) {
+ return true;
+ }
+ node = node.parentNode;
+ }
+ return false;
}
- function retrieveEvents (element) {
- return element._events = element._events || {};
+ function retrieveEvents(element) {
+ return (element._events = element._events) || {};
}
- function retrieveUid (handler) {
- return handler._uid = handler._uid || _uid++;
+ function retrieveUid(handler) {
+ return (handler._uid = handler._uid) || _uid++;
}
- function addNativeListener (element, type, fn) {
+ function addNativeListener(element, type, fn) {
if (element.addEventListener) {
element.addEventListener(type, fn, false);
} else {
@@ -30,7 +31,7 @@
}
}
- function removeNativeListener (element, type, fn){
+ function removeNativeListener(element, type, fn) {
if (element.removeEventListener) {
element.removeEventListener(type, fn, false);
} else {
@@ -38,34 +39,35 @@
}
}
- function fireNativeEvent (element, type) {
- if (document.createEventObject){
- var evt = document.createEventObject();
- return element.fireEvent('on'+type,evt)
+ function fireNativeEvent(element, type) {
+ var evt;
+ if (document.createEventObject) {
+ evt = document.createEventObject();
+ return element.fireEvent('on' + type, evt);
}
else {
- var evt = document.createEvent("HTMLEvents");
- evt.initEvent(type, true, true );
+ evt = document.createEvent("HTMLEvents");
+ evt.initEvent(type, true, true);
return !element.dispatchEvent(evt);
}
}
- function nativeHandler (element, fn) {
- return function(event){
+ function nativeHandler(element, fn) {
+ return function (event) {
event = event || fixEvent(((this.ownerDocument || this.document || this).parentWindow || window).event);
if (fn.call(element, event) === false) {
event.preventDefault();
event.stopPropagation();
}
- }
+ };
}
- function addCustomListener (element, type, fn) {
+ function addCustomListener(element, type, fn) {
if (element.addEventListener) {
element.addEventListener(type, fn, false);
} else {
element['_on' + type] = 0;
- element.attachEvent("onpropertychange", function(event) {
+ element.attachEvent("onpropertychange", function (event) {
if (event.propertyName == '_on' + type) {
fn.apply(element, arguments);
}
@@ -73,7 +75,7 @@
}
}
- function removeCustomListener (element, type, fn) {
+ function removeCustomListener(element, type, fn) {
if (element.addEventListener) {
element.removeEventListener(type, fn, false);
} else {
@@ -81,7 +83,7 @@
}
}
- function fireCustomEvent (element, type) {
+ function fireCustomEvent(element, type) {
if (element.addEventListener) {
var customeEvent = document.createEvent("UIEvents");
customeEvent.initEvent(type, false, false);
@@ -91,13 +93,13 @@
}
}
- function customHandler (custom, fn) {
- return function(event){
+ function customHandler(custom, fn) {
+ return function (event) {
if (custom.condition.call(this, event)) {
return fn.call(this, event);
}
return true;
- }
+ };
}
function addEvent(element, type, fn) {
@@ -151,38 +153,38 @@
}
delete events[type][handler._uid];
if (customEvents[type] && !nativeEvents[customEvents[type].base]) {
- removeCustomListener(element, type, handler, arguments[3])
+ removeCustomListener(element, type, handler, arguments[3]);
} else {
removeNativeListener(element, type, handler, arguments[3]);
}
return element;
}
- function removeEvents (element, events, fn) {
- var type;
+ function removeEvents(element, events, fn) {
+ var type, uid, attached, typeEvents, event;
if (typeof events == 'object') {
- for (var event in events) {
+ for (event in events) {
if (events.hasOwnProperty(event)) {
removeEvent(element, event, events[event]);
}
}
- return element
+ return element;
}
- var attached = retrieveEvents(element);
+ attached = retrieveEvents(element);
if (!attached) {
return element;
}
if (!events) {
- for (var type in attached) {
+ for (type in attached) {
removeEvents(element, type);
}
- delete attached;
- } else if (attached[events]){
+ attached = null;
+ } else if (attached[events]) {
if (fn) {
removeEvent(element, events, fn);
} else {
- var typeEvents = attached[events];
- for (var uid in typeEvents) {
+ typeEvents = attached[events];
+ for (uid in typeEvents) {
removeEvent(element, events, typeEvents[uid]);
}
delete attached[events];
@@ -191,7 +193,7 @@
return element;
}
- function fireEvent (element, type, args) {
+ function fireEvent(element, type, args) {
if (customEvents[type]) {
fireCustomEvent(element, type, args);
} else {
@@ -199,18 +201,18 @@
}
}
- function cloneEvents (element, from, type) {
- var events = retrieveEvents(from);
+ function cloneEvents(element, from, type) {
+ var events = retrieveEvents(from), eventType, typeEvents, k;
if (!events) {
return element;
}
if (!type) {
- for (var eventType in events) {
+ for (eventType in events) {
cloneEvents(element, from, eventType);
}
} else if (events[type]) {
- var typeEvents = events[type];
- for (var k in typeEvents) {
+ typeEvents = events[type];
+ for (k in typeEvents) {
addEvent(element, type, typeEvents[k]);
}
}
@@ -224,31 +226,31 @@
e.stopPropagation = fixEvent.stopPropagation;
e.target = e.target || e.srcElement;
if (e.target.nodeType == 3) {
- e.target = e.target.parentNode;
+ e.target = e.target.parentNode;
}
- if (type.indexOf('key') != -1){
+ if (type.indexOf('key') != -1) {
if (e.which) {
e.keyCode = e.which;
}
} else if ((/click|mouse|menu/i).test(type)) {
- e.rightClick = (e.which == 3) || (e.button == 2);
- e.pos = { x: 0, y: 0 };
- if (e.pageX || e.pageY) {
- e.pos.x = e.pageX;
- e.pos.y = e.pageY;
- } else if (e.clientX || e.clientY) {
- e.pos.x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
- e.pos.y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
- }
- if ((/over|out/).test(type)){
- e.relatedTarget = e.relatedTarget || e[(type == 'mouseover' ? 'from' : 'to') + 'Element'];
- }
- }
- };
- fixEvent.preventDefault = function() {
+ e.rightClick = (e.which == 3) || (e.button == 2);
+ e.pos = { x: 0, y: 0 };
+ if (e.pageX || e.pageY) {
+ e.pos.x = e.pageX;
+ e.pos.y = e.pageY;
+ } else if (e.clientX || e.clientY) {
+ e.pos.x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
+ e.pos.y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
+ }
+ if ((overOut).test(type)) {
+ e.relatedTarget = e.relatedTarget || e[(type == 'mouseover' ? 'from' : 'to') + 'Element'];
+ }
+ }
+ }
+ fixEvent.preventDefault = function () {
this.returnValue = false;
};
- fixEvent.stopPropagation = function() {
+ fixEvent.stopPropagation = function () {
this.cancelBubble = true;
};
@@ -264,7 +266,7 @@
'error', 'abort', 'scroll' //misc
];
- var check = function(event){
+ function check(event) {
var related = event.relatedTarget;
if (related == null) {
return true;
@@ -273,7 +275,7 @@
return false;
}
return (related != this && related.prefix != 'xul' && !/document/.test(this.toString()) && !isDescendant(this, related));
- };
+ }
var customEvents = {
mouseenter: {
@@ -301,6 +303,6 @@
context.evnt = oldEvnt;
return this;
};
- context.evnt = evnt
+ context.evnt = evnt;
}(this);
Please sign in to comment.
Something went wrong with that request. Please try again.