JSL.event
From Projects Wiki
All the event related functions are in this class.
Contents |
Methods
JSL.event.add( ele, type, func, capture )
The famous addEvent function. But calling it in this format is not the preffered method. Use the DOM interface to make the call.
Arguments
- ele
- The Element to which the event should be attached. This must be a DOM Node.
- type
- The event type - "load", 'mouseover', 'click', etc.
- func
- The function that must be called on the event
- capture
- true if you want to enable capture.
Example
JSL.dom("#ele").on("mouseover", function(e){ alert("Hello World"); }); JSL.event().add(document.getElementById("ele"), "mouseover", function(e){ alert("Hello World"); });
Code
// File /var/www/html/Sites/openjs/openjs.com/scripts/jslibrary/code/jsl_event.js, Line 22 function(ele,type,func,capture) { function _makeCallback(e){ var ele = JSL.event(e).getTarget() || document; func.call(ele,e); } capture = capture||true; if(ele.attachEvent) { return ele.attachEvent('on' + type, _makeCallback); } else if(ele.addEventListener) { ele.addEventListener(type, _makeCallback, capture); return true; } else { ele['on' + type] = _makeCallback; } }
JSL.event.stop( )
Stop an event from further propogation. Taken from http://www.openjs.com/articles/prevent_default_action/
Example
JSL.event(e).stop();
Code
// File /var/www/html/Sites/openjs/openjs.com/scripts/jslibrary/code/jsl_event.js, Line 45 function(){ var e = this.event; e.cancelBubble = true; e.returnValue = false; if(e.stopPropagation) e.stopPropagation(); if(e.preventDefault) e.preventDefault(); return false; }
JSL.event.getTarget( )
Get the target of the current event
Example
var ele = JSL.event(e).getTarget();
Code
// File /var/www/html/Sites/openjs/openjs.com/scripts/jslibrary/code/jsl_event.js, Line 59 function() { var element; var e = this.event; if(e.target) element=e.target; else if(e.srcElement) element=e.srcElement; if(element && element.nodeType==3) element=element.parentNode; //Safari Bug fix return element; }

