[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/phpgwapi/js/dynapi/api/ -> event.js (source)

   1  /*
   2      DynAPI Distribution
   3      DynEvent, EventObject, DynElement Classes
   4  
   5      The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
   6  */
   7  
   8  function DynEvent(type,src) {
   9      this.type = type;
  10      this.src = src;
  11      this.origin = src;
  12      this.propagate = true;
  13      this.bubble = false;
  14      this.bubbleChild = null;
  15      this.defaultValue = true;
  16  };
  17  var p = DynEvent.prototype; 
  18  p.getType = function() {return this.type};
  19  p.getSource = function() {return this.src};
  20  p.getOrigin=function() {return this.origin};
  21  p.stopPropagation = function() {this.propagate = false};
  22  p.preventBubble = function() {this.bubble = false};
  23  p.preventDefault = function() {this.defaultValue = false};
  24  p.getBubbleChild = function() {return this.bubbleChild};
  25  
  26  function EventObject() {
  27      this.DynObject = DynObject;
  28      this.DynObject();
  29      this._listeners = [];
  30  };
  31  EventObject._SubClass={};
  32  
  33  p = dynapi.setPrototype('EventObject','DynObject');
  34  p.addEventListener = function(el) {
  35      if (el) {
  36          for (var i=0;i<this._listeners.length;i++) if (this._listeners[i]==el) return;
  37          this._listeners[this._listeners.length] = el;        
  38          // Use onCreate() and onPrecreate() function for create events
  39          this._hasContentEvents=(el['oncontentchange'])? true:this._hasContentEvents;
  40          this._hasLocationEvents=(el['onlocationchange'])? true:this._hasLocationEvents;
  41          this._hasResizeEvents=(el['onresize'])? true:this._hasResizeEvents;
  42          this._hasDragEvents=(el['ondragstart']||el['ondragmove']||
  43                              el['ondragend']||el['ondragdrop']||el['ondrop']||
  44                              el['ondragover']||el['ondragout'])? true:this._hasDragEvents;
  45  
  46          if (this.captureMouseEvents) {
  47              this._hasMouseEvents = this._hasMouseEvents||(el.onmousedown || el.onmouseup || el.onmouseover || el.onmouseout || el.onclick || el.ondblclick);
  48              if (this._created && !this._hasMouseEvents) this.captureMouseEvents();
  49          }
  50          if (this.captureKeyEvents) {
  51              this._hasKeyEvents = this._hasKeyEvents || (el.onkeyup || el.onkeydown || el.onkeypress);
  52              if (this._created && !this._hasKeyEvents && (el.onkeydown || el.onkeyup || el.onkeypress)) this.captureKeyEvents();
  53          }
  54      }
  55  };
  56  p.removeEventListener = function(el) {
  57      if (el) {
  58          DynAPI.functions.removeFromArray(this._listeners, el, false);
  59          if (!this._listeners.length && this.releaseMouseEvents && this.getClassName()!='DynDocument') this.releaseMouseEvents();
  60          if (!this._listeners.length && this.releaseKeyEvents && this.getClassName()!='DynDocument') this.releaseKeyEvents();
  61      }
  62  };
  63  p.removeAllEventListeners = function() {
  64      delete this._listeners;
  65      this._listeners = [];
  66  };
  67  p.invokeEvent = function(type,e,args) {
  68      if (!e) e = new DynEvent(type,this);
  69      e.src = this;
  70      e.type = type;
  71      
  72      // Check for subclassing
  73      var clsFn=EventObject._SubClass[this+'_'+type];
  74      if(clsFn) {
  75          if (clsFn(e,args)==false) return;
  76      };
  77      
  78      if (this._listeners.length) for (var i=0;i<this._listeners.length;i++) {
  79          if (this._listeners[i]["on"+type]) this._listeners[i]["on"+type](e,args);
  80          if (!e.propagate) break;
  81      }
  82      if (this["on"+type]) this["on"+type](e,args);
  83      if (e.bubble && this.parent) {
  84          //if ((type=="mouseover" || type=="mouseout") && e._relative==this.parent) return;
  85          e.x += this.x;
  86          e.y += this.y;
  87          e.bubbleChild = this;
  88          this.parent.invokeEvent(type,e,args);
  89      }
  90  };
  91  
  92  // Add subClassEvent() function to dynapi.functions
  93  dynapi.functions.subClassEvent = function(type,eobj,fn){
  94      var ek=eobj+'_'+type;
  95      var cls=EventObject._SubClass;
  96      if(typeof(fn)=='function') cls[ek]=fn;
  97      else if(!fn && cls[ek]) delete cls[ek];
  98  };
  99  
 100  function DynElement() {
 101      this.EventObject = EventObject;
 102      this.EventObject();
 103      this.isChild = false;
 104      this._created = false;
 105      this.parent = null;
 106      this._dyndoc = null;
 107      this.children = [];
 108      this._childAnchors = {};
 109      //raphaelpereira
 110      this._cfn = {};
 111      this._fn = 0;
 112  };
 113  DynElement._flagCreate = function(c){ // much faster than using DynElemnt._flagEvent
 114      var ch=c.children;
 115      c._created = true;
 116      if (c._hasCreateFn) c._flagCreateEvent('create');        
 117      for (var i=0; i<ch.length; i++) this._flagCreate(ch[i]);
 118  };
 119  DynElement._flagPreCreate = function(c){
 120      var ch=c.children;
 121      if (c._hasPCreateFn) c._flagCreateEvent('precreate');        
 122      for (var i=0; i<ch.length; i++) this._flagPreCreate(ch[i]);
 123  };
 124  DynElement._flagEvent = function(c,type) {
 125      var ch=c.children;
 126      c.invokeEvent(type);
 127      for (var i=0; i<ch.length; i++) this._flagEvent(ch[i],type);
 128  };
 129  p = dynapi.setPrototype('DynElement','EventObject');
 130  p._adjustSize = dynapi.functions.Null;
 131  p.addChild = function(c,alias,inlineID) {
 132      if (!c) return dynapi.debug.print("Error: no object sent to [DynLayer].addChild()");
 133      if (c.isChild) c.removeFromParent();
 134      c.isChild = true;
 135      c.parent = this;
 136      if (c._saveAnchor) {
 137          c.setAnchor(c._saveAnchor);
 138          c._saveAnchor = null;
 139          delete c._saveAnchor;
 140      }
 141      c._alias = alias;
 142      if(alias) this[alias]=c;
 143      if(inlineID)
 144          c.setID(inlineID,true);
 145      if (this._created)    {
 146          if (c.isInline) c._createInline();
 147          else c._create();
 148      }
 149      this.children[this.children.length] = c;
 150      if(this._aSz) this._adjustSize(); // adjust size if necessary
 151      return c;
 152  };
 153  p.deleteAllChildren = function() {    // removes & destroy all children
 154      var i=0;
 155      var ch =this.children;
 156      var aSz = this._aSz;
 157      this._aSz = false; // prevent children from adjusting parent's size when removed
 158      while(ch.length) {
 159          c=ch[0];
 160          if(c) c.deleteFromParent();
 161          else {
 162              i++; // fail safe method
 163              if(i>=ch.length) break;
 164          }
 165      };    
 166      ch.length = 0;
 167      this._aSz = aSz;
 168      if(this._aSz) this._adjustSize(); // adjust size if necessary
 169  };
 170  p.deleteChild = function(c) { // removes & destroy child
 171      var l = this.children.length;
 172      for (var i=0;i<l && this.children[i]!=c;i++);
 173      if (i!=l) {
 174          c._destroy();
 175          this.dropChildIndex(i);
 176      }
 177  };
 178  p.deleteFromParent = function () { // removes & destroy child
 179      if (this.parent) this.parent.deleteChild(this);
 180  };
 181  p.dropChildIndex = function(i){
 182      var ch = this.children;
 183      var l = ch.length;
 184      delete ch[i];
 185      ch[i] = ch[l-1];
 186      ch[l-1] = null;
 187      ch.length--;
 188      // adjust parent size if necessary
 189      if(this._aSz) this._adjustSize();
 190  };
 191  p.removeChild = function(c) {
 192      var l = this.children.length;
 193      for (var i=0;i<l && this.children[i]!=c;i++);
 194      if (i!=l) {
 195          c._remove();
 196          c._created = c.isChild = false;
 197          c.parent = c.dyndoc = null;
 198          c.elm = c._blkBoardElm = c.css = c.doc = null;
 199          this.dropChildIndex(i);
 200      }
 201  };
 202  p.removeFromParent = function () {
 203      if (this.parent) this.parent.removeChild(this);
 204  };
 205  p._create = p._createInLine = p._createInserted = p._remove = p._delete = p._destroy = dynapi.functions.Null;
 206  
 207  p.getChildren = function() {return this.children};
 208  p.getAllChildren = function() {
 209      var temp;
 210      var ret = [];
 211      var ch = this.children;
 212      var l = ch.length;
 213      for(var i=0;i<l;i++) {
 214          ret[ch[i].id] = ch[i];
 215          temp = ch[i].getAll();
 216          for(var j in temp) ret[j] = temp[j];
 217      }
 218      return ret;
 219  };
 220  p.getParents = function(l) {
 221      if (l==null) l = [];
 222      if (this.parent) {
 223          l[l.length] = this.parent;
 224          l = this.parent.getParents(l);
 225      }
 226      return l;
 227  };
 228  p.isParentOf = function(c) {
 229      if (c) {
 230          var p = c.getParents();
 231          for (var i=0;i<p.length;i++) {
 232              if (p[i]==this) return true;
 233          }
 234      }
 235      return false;
 236  };
 237  p.isChildOf = function(p) {
 238      if (!p) return false;
 239      return p.isParentOf(this);
 240  };
 241  
 242  // New onPreCreate() and onCreate() callback functions
 243  p.onCreate = function(fn){
 244      if(!fn) return;
 245      if(!this._cfn){this._fn=0;this._cfn=[];}
 246      var s='create'+this._fn++;
 247      this._cfn[s]='create';
 248      this._hasCreateFn=true;
 249      this[s]=fn;
 250  };
 251  p.onPreCreate = function(fn){
 252      if(!fn) return;
 253      if(!this._cfn){this._fn=0;this._cfn=[];}
 254      var s='precreate'+this._fn++;
 255      this._cfn[s]='precreate';
 256      this._hasPCreateFn=true;
 257      this[s]=fn;
 258  };
 259  p._flagCreateEvent = function(t){
 260      for(var i in this._cfn){ 
 261          if(this._cfn[i]==t) 
 262          try{this[i]();}
 263          catch(e){return}
 264      };
 265  };
 266  
 267  p.updateAnchor = function() {
 268      this.parent._updateAnchor(this.id);
 269  };
 270  p._updateAnchor = function(id) {
 271      if (!id) return;
 272      var dlyr = DynObject.all[id];
 273      var a = this._childAnchors[id];
 274      var tw = this.w;
 275      var th = this.h;
 276      if (a==null || (tw==null && th==null)) return;
 277      
 278      // anchoring/docking
 279      var fn=dynapi.functions;
 280      var padX=0,padY=0;
 281      if(a.topA) {
 282          anc=fn.getAnchorLocation(a.topA,this);
 283          if(anc){padY=anc.y; th=th-padY;}
 284      }
 285      if(a.leftA) {
 286          anc=(a.leftA==a.topA && anc)? anc:fn.getAnchorLocation(a.leftA,this);
 287          if(anc) {padX=anc.x; tw=tw-padX;}
 288      }
 289      if(a.bottomA) {
 290          anc=fn.getAnchorLocation(a.bottomA,this);
 291          th=th-(this.h-anc.y);
 292      }
 293      if(a.rightA) {
 294          anc=(a.bottomA==a.rightA && anc)? anc:fn.getAnchorLocation(a.rightA,this);
 295          if(anc) tw=tw-(this.w-anc.x);                
 296      }
 297      
 298      var aleft=(tw>0 && a.left && typeof(a.left)=='string')? tw*(parseInt(a.left)/100):a.left;
 299      var aright=(tw>0 && a.right && typeof(a.right)=='string')? tw*(parseInt(a.right)/100):a.right;
 300      var atop=(th>0 && a.top && typeof(a.top)=='string')? th*(parseInt(a.top)/100):a.top;
 301      var abottom=(th>0 && a.bottom && typeof(a.bottom)=='string')? th*(parseInt(a.bottom)/100):a.bottom;
 302      var x = aleft;
 303      var y = atop;
 304      
 305  
 306      var w = null;
 307      var h = null;
 308      var dlyrWidth=dlyr.getWidth();
 309      var dlyrHeight=dlyr.getHeight();
 310      if (a.stretchH!=null) {
 311          if(typeof(a.stretchH)!='string') w=a.stretchH;
 312          else {
 313              if(a.stretchH=='*') w = tw - ((aleft!=null)? aleft:0);
 314              else w = tw*(parseInt(a.stretchH)/100);
 315          }
 316          dlyrWidth=w;
 317      }
 318      if (a.centerH!=null) {
 319          x = Math.ceil(tw/2 - dlyrWidth/2 + a.centerH);
 320      }else if (aright!=null) {
 321          if (aleft!=null) w = (tw - aright) - aleft;
 322          else x = (tw - dlyrWidth) - aright;
 323          if(tw<=0 && x<0) x=null; // ns4 needs x>=0
 324      }    
 325      if (a.stretchV!=null) {
 326          if(typeof(a.stretchV)!='string') h=a.stretchV;
 327          else {
 328              if(a.stretchV=='*') h = th - ((atop!=null)? atop:0);
 329              else h = th*(parseInt(a.stretchV)/100);
 330          }
 331          dlyrHeight=h;
 332      }    
 333      if (a.centerV!=null) {
 334          y = Math.ceil(th/2 - dlyrHeight/2 + a.centerV);
 335      }else if (abottom!=null) {
 336          if (atop!=null) h = (th - abottom) - atop;
 337          else y = (th - dlyrHeight) - abottom;
 338          if(th<=0 && y<0) y=null; // ns4 needs y>=0
 339      }
 340      if(padX) {x=(x)? x:0;x+=padX}
 341      if(padY) {y=(y)? y:0;y+=padY}
 342  
 343      // IE seems to be getting wrong position
 344      if (dynapi.ua.ie)
 345      {
 346  /*        aleft += 10;
 347          aright += 10;
 348          atop += 10;
 349          abottom += 10;*/
 350          x += 7;
 351          y += 14;
 352      }
 353          var tmp=dlyr._hasAnchor;    
 354      dlyr._hasAnchor=false; // ignore anchor updates of this layer
 355      if(x!=null||y!=null) dlyr.setLocation(x,y);
 356      if(w!=null||h!=null) dlyr.setSize(w,h);
 357      dlyr._hasAnchor = tmp; // useful for preventing stack overflow
 358  };
 359  p._updateAnchors = function() {
 360      var tw = this.w;
 361      var th = this.h;
 362      if (tw==null && th==null) return;
 363      for (id in this._childAnchors) this._updateAnchor(id);
 364  };
 365  
 366  
 367  // Bandwidth timer stop
 368  var ua=dynapi.ua; ua._bwe=new Date;
 369  ua.broadband=((ua._bwe-ua._bws)<=1500)? true:false;


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7