aboutsummaryrefslogtreecommitdiffstats
path: root/js/lib_event.js
diff options
context:
space:
mode:
authorRobin <robin@Amaya.(none)>2010-04-08 23:59:19 +0200
committerRobin <robin@Amaya.(none)>2010-04-08 23:59:19 +0200
commite8307187574380c12b8ca5f932185ca576074c68 (patch)
tree50cbaa134821ed9ca5c0c5a360aab90eb5fab048 /js/lib_event.js
parent7657926a602a524cf651e7e2b95a3369261fbde1 (diff)
downloadnextcloud-server-e8307187574380c12b8ca5f932185ca576074c68.tar.gz
nextcloud-server-e8307187574380c12b8ca5f932185ca576074c68.zip
some more cleanup
Diffstat (limited to 'js/lib_event.js')
-rwxr-xr-xjs/lib_event.js98
1 files changed, 23 insertions, 75 deletions
diff --git a/js/lib_event.js b/js/lib_event.js
index 9d5df93e2a1..f8482402d09 100755
--- a/js/lib_event.js
+++ b/js/lib_event.js
@@ -12,90 +12,38 @@ usage: document.events.add(node,type,function,arguments);
or: node.addEvent(type,function,arguments);
*/
-eventHandler=function(){
- this.holders=Array();
-}
+document.events=new Object;
+document.events.functions=Array();
+document.events.args=Array();
-eventHandler.prototype={
- add:function(element,type,func,arguments){
- var holder=this.getHolderByElement(element);
- holder.addListner(type,func,arguments);
- },
- getHolderByElement:function(element){
- var holder=false;
- for (var i=0;i<this.holders.length;i++){
- if (this.holders[i].getElement()==element){
- var holder=this.holders[i];
- }
+document.events.add=function(element,type,func,args){
+ if(args){
+ if(typeof args!='object' && typeof args!='Object'){
+ args=[args];
}
- if (!holder){
- var holder=new eventHolder(element);
- this.holders[this.holders.length]=holder;
- }
- return holder;
- },
- trigger:function(element,type,event){
- var holder=eventHandler.getHolderByElement(element);
- return holder.trigerEvent.call(holder,type,event);
}
-}
-
-eventHolder=function(element){
- this.element=element;
- this.listners=Array();
-}
-
-eventHolder.prototype={
- addListner:function(type,func,arguments){
- if (type && this.element){
- if (!this.listners[type]){
- this.listners[type]=Array();
- eval("callback=function(event){return holder.trigerEvent.call(holder,'"+type+"',event)}");
- if (this.element.tagName){//do we have a element (not an named event)
- var holder=this;
- //IE doesn't let you set the onload event the regulair way
- if (type=="onload" && this.element.addEventListener && window.ActiveXObject){
- this.element.addEventListener(type, callback, false);
- }else if (type=="onload" && this.element.attachEvent && window.ActiveXObject){
- this.element.attachEvent(type, callback);
- }else{
- eval("this.element."+type+"=function(event){return holder.trigerEvent.call(holder,'"+type+"',event)}");
- }
- }else{
- eval("this.element."+type+"=function(event){return holder.trigerEvent.call(holder,'"+type+"',event)}");
- }
- }
- var i=this.listners[type].length
- this.listners[type][i]=func;
- this.listners[type][i].applyArguments=arguments;
- }else{
- var i=this.listners.length
- this.listners[i]=func;
- this.listners[type][i].applyArguments=arguments;
- }
- },
- trigerEvent:function(type,event){
- if (type && this.element && this.listners[type]){
- for (var i=0;i<this.listners[type].length;i++){
- if(this.listners[type][i].applyArguments){
- return this.listners[type][i].apply(this,this.listners[type][i].applyArguments)
- }else{
- return this.listners[type][i].call();
- }
+ if(!args){
+ args=Array();
+ }
+ if (type && element){
+
+ //wrap the function in a function, otherwise it won't work if func is actually a callBack
+ var funcId=document.events.functions.length;
+ document.events.functions[funcId]=func;
+ document.events.args[funcId]=args;
+ eval('callback=function(event){result=document.events.functions['+funcId+'].apply(this,document.events.args['+funcId+']);if(result===false){if(event.preventDefault){event.preventDefault();}}};');
+ if(element.addEventListener){
+ var eventType=type;
+ if(eventType.substr(0,2)=='on'){
+ eventType=eventType.substr(2);
}
+ element.addEventListener(eventType,callback,false);
}else{
- for (var i=0;i<this.listners.length;i++){
- return this.listners[i](event);
- }
+ element.attachEvent(type,callback);
}
- },
- getElement:function(){
- return this.element;
}
}
-document.events=new eventHandler();
-
Node.prototype.addEvent=function(type,func,arguments){
document.events.add(this,type,func,arguments);
} \ No newline at end of file