Nothing better than needing them yourself in order to contribute to the
API :).
The are two parts in the script. First you need to parse your links so
anchors are redirected to a custom javascript method. Call this one
after content has been set.
DynLayer.prototype.parseLinks = function() {
var lks
if(is.ns4) lks = this.doc.links
else if(is.ie) lks = this.elm.all.tags('a')
else lks = this.elm.getElementsByTagName("a")
for(var i=0;i<lks.length;i++) {
var li = lks[i]
if(li.href.indexOf("#")>=0) {
// Anchors
var guere = li.href.substring(li.href.indexOf("#")+1)
li.href = "javascript:goAnchor('"+guere+"')"
}
}
}
Now all our anchors will call a goAnchor method
function goAnchor(name) {
myLayer.goAnchor(name,0,0,false,false)
}
And here goes the extension. Accepts additional parameters such as
position offsets ( in case you want margins ) and allows to ignore
scrolling for one coordinate.
DynLayer.getCoords = function(obj) {
var ret = obj.offsetParent ? DynLayer.getCoords(obj.offsetParent) : {
x:0, y:0 }
ret.x += obj.offsetLeft
ret.y += obj.offsetTop
return ret
}
DynLayer.prototype.goAnchor = function(name,xoff,yoff,ignoreX,ignoreY) {
var destX = -1
var destY = -1
// Search for anchor position
if(is.ie) {
var alllinks = contenidosScr.elm.all.tags('a')
for(var i=0;i<alllinks.length;i++) {
var li = alllinks[i]
if(li.name==name) {
var coords = IbsMinimalScroll.getCoords(li)
destX = coords.x - this.getPageX()
destY = coords.y - this.getPageY()
}
}
}
else if(is.ns4) {
var alllinks = this.doc.anchors
for(var i=0;i<alllinks.length;i++) {
var li = alllinks[i]
if(li.name==name) {
destX = li.x
destY = li.y
}
}
}
// Apply offsets
destX -= xoff
destY -= yoff
// Move layer within parent
this.moveTo(ignoreX?this.x:-destX,ignoreY?this.y:-destY)
}
I'll make into a proper extension as soon as I can. In the meantime,
enjoy this.
Cya
_______________________________________________
Dynapi-Dev mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dynapi-dev
[Dynapi-Dev] Dynlayer extension: allows anchors to work within a layer.
Jordi - IlMaestro - Ministral Mon, 07 May 2001 09:56:20 -0700
