Click here to Skip to main content
15,881,882 members
Articles / Web Development / HTML5

Custom JavaScript Event Manager (CJEM)

Rate me:
Please Sign up or sign in to vote.
4.93/5 (32 votes)
3 Aug 2011GPL39 min read 86.9K   3.7K   70  
A Custom JavaScript Event Manager Class Designed to Manage Window, Document and Control Events on a Webpage
var $N={R:function(N){var o=window;var x=false;for(var a=N.split('.');a.length>0;){var s=a.shift();if(a.length==0){if(o[s]){x=true;}}if(!o[s]){o[s]={};}o=o[s];}if(x){return 1;}}};function $O(S){return document.getElementById(S);}function $NU(O){if(O==undefined||O==null){return true;}else{if(typeof(O)=='string'&&O==''){return true;}else{return false;}}}var $CJEM={E:null,Add:function(P,C,T,H,I,W,U){if($NU(this.E)){this.E=new Array();}if($NU(this.E[C])){this.E[C]={};}var A=this.E[C];if($NU(A[T])){A[T]=new Array();}var B=A[T];B.push({'P':P,'C':C,'T':T,'H':H,'I':I,'W':W,'U':U,event:null});$CJEM.Register(C,T);},Remove:function(C,T,H){if($NU(this.E)){return;}var A=this.E[C];if($NU(A)){return;}var B=A[T];if($NU(B)){return;}if(!$NU(H)){for(var i=0;i<B.length;i++){if(H==B[i].H){B[i]=null;B.sort();B.pop();}}}else{B=[];}if(B.length==0){B=null;A[T]=null;delete A[T];$CJEM.UnRegister(C,T);}},UnRegister:function(C,T){switch(C){case 'window':window[T]=null;break;case 'document':document[T]=null;break;default:var A=$O(C);if($NU(A)){return;}A[T]=null;break;}},Register:function(C,T){switch(C){case 'window':window[T]=function(e){$CJEM.Caller(e,C,T);};break;case 'document':document[T]=function(e){$CJEM.Caller(e,C,T);};break;default:var A=$O(C);if($NU(A)){return;}A[T]=function(e){$CJEM.Caller(e,C,T);};break;}},Caller:function(e,C,T){if(!e){e=window.event;}var A=this.E[C];var B=A[T];if($NU(B)){return;}for(var i=0;i<B.length;i++){var D=B[i];D.event=e;if(!$NU(D.I)){if(D.I>0){D.I-=1;}}var F={'ClassObject':B[i].P,'ControlID':B[i].C,'EventType':B[i].T,'TotalInstance':B[i].I,'Wait':B[i].W,'UserObject':B[i].U,event:e};if(!$NU(D.W)){var t=setTimeout(function(){if(D.H(F)){if(navigator.appVersion.indexOf('MSIE')!=-1){e.cancelBubble=true;}else{e.stopPropagation();}}},D.W);}else{if(D.H(F)){if(navigator.appVersion.indexOf('MSIE')!=-1){e.cancelBubble=true;} else {e.stopPropagation();}}}if(D.I==0){$CJEM.Remove(C,T,D.H);}}}};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior) Codevendor
United States United States
Please visit my personal website https://codevendor.com for my latest codes and updates.

Comments and Discussions