|
From: Pascal B. <pa...@dy...> - 2000-11-01 19:13:16
|
First a question, in createElement the following code is there:
if (!this.dyndoc.allID[this.id]) {
if (DynLayer.unassigned.length>0) {
for (var i=0; i<DynLayer.unassigned.length; i++) {
if (DynLayer.unassigned[i]==this)
DynAPI.removeFromArray(DynLayer.unassigned,this)
}
}
} else...
in the previous version this was:
if (!this.dyndoc.allID[this.id]) {
this.dyndoc.all[this.dyndoc.all.length]=this
this.dyndoc.allID[this.id]=this
} else...
which looks better then the first code.. it should be added to the
dyndoc.all array, the remove from the unassigned
array is done in the addChild() method of the parent.. also the
removeFromArray already walks thru the complete array
to see if the child is in it, so no need to do that before calling the array
(kinda makes it a double-check slowing things down)
I think the original code was correct (Scott's original code I believe) not
sure where this change comes from
but I think it's not doing what it should do (i.e.: add it to the dyndoc.all
array)
I've did some more research into the speed improvements, and the previous
setClip() fix wasn't correct (so dont use it)..
I now took another aproach and unrolled most css calls from within the
createElement.. this shows some nice improvements.
Here's a re-hack of the createElement() method (with the old code as
explained above still in place) look at the comments for
info on changes:
DynLayer.prototype.createElement=function() {
if (this.created || !this.parent || !this.parent.created) return
var id=this.id
var parent=this.parent
var p=this.pad // [*] changed this line, it was var p=this.pad||0
var w=this.w
var lyr
var doc=parent.doc
if (parent.isDynDocument) this.dyndoc=parent
else this.dyndoc=this.parent.dyndoc
// [!] warning, this is still the old code from Scott, not the code from
the latest release..
if (!this.dyndoc.allID[this.id]) {
this.dyndoc.all[this.dyndoc.all.length]=this
this.dyndoc.allID[this.id]=this
} else {
alert("Not allowed to create the same element twice in the same
document: "+this.id)
return
}
if (is.ns && doc.recycled && doc.recycled.length>0) {
lyr=doc.recycled[0]
DynAPI.removeFromArray(doc.recycled,doc.recycled[0],false)
} else {
var parentElement=(parent.isDynLayer)? parent.elm : parent.doc.body
if (is.ns4) {
lyr=new Layer(w,parent.elm);
lyr.captureEvents(Event.LOAD);
lyr.onload=function() {}
if (p) lyr.padding=p; // [*] added an if (p)
}
else if (is.ie4) {
if (!p) p=0 // [*] we call this backward compatibility :-)
var code='<div id="' + id + '" style="position:absolute; left:0px;
top:0px; padding:'+p+'px; width:'+w+'px;"></div>'
parentElement.insertAdjacentHTML("beforeEnd", code)
lyr=parentElement.children[parentElement.children.length-1]
}
else if (is.ie5 || is.ns5) {
lyr=this.dyndoc.doc.createElement("DIV")
lyr.style.position="absolute"
if (p) lyr.style.padding=p // [*] added an if (p) skipping this
actually saves some noticeable time! (strangely)
lyr.id=id
parentElement.appendChild(lyr)
}
}
this.assignElement(lyr)
// [-] removed this.setBgColor, and replaced it with following code
if (this.bgColor!=null)
if (is.ns4) this.doc.bgColor=this.bgColor
else this.css.backgroundColor=this.bgColor
}
if (this.bgImage!=null) this.setBgImage(this.bgImage)
if (this.hasEventListeners) this.captureMouseEvents()
if (this.html!=null) {
this.setHTML(this.html)
if (this.w==null) this.w=this.getContentWidth()
if (this.h==null) this.h=this.getContentHeight()
}
// [-] Now for the major changes, removed all setSize() moveTo() and clip()
methods, and replaced it with this code:
var mycss=this.css
if (is.ns) {
mycss.left=this.x
mycss.top=this.y
mycss.top=mycss.left=0
mycss.right=this.w
mycss.bottom=this.h
} else {
mycss.pixelLeft=this.x
mycss.pixelTop=this.y
}
if (is.ie || is.ns5) {
mycss.width=this.w
mycss.height=this.h
mycss="rect(0px "+this.w+"px "+this.h+"px 0px)"
}
mycss.visibility=this.visible?"inherit":(is.ns4?"hide":"hidden")
// -- end of changes :-)
if (is.ie55 && this.bgImage==null && this.html==null)
this.setBgImage('javascript:bugfix=true')
if (this.z) this.setZIndex(this.z)
// [!] this also differs from original code, no call to
createChildElements, but do it here..
// no call to other function should also speed it up a bit.
for (var i in this.children) this.children[i].createElement()
if (this.onCreate) this.onCreate()
}
Pascal Bestebroer
pa...@dy...
http://www.dynamic-core.net
|