/** * Event * * Event api wrapper */ (function (){ "use strict"; // Property name for expandos on DOM objects var kis_expando = "KIS_0_5_0"; var _attach, _remove, _add_remove, e, _attach_delegate; // Define the proper _attach and _remove functions // based on browser support if(typeof document.addEventListener !== "undefined") { /** * @private */ _attach = function (sel, event, callback) { if(typeof sel.addEventListener !== "undefined") { // Duplicated events are dropped, per the specification sel.addEventListener(event, callback, false); } }; /** * @private */ _remove = function (sel, event, callback) { if(typeof sel.removeEventListener !== "undefined") { sel.removeEventListener(event, callback, false); } }; } // typeof function doesn't work in IE where attachEvent is available: brute force it else if(typeof document.attachEvent !== "undefined") { /** * @private */ _attach = function (sel, event, callback) { function _listener () { // Internet Explorer fails to correctly set the 'this' object // for event listeners, so we need to set it ourselves. callback.apply(arguments[0]); } if (typeof sel.attachEvent !== "undefined") { _remove(event, callback); // Make sure we don't have duplicate listeners sel.attachEvent("on" + event, _listener); // Store our _listener so we can remove it later var expando = sel[kis_expando] = sel[kis_expando] || {}; expando.listeners = expando.listeners || {}; expando.listeners[event] = expando.listeners[event] || []; expando.listeners[event].push({ callback: callback, _listener: _listener }); } else { console.log("Failed to _attach event:"+event+" on "+sel); } }; /** * @private */ _remove = function (sel, event, callback) { if(typeof sel.detachEvent !== "undefined") { var expando = sel[kis_expando]; if (expando && expando.listeners && expando.listeners[event]) { var listeners = expando.listeners[event]; var len = listeners.length; for (var i=0; i