From: Barre B. <ba...@ho...> - 2000-11-17 15:36:28
|
Hey.. I dug up the code for creating imagemaps outof layers. Now this addon to dynapi1 is pretty strightforward. ( hmm well, not really as I'm using a modified version of dynapi1.. but this code should work ) Had to do it in like a couple of hours, so I just hacked it quickly. Not my proudest programming effort :) Oh, and it only supports rectangular areas. But the idea is valid, i.e. the whole layer is treated as a map and you set areas that correspond to mouseevents(just like in an imagemap), which are enabled by tracking the mouse coords and comparing them against the areas set. Or something to that effect.... ------------------- example of use: ---------------------- window.onload = function(){ crap = new DynLayer("crapID") crap.setMap(0,0,33,16) // righttop corner, bottom left corner crap.setMapEvents("www.theurl.com","onmouseClickFunc ()","onmouseOverFunc()","onmouseOutFunc()") crap.show_msXY = true // shows coordinates so you can set the map } -------------------- the library addons: ---------------------- function setBoxMap(topX,topY,bottomX,bottomY){ this.show_msXY = false // if(typeof this.map_i == "undefined"){ this.map_overi = this.MSOUT = false this.map_i = 0 this.mapTX = new Array() this.mapTY = new Array() this.mapBX = new Array() this.mapBY = new Array() this.map_msdown = new Array() this.map_msover = new Array() this.map_msout = new Array() this.map_url = new Array() if(is.NS) this.elm.captureEvents (Event.MOUSEMOVE|Event.MOUSEDOWN) this.elm.onmousemove = BoxMap_msOver this.elm.onmousedown = BoxMap_msDown //this.elm.onmouseout = BoxMap_msOut this.elm.box = this } else this.map_i++ this.mapTX[this.map_i] = topX this.mapTY[this.map_i] = topY this.mapBX[this.map_i] = bottomX this.mapBY[this.map_i] = bottomY this.map_msdown[this.map_i] = "" this.map_msover[this.map_i] = "" this.map_msout[this.map_i] = "" this.map_url[this.map_i] = "" } DynLayer.prototype.setMap = setBoxMap function setBoxMapEvents(url,msdown,msover,msout){ this.map_url[this.map_i] = url this.map_msdown[this.map_i] = msdown this.map_msover[this.map_i] = msover this.map_msout[this.map_i] = msout } DynLayer.prototype.setMapEvents = setBoxMapEvents function BoxMap_msDown(e){ var y = (is.NS)? e.layerY:event.offsetY var x = (is.NS)? e.layerX:event.offsetX for(var i=0; i <= this.box.map_i; i++) { if( (y >= this.box.mapTY[i]) && (x >= this.box.mapTX[i]) && (y <= this.box.mapBY[i]) && (x <= this.box.mapBX[i]) ){ if(this.box.map_msdown[i]) eval (this.box.map_msdown[i]) if(this.box.map_url[i]) eval (this.box.map_url[i]) } } } function BoxMap_msOver(e){ var y = (is.NS)? e.layerY:event.offsetY var x = (is.NS)? e.layerX:event.offsetX if(this.box.show_msXY) status = x +" " +y for(var i=0; i <= this.box.map_i; i++) { if( (y >= this.box.mapTY[i]) && (x >= this.box.mapTX[i]) && (y <= this.box.mapBY[i]) && (x <= this.box.mapBX[i]) ){ if(i == this.box.map_overi) return false; if(this.box.map_msover[i]) eval (this.box.map_msover[i]) this.box.map_overi = i this.box.MSOUT = false break; } else this.box.MSOUT = true } if(!isNaN(this.box.map_overi) && this.box.MSOUT){ eval(this.box.map_msout[this.box.map_overi]) this.box.map_overi = null } return true; } |