From: Robert R. <rai...@us...> - 2002-04-10 18:31:42
|
Update of /cvsroot/dynapi/dynapi2x/src/api In directory usw-pr-cvs1:/tmp/cvs-serv19326/src/api Added Files: dyndocument.js dynlayer.js event.js mouse_ie.js mouse_ns4.js mouse_ns6.js Log Message: initial import --- 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; this._dyndoc = this; 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 = dynapi.functions.Zero; 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._dynobj = 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.captureMouseEvents) this.captureMouseEvents(); this.invokeEvent('load'); }; p.destroyAllChildren = function() { for (var i=0;i<this.children.length;i++) { this.children[i]._destroy(); delete this.children[i]; } }; p._destroy = function() { this.destroyAllChildren(); 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'); this._updateAnchors(); } } }; 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._textSelectable = true; }; var p = dynapi.setPrototype('DynLayer','DynElement'); p._destroy = function() { for (var i=0;i<this.children.length;i++) { this.children[i]._destroy(); } this.removeAllEventListeners(); if (this.elm) this._remove(); DynObject.all[this.id] = null; 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; this.doc = null; this.css = null; this._dyndoc = null; this.parent = null; }; p._remove = function() { if (this.elm) { if (dynapi.ua.def) { //this.elm.style.visibility = "hidden"; this.elm.innerHTML = ""; this.elm.outerHTML = ""; } else if (dynapi.ua.ns4) { 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.elm = null; this.releaseMouseEvents(); } /*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; if (this.visible) elm.visibility = 'inherit'; DynLayer._assignElement(this,elm); //if (this.updateLayout) this.updateLayout(); 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._dyndoc = dlyr.parent._dyndoc; 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); for (var i=0; i<dlyr.children.length; i++) { DynLayer._assignElement(dlyr.children[i]); } if (dlyr._hasMouseEvents) dlyr.captureMouseEvents(); }; p.getOuterHTML=function() { var s='\n<layer id="'+this.id+'"'; if (this.visible) s+=' visibility="inherit"'; else 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._updateAnchors) this._updateAnchors(); if (this.css) { if (cw) this.css.clip.width = this.w || 0; if (ch) this.css.clip.height = this.h || 0; if (this.updateLayout) this.updateLayout(); } } return (cw||ch); }; p.setHTML=function(html) { var ch = (html!=null && html!=this.html); if (ch) { this.html = html; if (this.css) { this.doc.open(); this.doc.write(this.html); this.doc.close(); var i; for (i=0;i<this.doc.images.length;i++) this.doc.images[i]._dynobj = this; for (i=0;i<this.doc.links.length;i++) this.doc.links[i]._dynobj = 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.elm._dynobj = dlyr; dlyr._dyndoc = dlyr.parent._dyndoc; if (dlyr.z && dynapi.ua.ns6) dlyr.css.zIndex = dlyr.z; 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); } for (var i=0; i<dlyr.children.length; i++) { DynLayer._assignElement(dlyr.children[i]); } if (this._textSelectable==false) elm.onselectstart = dynapi.functions.Disallow; if (dynapi.ua.ie && elm.all.tags("img").length) elm.ondragstart = dynapi.functions.False; if (dlyr._hasMouseEvents) dlyr.captureMouseEvents(); }; 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.ie && this.bgImage==null && this.html==null) s+=' background-image:none;'; 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._updateAnchors) this._updateAnchors(); 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)'; if (this.updateLayout) this.updateLayout(); } } 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.setTextSelectable=function(b) { this._textSelectable = b if (dynapi.ua.ie) { if (this.elm) this.elm.onselectstart = b? dynapi.functions.Allow : dynapi.functions.Deny; if (!b) this.setCursor('default'); } if (dynapi.ua.ns4){ this.addEventListener({ onmousemove : function(e) { e.preventDefault(); } }); } // && this.captureMouseEvents && !this._hasMouseEvents) this.captureMouseEvents(); }; 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) { if (dynapi.ua.ns4 && this.w==null) s += '<nobr>'+this.html+'</nobr>'; else 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 = 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.captureMouseEvents) { if (this._created && !this._hasMouseEvents && (el.onmousedown || el.onmouseup || el.onmouseover || el.onmouseout || el.onclick || el.ondblclick)) { this.captureMouseEvents(); } else this._hasMouseEvents = true; } } }; p.removeEventListener = function(el) { if (el) { DynAPI.functions.removeFromArray(this._listeners, el, false); if (!this._listeners.length && this.releaseMouseEvents && this.getClassName()!='DynDocument') this.releaseMouseEvents(); } }; p.removeAllEventListeners = function() { this._listeners = []; }; p.invokeEvent = function(type,e,args) { if (!e) e = new DynEvent(type,this); e.src = this; e.type = type; 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) { //if ((type=="mouseover" || type=="mouseout") && e._relative==this.parent) return; e.x += this.x; e.y += this.y; 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.getChildren = function() {return this.children} p.getAllChildren = 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.getParents = function(l) { if (l==null) l = []; if (this.parent) { l[l.length] = this.parent; l = this.parent.getParents(l); } return l; }; p.isParentOf = function(c) { if (c) { var p = c.getParents(); for (var i=0;i<p.length;i++) { if (p[i]==this) return true; } } return false; }; p.isChildOf = function(p) { if (!p) return false; return p.isParentOf(this); }; DynElement._flagEvent = function(c,type) { if (type=="create") c._created = true; c.invokeEvent(type); for (var i=0; i<c.children.length; i++) { DynElement._flagEvent(c.children[i],type); } }; p.updateAnchor = function() { this.parent._updateAnchor(this.id); }; p._updateAnchor = function(id) { if (!id) return; var dlyr = DynObject.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(dyndoc) { this.inherit('DynEvent'); this.bubble = true; this._mouseEvent = null; this._relative = null; this._dyndoc = dyndoc; }; 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 = dynapi.functions.Null; p.getRelative = function() {return this._relative}; p.preventBubble = function() {this.bubble = false;}; p.getButton = function() { if (!this._mouseEvent) return "left"; var b = this._mouseEvent.button; if (b==4) return "middle"; if (b==2) return "right"; else return "left"; }; p._init = function(type,e,src) { this.type = type; this._mouseEvent = e; this.origin = src; this.bubbleChild = null; this.defaultValue = true; this.bubble = true; }; p._invoke = function() { var o = this.origin; o.invokeEvent(this.type,this); }; MouseEvent._getContainerLayerOf = function(element) { if (!element) return null; while (!element._dynobj && element.parentElement && element.parentElement!=element) { element = element.parentElement; } return element._dynobj; }; MouseEvent._eventHandler = function() { var dynobj = this._dynobj; if (!dynobj) return true; var dyndoc = dynobj._dyndoc; var e = dyndoc.frame.event; var target = e.srcElement; var me = dyndoc._mouseEvent; var src = MouseEvent._getContainerLayerOf(target); me._init(e.type,e,src); var rel = e.type=="mouseout"? e.toElement : e.fromElement; var r = me._relative = MouseEvent._getContainerLayerOf(rel); if (e.type=="mouseout" || e.type=="mouseover") { if (r&&src.isParentOf(r)) return; if (r&&(r==src.parent||r.isChildOf(src.parent))) me.bubble=false; } me.pageX = e.clientX; me.pageY = e.clientY; me.x = me.pageX - src.getPageX(); //offsetX; me.y = me.pageY - src.getPageY(); //offsetY; e.cancelBubble = true; me._invoke(); }; DynElement.prototype.captureMouseEvents = function() { this._hasMouseEvents = true; if (this.elm) { var elm = (this.getClassName()=='DynDocument')? this.doc : this.elm; elm.onmouseover = elm.onmouseout = elm.onmousedown = elm.onmouseup = elm.onclick = elm.ondblclick = elm.onmousemove = MouseEvent._eventHandler; } }; DynElement.prototype.releaseMouseEvents = function() { this._hasMouseEvents = false; if (this.elm) { var elm = (this.getClassName()=='DynDocument')? this.doc : this.elm; elm.onmousedown = elm.onmouseup = elm.onclick = elm.ondblclick = null; } }; function main() { dynapi.document._mouseEvent = new MouseEvent(dynapi.document); } if (!dynapi.loaded) main(); --- 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(dyndoc) { this.inherit('DynEvent'); this.bubble = true; this._browserEvent = null; this._relative = null; this._dyndoc = dyndoc; }; 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 = dynapi.functions.Null; p.getRelative = function() {return this._relative}; p.getButton = function() { if (!this._browserEvent) return "left"; var b = this._browserEvent.which; if (b==2) return "middle"; if (b==3) return "right"; else return "left"; }; p._init = function(type,e,src) { this.type = type; this._browserEvent = e; this.origin = src; this.bubbleChild = null; this.pageX = e.pageX-this._dyndoc.frame.pageXOffset; this.pageY = e.pageY-this._dyndoc.frame.pageYOffset; if (e.target._dynobj == src) { this.x = e.layerX; this.y = e.layerY; } else { this.x = e.pageX - (src.pageX||0); this.y = e.pageY - (src.pageY||0); } this.defaultValue = true; this.bubble = true; }; p._invoke = function() { var o = this.origin; if (this.type=='mousedown' && o._textSelectable==false) this.defaultValue = false; o.invokeEvent(this.type,this); // synthetic click event if (this.type=='mouseup') { this._init('click',this._browserEvent,o); this._invoke(); // synthetic dblclick event if (dynapi.ua.other); } }; function main() { dynapi.document._mouseEvent = new MouseEvent(dynapi.document); } if (!dynapi.loaded) main(); MouseEvent._docMoveHandler = function(e) { var dyndoc = this._dynobj; var src = e.target; var dynobj = src._dynobj || src._dynobji; if (!dynobj) { dyndoc._moveOver = null; return true; } var me = dyndoc._mouseEvent; //dynapi.debug.status('move '+dynobj.name+' '+e.layerX+' '+e.layerY); me._init('mousemove',e,dynobj); me._invoke(); var defaultVal = me.defaultValue; // synthetic mouseover/out events if (dyndoc._moveOver!=dynobj) { var rel = dyndoc._moveOver; var bubble = true; // mouse out if (rel) { // && !rel.isChildOf(dynobj) // during mouseout e.getRelated() is which elm it is moving to //bubble = !dynobj.isChildOf(rel); me._init('mouseout',e,rel); me._relative = dynobj; me._invoke(); //MouseEvent._generateEvent('mouseout',e,me,rel,dynobj,bubble); // out occurs before over } // mouse over dyndoc._moveOver = dynobj; //if (rel) var bubble = !rel.isChildOf(dynobj); //var bubble = !dynobj.isChildOf(rel); // during mouseover e.getRelated() is which elm it is moving to me._init('mouseover',e,dynobj); me._relative = rel; me._invoke(); //MouseEvent._generateEvent('mouseover',e,me,dynobj,rel); } return defaultVal; } MouseEvent._eventHandler = function(e) { var src = e.target; var dynobj = this._dynobj; if (!dynobj) return true; var dyndoc = dynobj._dyndoc; var me = dyndoc._mouseEvent; me._wasHandled = false; var r = routeEvent(e); if (!me._wasHandled) { if (src._dynobji) { // src._dynobji == dynlayer.doc.images[x]._dynobji me._init(e.type,e,src._dynobji); if (e.type=='mousedown') me.defaultValue = false; me._invoke(); } else if (src._dynobj) { // src._dynobj == dynlayer.doc._dynobj me._init(e.type,e,src._dynobj); me._invoke(); } else { // dynobj == dynlayer.elm._dynobj me._init(e.type,e,dynobj); me._invoke(); } me._wasHandled = true; } return me.defaultValue; }; DynElement.prototype.captureMouseEvents = function() { this._hasMouseEvents = true; var elm = this.elm; if (elm) { elm.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.DBLCLICK); elm.onmousedown = elm.onmouseup = elm.ondblclick = MouseEvent._eventHandler; if (this.getClassName()=='DynDocument') { // move/over/out events are generated from the document this.doc.captureEvents(Event.MOUSEMOVE); elm.onmousemove = MouseEvent._docMoveHandler; } elm._dynobj = this; this.doc._dynobj = this; for (var i=0;i<this.doc.images.length;i++) this.doc.images[i]._dynobji=this; for (var i=0;i<this.doc.links.length;i++) this.doc.links[i]._dynobj=this; } }; DynElement.prototype.releaseMouseEvents = function() { this._hasMouseEvents = false; var elm = this.elm; if (elm) { elm.releaseEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.DBLCLICK); elm.onmousedown = elm.onmouseup = elm.ondblclick = null; if (this.getClassName()=='DynDocument') { elm.releaseEvents(Event.MOUSEMOVE); elm.onmousemove = null; } elm._dynobj = null; this.doc._dynobj = null; for (var i=0;i<this.doc.images.length;i++) this.doc.images[i]._dynobji=null; for (var i=0;i<this.doc.links.length;i++) this.doc.links[i]._dynobj=null; } }; --- 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(dyndoc) { this.inherit('DynEvent'); this.bubble = true; this._mouseEvent = null; this._relative = null; this._dyndoc = dyndoc; }; 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 = dynapi.functions.Null; p.getRelative = function() {return this._relative}; p.preventBubble = function() { this.bubble = false; }; p.getButton = function() { if (!this._mouseEvent) return "left"; var b = this._mouseEvent.which; if (b==2) return "middle"; if (b==3) return "right"; else return "left"; }; p._init = function(type,e,src) { this.type = type; this._mouseEvent = e; this.origin = src; this.bubbleChild = null; this.defaultValue = true; this.bubble = true; }; p._invoke = function() { var o = this.origin; o.invokeEvent(this.type,this); }; MouseEvent._getContainerLayerOf = function(element) { if (!element) return null; while (!element._dynobj && element.parentNode && element.parentNode!=element) { element = element.parentNode; } return element._dynobj; }; MouseEvent._eventHandler = function(e) { var dynobj = this._dynobj; if (!dynobj) return true; var dyndoc = dynobj._dyndoc; var target = e.target; var me = dyndoc._mouseEvent; var src = MouseEvent._getContainerLayerOf(target); me._init(e.type,e,src); var rel = e.relatedTarget; var r = me._relative = MouseEvent._getContainerLayerOf(rel); if (e.type=="mouseout" || e.type=="mouseover") { if (r&&src.isParentOf(r)) return; if (r&&(r==src.parent||r.isChildOf(src.parent))) me.bubble=false; } me.pageX = e.clientX; me.pageY = e.clientY; me.x = me.pageX - src.getPageX(); //offsetX; me.y = me.pageY - src.getPageY(); //offsetY; e.cancelBubble = true; me._invoke(); }; DynElement.prototype.captureMouseEvents = function() { this._hasMouseEvents = true; var elm = (this.getClassName()=='DynDocument')? this.doc : this.elm; 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); }; DynElement.prototype.releaseMouseEvents=function() { this._hasMouseEvents = false; var elm = (this.getClassName()=='DynDocument')? this.doc : this.elm; 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); }; function main() { dynapi.document._mouseEvent = new MouseEvent(dynapi.document); } if (!dynapi.loaded) main(); |