From: Robert R. <rai...@us...> - 2002-01-11 20:51:59
|
Update of /cvsroot/dynapi/dynapi2x/src/dynapi/api In directory usw-pr-cvs1:/tmp/cvs-serv15575/src/dynapi/api Added Files: dyndocument.js dynlayer.js event.js mouse.js Log Message: Initial Import == 2.9 --- NEW FILE --- /* DynAPI Distribution DynDocument Class The DynAPI Distribution is distributed under the terms of the GNU LGPL license. requires: dynapi.api.DynElement */ function DynDocument(frame) { this.inherit('DynElement'); this.frame = frame; this.doc = this.frame.document; if (this.frame==dynapi.frame) this.all = DynObject.all; // need it? this._dyndoc = this; // need it? this.x = 0; this.y = 0; this.w = 0; this.h = 0; this._topZIndex = 10000; var o = this; this.frame.onresize = function() {o._handleResize()}; this.onResizeNS4 = "reload" // or "redraw" this.fgColor = this.doc.fgColor||''; this.bgColor = this.doc.bgColor||''; this._created = false; }; var p = dynapi.setPrototype('DynDocument','DynElement'); p.getBgColor = function() { return this.bgColor; }; p._remove = function() { this.elm=null; this.doc=null; this.frame=null; }; p.getX = p.getY = p.getPageX = p.getPageY = function() {return 0}; p.getWidth = function() { if (!this.w) this.findDimensions(); return this.w; }; p.getHeight = function() { if (!this.h) this.findDimensions(); return this.h; }; p.findDimensions = function() { this.w=(dynapi.ua.ns||dynapi.ua.opera)? this.frame.innerWidth : this.elm.clientWidth; this.h=(dynapi.ua.ns||dynapi.ua.opera)? this.frame.innerHeight : this.elm.clientHeight; }; p.setBgColor = function(color) { if (color == null) color=''; if (dynapi.ua.ns4 && color == '') color = '#ffffff'; this.bgColor = color; this.doc.bgColor = color; }; p.setFgColor = function(color) { if (color == null) color=''; if (dynapi.ua.ns4 && color == '') color='#ffffff'; this.fgColor = color; this.doc.fgColor = color; }; p.insertChild = function(c) { if (c.parent == this) { DynElement._flagEvent(c,'precreate'); this.doc.write(c.getOuterHTML()); c._inserted = true; } }; p.insertAllChildren = function() { var str = ''; var c; for (var i=0;i<this.children.length;i++) { c = this.children[i]; DynElement._flagEvent(c,'precreate'); str += c.getOuterHTML(); c._inserted = true; } this.doc.write(str); this.doc.close(); }; p._create = function() { this._created = true; if (dynapi.ua.ns4) { this.css = this.doc; this.elm = this.doc; } else { this.elm = this.frame.document.body; this.css = this.frame.document.body.style; if (dynapi.ua.ie) { this._overflow = this.css.overflow || ''; if (this._cursor) this.css.cursor = this._cursor; } } this.elm.lyrobj = this; this.findDimensions(); for (var i=0;i<this.children.length;i++) { if (this.children[i]._inserted) { DynLayer._assignElement(this.children[i]); DynElement._flagEvent(this.children[i],'create'); } else this.children[i]._create(); } this._updateAnchors(); if (this.assignMouseEvents) this.assignMouseEvents(); this.invokeEvent('load'); }; p._destroy = function() { for (var i=0;i<this.children.length;i++) { this.children[i]._destroy(); delete this.children[i]; } delete DynObject.all; this.elm = null; this.css = null; this.frame = null; }; p._handleResize = function() { var w = this.w; var h = this.h; this.findDimensions(); if (this.w!=w || this.h!=h) { if (dynapi.ua.ns4) { if (this.onResizeNS4=="redraw") { for (var i=0;i<this.children.length;i++) { this.children[i].elm = null; if (this.children[i]._created) { this.children[i]._created = false; this.children[i]._create(); } } this.invokeEvent('resize'); } else if (this.onResizeNS4=="reload") { this.doc.location.href = this.doc.location.href; } } else this.invokeEvent('resize'); } }; p.setCursor = function(c) { if (!c) c = 'default'; if (dynapi.ua.ie && this._cursor!=c) { this._cursor = c; if (this.css) this.css.cursor = c; } }; function main() { if (dynapi.document==null) { dynapi.document = new DynDocument(dynapi.frame); if (dynapi.loaded) dynapi.document._create(); else dynapi.onLoad(function() { dynapi.document._create(); }); } }; if (!dynapi.loaded) main(); --- NEW FILE --- /* DynAPI Distribution DynLayer Class The DynAPI Distribution is distributed under the terms of the GNU LGPL license. requires: dynapi.api.DynDocument */ // to-do: split this file into ns4/ie4 versions, correct dynapi.library definitions to reflect function DynLayer() { this.inherit('DynElement'); var a = arguments; if (a[0]) this.setHTML(a[0]); else this.html = null; this.x = a[1]; this.y = a[2]; this.w = a[3]; this.h = a[4]; this.bgColor = a[5]; this.visible = true; this.z = 1; this.elm = null; this.doc = null; this.css = null; this._saveAnchor = false; this._layout = null; }; var p = dynapi.setPrototype('DynLayer','DynElement'); p._destroy = function() { for (var i=0;i<this.children.length;i++) { this.children[i]._destroy(); } this.children = null; this.frame = null; this.bgImage = null; this.bgColor = null; this.html = null; this.x = null; this.y = null; this.w = null; this.h = null; this.z = null; if (this.elm) { this.elm.lyrobj = null; this.elm = null; } this.doc = null; this.css = null; this.parent = null; }; p._remove = function() { if (dynapi.ua.def && this.elm) { this.elm.style.visibility = "hidden"; this.elm.innerHTML = ""; this.elm.outerHTML = ""; } else if (dynapi.ua.ns4 && this.elm) { if (!this.parent.doc.recycled) this.parent.doc.recycled=[]; this.parent.doc.recycled[this.parent.doc.recycled.length]=this.elm; this.elm.visibility="hide"; } this.frame = null; this.bgImage = null; this.bgColor = null; this.html = null; this.z = null; this.w = null; this.h = null; this.elm = null; this.doc = null; this.css = null; }; if (dynapi.ua.ns4) { p._create = function() { if (this.parent && !this.elm) { DynElement._flagEvent(this,'precreate'); var parentElement = this.parent.isClass('DynLayer')? this.parent.elm : this.parent.frame; var elm = new Layer(this.w||0, parentElement); if (this.w) elm.clip.width = this.w; if (this.h) elm.clip.height = this.h; if (this.x && this.y) elm.moveTo(this.x,this.y); else if (this.x) elm.left = this.x; else if (this.y) elm.top = this.y; if (this.children.length || (this.html!=null && this.html!='')) { elm.document.write(this.getInnerHTML()); elm.document.close(); } if (this.bgColor!=null) elm.document.bgColor = this.bgColor; if (this.clip) { var c = elm.clip, cl = this.clip; c.top=cl[0], c.right=cl[1], c.bottom=cl[2], c.left=cl[3]; } if (this.z) elm.zIndex = this.z; elm.visibility = this.visible? "inherit" : "hide"; DynLayer._assignElement(this,elm); DynElement._flagEvent(this,'create'); } }; DynLayer._assignElement = function(dlyr,elm) { if (!elm) elm = dlyr.parent.doc.layers[dlyr.id]; dlyr.elm = elm; dlyr.css = elm; dlyr.doc = elm.document; dlyr.doc.lyrobj = dlyr; dlyr.elm.lyrobj = dlyr; dlyr._dyndoc = dlyr.parent._dyndoc; for (var i=0;i<dlyr.doc.images.length;i++) dlyr.doc.images[i].lyrobj=dlyr; if (dlyr.html!=null && dlyr.html!='' && (dlyr.w==null || dlyr.h==null)) { var cw = (dlyr.w==null)? dlyr.getContentWidth() : null; var ch = (dlyr.h==null)? dlyr.getContentHeight() : null; dlyr.setSize(cw,ch); } if (dlyr.bgImage!=null) dlyr.setBgImage(dlyr.bgImage); if (dlyr.assignMouseEvents) dlyr.assignMouseEvents(); for (var i=0; i<dlyr.children.length; i++) { DynLayer._assignElement(dlyr.children[i]); } }; p.getOuterHTML=function() { var s='\n<layer id="'+this.id+'"'; if (this.visible==false) s+=' visibility="hide"'; s+=' left='+(this.x!=null? this.x : 0); s+=' top='+(this.y!=null? this.y : 0); if (this.w!=null) s+=' width='+this.w; if (this.h!=null) s+=' height='+this.h; if (this.clip) s+=' clip="'+this.clip[3]+','+this.clip[0]+','+this.clip[1]+','+this.clip[2]+'"'; else s+=' clip="0,0,'+((this.w>=0)?this.w:0)+','+((this.h>=0)?this.h:0)+'"'; if (this.z) s+=' z-index='+this.z; if (this.bgColor!=null) s+=' bgcolor="'+this.bgColor+'"'; s+='>'; s += this.getInnerHTML(); s+='</layer>'; return s; }; p.setLocation = function(x,y) { var cx = (x!=null && x!=this.x); var cy = (y!=null && y!=this.y); if (cx) this.x = x||0; if (cy) this.y = y||0; if (this.css!=null) { if (cx && cy) this.elm.moveTo(this.x, this.y); else if (cx) this.css.left = this.x; else if (cy) this.css.top = this.y; } return (cx||cy); }; p.setPageLocation = function(x,y) { if (this.css) { if (x!=null) { this.css.pageX = x; this.x = this.css.left; } if (y!=null) { this.css.pageY = y; this.y = this.css.top; } return true; } else { if (this.isChild) { if (x!=null) x = x - this.parent.getPageX(); if (y!=null) y = y - this.parent.getPageY(); } return this.setLocation(x,y); } }; p.getPageX = function() {return this.css? this.css.pageX : null}; p.getPageY = function() {return this.css? this.css.pageY : null}; p.setVisible = function(b) { if (b!=this.visible) { this.visible = b; if (this.css) this.css.visibility = b? "inherit" : "hide"; } }; p.setSize = function(w,h) { var cw = (w!=null && w!=this.w); var ch = (h!=null && h!=this.h); if (cw) this.w = w<0? 0 : w; if (ch) this.h = h<0? 0 : h; if (cw||ch) { if (this._childAnchors) this._updateAnchors(); if (this._layout) this._layout._fixLayout(); if (this.css) { if (cw) this.css.clip.width = this.w; if (ch) this.css.clip.height = this.h; } } return (cw||ch); }; p.setHTML=function(html) { var ch = (html!=null && html!=this.html); if (ch) { this.html = html; if (this.css) { if (dynapi.ua.platform=="mac") this.html+='\n'; var sTmp=(this.w==null)?'<NOBR>'+this.html+'</NOBR>':this.html; this.doc.open(); this.doc.write(sTmp); this.doc.close(); for (var i=0;i<this.doc.images.length;i++) this.doc.images[i].lyrobj=this; for (i=0;i<this.doc.links.length;i++) this.doc.links[i].lyrobj=this; } } }; } else { p._create = function() { if (this.parent && !this.elm) { DynElement._flagEvent(this,'precreate'); var elm, parentElement; if (dynapi.ua.ns6) { parentElement = this.parent.elm; var r = parentElement.ownerDocument.createRange(); r.setStartBefore(parentElement); var ptxt = r.createContextualFragment(this.getOuterHTML()); parentElement.appendChild(ptxt); elm = parentElement.lastChild; } else if (dynapi.ua.ie) { parentElement = this.parent.elm; parentElement.insertAdjacentHTML("beforeEnd",this.getOuterHTML()); elm = parentElement.children[parentElement.children.length-1]; } DynLayer._assignElement(this,elm); DynElement._flagEvent(this,'create'); } }; DynLayer._assignElement = function(dlyr,elm) { if (!elm) elm = dynapi.ua.ns6? dlyr.parent.doc.getElementById(dlyr.id) : dlyr.parent.elm.all[dlyr.id]; dlyr.elm = elm; dlyr.css = elm.style; dlyr.doc = dlyr.parent.doc; dlyr.elm.lyrobj = dlyr; dlyr._dyndoc = dlyr.parent._dyndoc; if (dynapi.ua.ie && elm.all.tags("img").length) elm.ondragstart = dynapi.functions.False; if (dlyr.z && dynapi.ua.ns6) dlyr.css.zIndex = dlyr.z; if (dlyr.assignMouseEvents) dlyr.assignMouseEvents(); for (var i=0; i<dlyr.children.length; i++) { DynLayer._assignElement(dlyr.children[i]); } if (dlyr.html!=null && dlyr.html!='' && (dlyr.w==null || dlyr.h==null)) { var cw = (dlyr.w==null)? dlyr.getContentWidth() : null; var ch = (dlyr.h==null)? dlyr.getContentHeight() : null; dlyr.setSize(cw,ch); } }; p.getOuterHTML=function() { var s='<div id="'+this.id+'" style="'; if (this.visible==false) s+=' visibility:hidden;'; s+=' left:'+(this.x!=null? this.x : 0)+'px;'; s+=' top:'+(this.y!=null? this.y : 0)+'px;'; if (this.w!=null) s+=' width:'+this.w+'px;'; if (this.h!=null) s+=' height:'+this.h+'px;'; if (this.clip) s+=' clip:rect('+this.clip[0]+'px '+this.clip[1]+'px '+this.clip[2]+'px '+this.clip[3]+'px);'; else if (this.w!=null && this.h!=null) s+=' clip:rect(0px '+this.w+'px '+this.h+'px 0px);'; if (this.z) s+=' z-index='+this.z+';'; if (this.bgImage!=null) s+=' background-image:url('+this.bgImage+');'; if (this.bgColor!=null) s+=' background-color:'+this.bgColor+';'; if (dynapi.ua.ie55 && this.bgImage==null && this.html==null) s+=' background-image:url(javascript:null);'; if (this._cursor!=null) s+=' cursor:'+this._cursor+';'; s+=' position:absolute;">'; s += this.getInnerHTML(); s+='</div>'; return s; }; p.setLocation=function(x,y) { var cx = (x!=null && x!=this.x); var cy = (y!=null && y!=this.y); if (cx) this.x = x||0; if (cy) this.y = y||0; if (this.css!=null) { if (dynapi.ua.ie && dynapi.ua.v>=5) { if (cx) this.css.pixelLeft = this.x; if (cy) this.css.pixelTop = this.y; } else { if (cx) this.css.left = this.x+"px"; if (cy) this.css.top = this.y+"px"; } } return (cx||cy); }; p.setPageLocation = function(x,y) { if (this.isChild) { if (x!=null) x = x - this.parent.getPageX(); if (y!=null) y = y - this.parent.getPageY(); } return this.setLocation(x,y); }; p.getPageX=function() {return (this.isChild)? this.parent.getPageX()+(this.x||0) : this.x||0}; p.getPageY=function() {return (this.isChild)? this.parent.getPageY()+(this.y||0) : this.y||0}; p.setVisible=function(b) { if (b!=this.visible) { this.visible = b; if (this.css) this.css.visibility = b? "inherit" : "hidden"; } }; p.setSize = function(w,h) { var cw = (w!=null && w!=this.w); var ch = (h!=null && h!=this.h); if (cw) this.w = w<0? 0 : w; if (ch) this.h = h<0? 0 : h; if (cw||ch) { if (this._childAnchors) this._updateAnchors(); if (this._layout) this._layout._fixLayout(); if (this.css) { if (cw) this.css.width = this.w||0; if (ch) this.css.height = this.h||0; if (cw || ch) this.css.clip = 'rect(0px '+(this.w||0)+'px '+(this.h||0)+'px 0px)'; } } return (cw||ch); }; if (dynapi.ua.ie) { p.setHTML = function(html) { var ch = (html!=null && html!='' && html!=this.html); if (ch) { this.html = html; if (this.css) { this.elm.innerHTML = html; } } }; } else { p.setHTML=function(html) { var ch = (html!=null && html!=this.html); if (ch) { this.html = html; if (this.css) { var sTmp=(this.w==null)?'<NOBR>'+this.html+'</NOBR>':this.html; while (this.elm.hasChildNodes()) this.elm.removeChild(this.elm.firstChild); var r=this.elm.ownerDocument.createRange(); r.selectNodeContents(this.elm); r.collapse(true); var df=r.createContextualFragment(sTmp); this.elm.appendChild(df); } } }; } } p.setAnchor = function(anchor) { if (anchor == null) { delete this._saveAnchor; if (this.parent && this.parent._childAnchors && this.parent._childAnchors[this.is]) delete this.parent._childAnchors[this.is]; } else if (this.parent) { if (!this.parent._childAnchors) this.parent._childAnchors = {}; var a = this.parent._childAnchors; a[this.id] = anchor; this.parent._updateAnchor(this.id); } else this._saveAnchor = anchor; }; p.setX=function(x) {this.setLocation(x,null)}; p.setY=function(y) {this.setLocation(null,y)}; p.getX=function() {return this.x||0}; p.getY=function() {return this.y||0}; p.setPageX = function(x) {this.setPageLocation(x,null)}; p.setPageY = function(y) {this.setPageLocation(null,y)}; p.getVisible=function() {return this.visible}; p.setZIndex=function(z) { if (typeof(z)=="object") { if (z.above) this.z = z.above.z + 1; else if (z.below) this.z = z.below.z - 1; else if (z.topmost && this.parent) { if (this.parent._topZ==null) this.parent._topZ = 10000; this.z = this.parent._topZ++; } } else this.z = z; if (this.css) this.css.zIndex = this.z; }; p.getZIndex=function() {return this.z}; p.getInnerHTML=function() { var s=""; if (this.html!=null) s+=this.html; for (var i=0;i<this.children.length;i++) s+=this.children[i].getOuterHTML(); return s; }; p.getHTML = function() {return this.html}; p.setWidth=function(w) {this.setSize(w,null)}; p.setHeight=function(h) {this.setSize(null,h)}; p.getWidth=function() {return this.w||0}; p.getHeight=function() {return this.h||0}; p.getBgImage=function() {return this.bgImage}; p.getBgColor=function() {return this.bgColor}; p.setCursor = function(c) { if (!c) c = 'default'; if (dynapi.ua.ie && this._cursor!=c) { this._cursor = c; if (this.css) this.css.cursor = c; } }; p.getCursor = function() {return this._cursor}; p.setBgColor=function(c) { if (c==null && !dynapi.ua.ns4) c = 'transparent'; this.bgColor = c; if (this.css) { if (dynapi.ua.ns4) this.doc.bgColor = c; else this.css.backgroundColor = c; } }; p.setBgImage=function(path) { this.bgImage=path; if (this.css) { if (dynapi.ua.ns4) { if (!path) this.setBgColor(this.getBgColor()); else setTimeout(this+'.elm.background.src="'+path+'"',1); } else this.css.backgroundImage='url('+path+')'; } }; p.getContentWidth=function() { if (this.elm==null) return 0; else { if (dynapi.ua.ns4) return this.doc.width; else if (dynapi.ua.ie) { if (dynapi.ua.platform=="mac") return this.elm.offsetWidth; return parseInt(this.elm.scrollWidth); } else { var tw = this.elm.style.width; this.elm.style.width = "auto"; var w = this.elm.offsetWidth; this.elm.style.width = tw; return w; } }; }; p.getContentHeight=function() { if (this.elm==null) return 0; else { if (dynapi.ua.ns4) return this.doc.height; else if (dynapi.ua.ie) { if (dynapi.ua.platform=="mac") return this.elm.offsetHeight; return parseInt(this.elm.scrollHeight); } else { var th = this.elm.style.height; this.elm.style.height = "auto"; var h = this.elm.offsetHeight; this.elm.style.height = th; return h; } } }; p.setClip=function(clip) { var cc=this.getClip(); for (var i=0;i<clip.length;i++) if (clip[i]==null) clip[i]=cc[i]; this.clip=clip; if (this.css==null) return; var c=this.css.clip; if (dynapi.ua.ns4) c.top=clip[0], c.right=clip[1], c.bottom=clip[2], c.left=clip[3]; else this.css.clip="rect("+clip[0]+"px "+clip[1]+"px "+clip[2]+"px "+clip[3]+"px)"; }; p.getClip=function() { if (this.css==null || !this.css.clip) return [0,0,0,0]; var c = this.css.clip; if (c) { if (dynapi.ua.ns4) return [c.top,c.right,c.bottom,c.left]; if (c.indexOf("rect(")>-1) { c=c.split("rect(")[1].split(")")[0].split("px"); for (var i=0;i<c.length;i++) c[i]=parseInt(c[i]); return [c[0],c[1],c[2],c[3]]; } else return [0,this.w,this.h,0]; } }; p.slideTo = function(endx,endy,inc,speed) { if (!this._slideActive) { var x = this.x||0; var y = this.y||0; if (endx==null) endx = x; if (endy==null) endy = y; var distx = endx-x; var disty = endy-y; if (x==endx && y==endy) return; var num = Math.sqrt(Math.pow(distx,2) + Math.pow(disty,2))/(inc||10)-1; var dx = distx/num; var dy = disty/num; this._slideActive = true; this._slide(dx,dy,endx,endy,num,this.x,this.y,1,(speed||20)); } }; p.slideStop = function() { this._slideActive = false; this.invokeEvent('pathcancel'); }; p._slide = function(dx,dy,endx,endy,num,x,y,i,speed) { if (!this._slideActive) this.slideStop(); else if (i++ < num) { this.invokeEvent('pathrun'); if (this._slideActive) { x += dx; y += dy; this.setLocation(Math.round(x),Math.round(y)); setTimeout(this+'._slide('+dx+','+dy+','+endx+','+endy+','+num+','+x+','+y+','+i+','+speed+')',speed); } else this.slideStop(); } else { this._slideActive = false; this.invokeEvent('pathrun'); this.setLocation(endx,endy); this.invokeEvent('pathfinish'); } }; --- NEW FILE --- /* DynAPI Distribution DynEvent, EventObject, DynElement Classes The DynAPI Distribution is distributed under the terms of the GNU LGPL license. */ function DynEvent(type,src) { this.inherit('DynObject'); this.type = type; this.src = src; this.origin = src; this.propagate = true; this.bubble = false; this.bubbleChild = null; this.defaultValue = true; }; var p = dynapi.setPrototype('DynEvent','DynObject'); p.getType = function() {return this.type}; p.getSource = function() {return this.src}; p.getOrigin=function() {return this.origin}; p.stopPropagation = function() {this.propagate = false}; p.preventBubble = function() {this.bubble = false}; p.preventDefault = function() {this.defaultValue = false}; p.getBubbleChild = function() {return this.bubbleChild}; function EventObject() { this.inherit('DynObject'); this._listeners = []; } p = dynapi.setPrototype('EventObject','DynObject'); p._addEventListener = DynAPI.functions.Null; p.addEventListener = function(el) { if (el) { for (var i=0;i<this._listeners.length;i++) if (this._listeners[i]==el) return; this._listeners[this._listeners.length] = el; if (this._listeners.length && this.captureMouseEvents) this.captureMouseEvents(); } }; p._removeEventListener = DynAPI.functions.Null; p.removeEventListener = function(el) { if (el) { DynAPI.functions.removeFromArray(this._listeners, el, false); if (!this._listeners.length && this.releaseMouseEvents) this.releaseMouseEvents(); } }; p.removeAllEventListeners = function() { this._listeners = []; }; p.invokeEvent = function(type,e,args) { if (!e) e = new DynEvent(type,this); if (this._listeners.length) for (var i=0;i<this._listeners.length;i++) { if (this._listeners[i]["on"+type]) this._listeners[i]["on"+type](e,args); if (!e.propagate) break; } if (this["on"+type]) this["on"+type](e,args); if(e.bubble && this.parent) { e.x += e.src.x; e.y += e.src.y; e.src = this.parent; e.bubbleChild = this; this.parent.invokeEvent(type,e,args); } }; function DynElement() { this.inherit('EventObject'); this.isChild = false; this._created = false; this.parent = null; this._dyndoc = null; this.children = []; this._childAnchors = []; }; p = dynapi.setPrototype('DynElement','EventObject'); p.addChild = function(c) { if (!c) return DynAPI.debug.print("Error: no object sent to [DynLayer].addChild()"); if (c.isChild) c.removeFromParent(); c.isChild = true; c.parent = this; if (c._saveAnchor) { c.setAnchor(c._saveAnchor); delete c._saveAnchor; } if (this._created) c._create(); this.children[this.children.length] = c; return c; }; p.removeChild = function(c) { var l = this.children.length; for (var i=0;i<l && this.children[i]!=c;i++); if (i!=l) { c._remove(); c._created = false; c.isChild = false; c.parent = null; c.dyndoc = null; this.children[i] = this.children[l-1]; this.children[l-1] = null; this.children.length--; } }; p.deleteChild = function(c) { c.removeFromParent(); c._delete(); }; p.deleteAllChildren = function() { var l = this.children.length; for(var i=0;i<l;i++) { this.children[i].del(); delete this.children[i]; } this.children = []; }; p.deleteFromParent = function () { if (this.parent) this.parent.deleteChild(this); }; p.removeFromParent = function () { if (this.parent) this.parent.removeChild(this); }; p._create = p._remove = p._delete = p._destroy = DynAPI.functions.Null; p.getAll = function() { var ret = []; var temp; var l = this.children.length; for(var i=0;i<l;i++) { ret[this.children[i].id] = this.children[i]; temp = this.children[i].getAll(); for(var j in temp) ret[j] = temp[j]; } return ret }; p.isParentOf = function(obj,equality) { if (!obj) return false; return (equality && this==obj) || this.getAll()[obj.id]==obj; }; p.isChildOf = function(obj,equality) { if(!obj) return false; return (equality && this==obj) || obj.getAll()[this.id]==this; }; DynElement._flagEvent = function(obj,type) { if (type=="create") obj._created = true; obj.invokeEvent(type); var l=obj.children.length; for (var i=0; i<l; i++) { DynElement._flagEvent(obj.children[i],type); } }; p.updateAnchor = function() { this.parent._updateAnchor(this.id); }; p._updateAnchor = function(id) { var dlyr = DynAPI.document.all[id]; var a = this._childAnchors[id]; var tw = this.w; var th = this.h; if (tw==null && th==null) return; var x = a.left; var y = a.top; var w = null; var h = null; if (a.centerH!=null) { x = Math.ceil(tw/2 - dlyr.getWidth()/2 + a.centerH); } else if (a.right!=null) { if (a.left!=null) w = tw - a.right - a.left; else x = tw - dlyr.getWidth() - a.right; } if (a.centerV!=null) { y = Math.ceil(th/2 - dlyr.getHeight()/2 + a.centerV); } else if (a.bottom!=null) { if (a.top!=null) h = th - a.bottom - a.top; else y = th - dlyr.getHeight() - a.bottom; } dlyr.setLocation(x,y); dlyr.setSize(w,h); }; p._updateAnchors = function() { var tw = this.w; var th = this.h; if (tw==null && th==null) return; for (id in this._childAnchors) this._updateAnchor(id); }; --- NEW FILE --- /* DynAPI Distribution MouseEvent Class The DynAPI Distribution is distributed under the terms of the GNU LGPL license. requires: dynapi.api.DynDocument */ function MouseEvent(type, src) { this.inherit('DynEvent',type,src); this.bubble = true; this._trap = false; this._trapSrc = null; this._button = 1; this._mouseEvent = null; }; var p = dynapi.setPrototype('MouseEvent','DynEvent'); p.getX = function() {return this.x}; p.getY = function() {return this.y}; p.getPageX = function() {return this.pageX}; p.getPageY = function() {return this.pageY}; p.trapMouseUp = function() {return this._trap = true}; p.getButton = function() { if (!this._mouseEvent) return "left"; var b = DynAPI.ua.ie? this._mouseEvent.button : this._mouseEvent.which; if (DynAPI.ua.ie){ if (b==2) b=3; else if (b==4) b=2; }; if (b==2) return "middle"; if (b==3) return "right"; else return "left"; }; MouseEvent._e = new MouseEvent(); MouseEvent.docEventHandler = function(e) { if (!e.target.lyrobj) { routeEvent(e); return true; } else { routeEvent(e); return MouseEvent._e.defaultValue; } }; MouseEvent.eventHandler = function(e) { var dynobject = this.lyrobj; if (DynAPI.ua.def) { if (DynAPI.ua.ie) var e = window.event; e.cancelBubble=true; } if (DynAPI.ua.def) var realsrc = dynapi.functions.getContainerLayerOf(DynAPI.ua.ie?e.srcElement:e.target) || dynobject; else if (DynAPI.ua.ns4) var realsrc = e.target.lyrobj || dynobject; if (DynAPI.ua.ns4) { if (!e.target.lyrobj && (e.type=="mousedown" || e.type=="mouseup" || e.type=="click")) { return routeEvent(e); } } if (!realsrc) return true if (DynAPI.ua.def) { if (e.type=="mouseout" && realsrc.isParentOf(dynapi.functions.getContainerLayerOf(DynAPI.ua.ie?e.toElement:e.relatedTarget),true)) return true; if (e.type=="mouseover" && realsrc.isParentOf(dynapi.functions.getContainerLayerOf(DynAPI.ua.ie?e.fromElement:e.relatedTarget),true)) return true; } var evt = MouseEvent._e; var type = e.type; evt.type = type; evt.src = realsrc; evt.bubbleChild = null; evt.defaultValue = true; evt.bubble = true; evt.pageX = DynAPI.ua.ie? e.x+document.body.scrollLeft : e.pageX-window.pageXOffset; evt.pageY = DynAPI.ua.ie? e.y+document.body.scrollTop : e.pageY-window.pageYOffset; evt.x = DynAPI.ua.ie? evt.pageX-evt.src.getPageX() : e.layerX; evt.y = DynAPI.ua.ie? evt.pageY-evt.src.getPageY() : e.layerY; evt._mouseEvent = e; if (DynAPI.ua.def) { if (evt.type=='mouseover') { var fromL = dynapi.functions.getContainerLayerOf(DynAPI.ua.ie?e.fromElement:e.relatedTarget); if(fromL && fromL.isChildOf(realsrc.parent,true)) evt.preventBubble(); } if (evt.type=='mouseout') { var toL = dynapi.functions.getContainerLayerOf(DynAPI.ua.ie?e.toElement:e.relatedTarget); if(toL && toL.isChildOf(realsrc.parent,true)) evt.preventBubble(); } } else if (DynAPI.ua.ns4 && (e.type=="mouseover" || e.type=="mouseout")) evt.preventBubble(); if (DynAPI.ua.def) { if (e.type=='mousedown') evt._trap = false; if (e.type=='mouseup' && evt._trap) evt.src = realsrc = evt._trapSrc; } evt.origin = realsrc; realsrc.invokeEvent(type,evt); if (DynAPI.ua.def) { if (e.type=='mousedown') { if (evt._trap) evt._trapSrc = realsrc; } } return evt.defaultValue; }; DynDocument.prototype.captureMouseEvents = function() { if(DynAPI.ua.def&&!DynAPI.ua.ie) { this.doc.addEventListener("mousemove",MouseEvent.eventHandler,false); this.doc.addEventListener("mousedown",MouseEvent.eventHandler,false); this.doc.addEventListener("mouseup",MouseEvent.eventHandler,false); this.doc.addEventListener("mouseover",MouseEvent.eventHandler,false); this.doc.addEventListener("mouseout",MouseEvent.eventHandler,false); this.doc.addEventListener("click",MouseEvent.eventHandler,false); this.doc.addEventListener("dblclick",MouseEvent.eventHandler,false); } else { if (DynAPI.ua.ns4) this.doc.captureEvents(Event.MOUSEMOVE | Event.MOUSEDOWN | Event.MOUSEUP | Event.CLICK | Event.DBLCLICK); this.doc.onmousemove=this.doc.onmousedown=this.doc.onmouseup=this.doc.onclick=this.doc.onclick=this.doc.ondblclick=MouseEvent.eventHandler; } }; DynDocument.prototype.releaseMouseEvents=function() { if(DynAPI.ua.def&&!DynAPI.ua.ie) { this.doc.removeEventListener("mousemove",MouseEvent.eventHandler,false); this.doc.removeEventListener("mousedown",MouseEvent.eventHandler,false); this.doc.removeEventListener("mouseup",MouseEvent.eventHandler,false); this.doc.removeEventListener("mouseover",MouseEvent.eventHandler,false); this.doc.removeEventListener("mouseout",MouseEvent.eventHandler,false); this.doc.removeEventListener("click",MouseEvent.eventHandler,false); this.doc.removeEventListener("dblclick",MouseEvent.eventHandler,false); } else { if (DynAPI.ua.ns4) this.doc.releaseEvents(Event.MOUSEMOVE | Event.MOUSEDOWN | Event.MOUSEUP | Event.CLICK | Event.DBLCLICK); this.doc.onmousemove=this.doc.onmousedown=this.doc.onmouseup=this.doc.onclick=this.doc.ondblclick=null; } }; DynLayer.prototype.captureMouseEvents = function() { var elm=this.elm; if(!elm) return; if(DynAPI.ua.def&&!DynAPI.ua.ie) { elm.addEventListener("mousemove",MouseEvent.eventHandler,false); elm.addEventListener("mousedown",MouseEvent.eventHandler,false); elm.addEventListener("mouseup",MouseEvent.eventHandler,false); elm.addEventListener("mouseover",MouseEvent.eventHandler,false); elm.addEventListener("mouseout",MouseEvent.eventHandler,false); elm.addEventListener("click",MouseEvent.eventHandler,false); elm.addEventListener("dblclick",MouseEvent.eventHandler,false); elm.ondragstart = dynapi.functions.False; elm.onselectstart = dynapi.functions.False; } else { if (DynAPI.ua.ns4) elm.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.CLICK | Event.DBLCLICK | Event.MOUSEMOVE); elm.onmousemove=elm.onmousedown=elm.onmouseup=elm.onmouseover=elm.onmouseout=elm.onclick=elm.ondblclick = MouseEvent.eventHandler; } }; DynLayer.prototype.releaseMouseEvents=function() { var elm=this.elm; if(!elm) return; if(DynAPI.ua.def&&!DynAPI.ua.ie) { elm.removeEventListener("mousemove",MouseEvent.eventHandler,false); elm.removeEventListener("mousedown",MouseEvent.eventHandler,false); elm.removeEventListener("mouseup",MouseEvent.eventHandler,false); elm.removeEventListener("mouseover",MouseEvent.eventHandler,false); elm.removeEventListener("mouseout",MouseEvent.eventHandler,false); elm.removeEventListener("click",MouseEvent.eventHandler,false); elm.removeEventListener("dblclick",MouseEvent.eventHandler,false); } else { if (DynAPI.ua.ns4) elm.releaseEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.CLICK | Event.DBLCLICK | Event.MOUSEMOVE); elm.onmousemove=elm.onmousedown=elm.onmouseup=elm.onclick=elm.ondblclick=null; } }; DynElement.prototype.assignMouseEvents = function() { if (this._listeners.length) this.captureMouseEvents(); }; |