// the following code was lifted from webreference.com DHTML LAB "Array Power III" // it is essential for the OjectManager to run in Internet Explorer //---------------------------------------------------------------------------------- if(Array.prototype.splice && typeof([0].splice(0))=="number") Array.prototype.splice = null; if(!Array.prototype.splice) { function array_splice(ind,cnt){ if(arguments.length == 0) return ind; if(typeof ind != "number") ind = 0; if(ind < 0) ind = Math.max(0,this.length + ind); if(ind > this.length) { if(arguments.length > 2) ind = this.length; else return []; } if(arguments.length < 2) cnt = this.length-ind; cnt = (typeof cnt == "number") ? Math.max(0,cnt) : 0; removeArray = this.slice(ind,ind+cnt); endArray = this.slice(ind+cnt); this.length = ind; for(var i=2;i> respectively browser window width, height, midpoimt x, * * midpoint y, * * * * .event >> a copy or pointer to the event object as passed along * * .mouseX >> x position of the mouse per current event captured * * .mouseY >> y pos " * * .dx .dy >> change in x and y since last mousemove was passed along * * to gui (used for dragging) * * * * * * public methods * * -------------- * * .setTheme(Array) >> sets the theme used by the guiManager. used for box * * border color for open/close flourish and for dragging. * * .getWindowSize() >> resets w,h,mx,my properties * * .addObject() >> called by gui to add itself to the event list. also * * gui then automaticaly focused, blurred, and setup to * * receive mousevents and dragcalls * * .killObject() >> called by close function of gui to remeove gui from * * event list and no longer tracked * * .init(x,y) >> called to initialize the event capture and setup any * * preregistered guis, also sets up the default base * * position where windows are opened * * .showGUI(gui,ox,oy,ax,ay) >> opens op (setXY) gui, using expaning box * * animation flourish. ox oy setup the origin * * of the flourish box. ax and ay are used to * * override the guimanagers default positioning * * based on the init * * * ********************************************************************************* */ defaultScheme = new Array(); defaultScheme["border"]="808080"; function GuiManager(id) { this.id=id; this.objects = new Array(); // array of objects -- contains actual pointers to the objects this.active = null; // on instantiation there are no active layers this.dropIntoObjRef=null; this.bottomZ =100; this.topZ = 100; // and the current top zIndex = 0; this.dragObject = null; // reference to object undergoing drag event this.floatBlur=false; // whether float object is blurred this.floatZ = 2000; // abritrary setting of top Z index this.floatObject = null;// float object is set to null on instantiation this.startx=0; this.starty=0; this.x=0; this.y=0; this.sx = new Array(); this.sy= new Array(); this.originalX=0; // used when dragging objects need to be returned... this.originalY=0; // to their original positions. this.mouseX=0; this.mouseY=0; this.dx=0; this.dy=0; this.event = null; this.pageIsLoaded=false; this.startup = new Array(); // guis register at compile-time to be initialized onload. this.popup =null; this.w; this.h; this.showingFlag=false; this.hidingFlag=false; this.box=new Array(); this.theme = defaultScheme; this.addObject = addObject; // methods to add object this.killObject = killObject; this.parseObjects = parseObjects; this.makeActive=makeActive; this.checkDrop =checkDrop; this.mousedown = mousedown; this.mousemove = mousemove; this.mouseup = mouseup; this.rightClick = rightClick; this.popup=null; this.recordEvent = recordEvent; this.init = guiManagerInit; this.addMeToStartup = addMeToStartup; this.initObjects = initObjects; this.getObjectRef = getObjectRef; this.showGUI = showGUI; this.hideGUI = hideGUI; this.setTheme = setTheme; this.getWindowSize= getWindowSize; this.setBounds = setBounds; } function guiManagerInit(x,y,scheme,dBugMode) { this.startx=x;this.starty=y;this.x=x;this.y=y; this.pageIsLoaded=true; // to capture events and pass them to a function that is a method of an object (this) // we have to nest the fucntion for some dumb reason; otherwise the function loses object scope if(ie) { document.onmousedown=mousedown; document.onmousemove=mousemove; document.onmouseup=mouseup; } if(ns) { window.captureEvents(Event.MOUSEDOWN|Event.MOUSEMOVE|Event.MOUSEUP); window.onmousedown =mousedown; window.onmousemove= mousemove; window.onmouseup=mouseup; } if(ns6) { window.addEventListener("mousedown", mousedown, true); window.addEventListener("mousemove", mousemove, true); window.addEventListener("mouseup", mouseup, true); } this.initObjects(); this.theme=scheme; if(w3){ for(bx=0;bx<5;bx++){ this.box[bx] = new Box("guiManager.box["+bx+"]","box"+bx,1,1,this.theme["border"]); this.box[bx].layer[0].zIndex=2000; this.box[bx].layer[0].borderWidth=2; } this.dragBox = new Box("guiManager.dragBox","box2",1,1,this.theme["border"]); this.dragBox.layer[0].zIndex=2000; this.dragBox.layer[0].borderWidth=2; } this.getWindowSize(); this.setBounds(0,0,this.w,this.h); // } function getWindowSize() { if (ns||ns6){ this.w=self.innerWidth; this.h=self.innerHeight; } if (ie){ this.w=document.body.clientWidth; this.h=document.body.clientHeight; } this.mx = this.w/2 ; this.my = this.h/2 ; } function setBounds(leftX,topY,rightX,bottomY) { this.leftBound = leftX; this.rightBound = rightX; this.topBound=topY; this.bottomBound =bottomY; } function addMeToStartup(object) { this.startup[this.startup.length]=object; } function initObjects() { for (s=0;sthis.rightBound/4) this.x=this.startx; if (this.y>this.bottomBound/4) this.y=this.starty; //overide: open at specific position if (ax && ay) { if (ax =="center") ax = guiManager.mx-(guiObject.clipW/2); if (ay =="center") ay = guiManager.my-(guiObject.clipH/2); this.x=(ax>-1)? ax:0; this.y=(ay>20)?ay:50; ax=null;ay=null; } if(w3) { this.sx[guiObject.id]=ox; this.sy[guiObject.id]=oy; this.box[bc].busy =true; this.box[bc].setSize(15,15) this.box[bc].setXY(ox,oy,1); this.box[bc].Move(this.x+guiObject.clipW/2-ox,this.y+guiObject.clipH/2-oy,200) setTimeout('guiManager.box['+bc+'].grow('+ guiObject.clipW+','+guiObject.clipH+',400,'+(-guiObject.clipW/2)+','+(-guiObject.clipH/2)+')',200); setTimeout('guiManager.box['+bc+'].hide();guiManager.box['+bc+'].busy=false;',600); setTimeout(guiObject.id+'.setXY('+this.x+','+this.y+',1)',600); } else guiObject.setXY(this.x,this.y,1); this.showingFlag=false; } function hideGUI(object) { if (this.hidingFlag) return this.hidingFlag = true; if(w3) { for(bx=0;bxthis.objects.length) return; for(i=0;i0) this.makeActive(this.objects.length-1); } function parseObjects() { returnflag = false; for (p=this.objects.length-1;p>-1;p--) { if(this.mouseX this.objects[p].x+this.objects[p].clipW) continue; if (this.mouseY this.objects[p].y+this.objects[p].clipH) continue; if (this.active != this.objects[p]){ if(this.activeMenu && this.objects[p].type!='menu'){ if(this.activeMenu.activeChild) this.activeMenu.childMenu[activeChild].hideAll(); } this.makeActive(p); } this.active.parseXY(this.mouseX,this.mouseY); returnflag = true; break; } if(returnflag==false && this.activeMenu) { //alert(this.activeMenu.id) if(this.activeMenu.activeChild) this.activeMenu.childMenu[this.activeMenu.activeChild].hideAll(); } return returnflag } function checkDrop() // check to see if object has been dropped on anything { returnObject = null; // simply returns object in mouse range like this.dropIntoObjRef = null; /// like parseObjects() for (i=this.objects.length-1;i>-1;i--) { if(this.mouseX this.objects[i].x+this.objects[i].clipW) continue; if (this.mouseY this.objects[i].y+this.objects[i].clipH) continue; if (this.objects[i]==dragObject) continue; returnObject = this.objects[i]; this.dropIntoObjRef= i; break; } return returnObject; } // event handlers function recordEvent(e) { ox = this.mouseX; oy = this.mouseY; if (ie) // first get oblig sex and wine coordinates { this.event = event; this.mouseX = (event.clientX + document.body.scrollLeft); this.mouseY = (event.clientY + document.body.scrollTop); this.button = event.button; } if(ns || ns6) { this.event = e; this.mouseX = e.pageX; this.mouseY = e.pageY; this.button = e.which } this.dx = this.mouseX - ox; this.dy = this.mouseY - oy; } function mousedown(e) { guiManager.recordEvent(e) us = guiManager.parseObjects(); if (!us) { if(ns) routeEvent(e); return false; } if(w3) e.preventDefault(); if(ns6) { document.body.addEventListener("select",rtf,true) } if(ns) routeEvent(e); return false; } function rtf(){alert('test');return false}; function mousemove(e) { guiManager.recordEvent(e) if (guiManager.dragObject){ guiManager.dragObject.drag() if(ie) event.returnValue=false; return true; }else{ if(ns) routeEvent(e); return true; } } function mouseup(e) { clearTimeout(guiManager.scrollRepeat) guiManager.recordEvent(e) if (guiManager.dragObject){ if(ns6) { document.body.removeEventListener("select",rtf,true) } guiManager.dragObject.dragStop(); guiManager.dragObject = null; } if(ns) routeEvent(e); return true; } function rightClick() { return false; } // // end guiManager //------------------------------------------------- //------------------------------------------------- //utlities global functions /* Basic cross browser dom interface functions that are somewhat polymorphic. getters can usually handle and id for a css obj or the css obj itself ********************************************************************************* * clipLayer( id or obj, left, top, width, height) * * * * * * * * * * * * * * * * * * * * * * * * * * * ********************************************************************************* */ function clipLayer(layerRef,x,y,w,h) { if (typeof layerRef=='string') layerRef=getStyle(layerRef); if(ns) { layerRef.clip.top=y; layerRef.clip.left=x; layerRef.clip.height=h; layerRef.clip.width=w; }else{ layerRef.clip = "rect("+y+"px "+(x+w)+"px "+(y+h)+"px "+x+")"; } } function getLayer(id) { if(w3) return document.getElementById(id); if(ie) return document.all[id]; if(ns) return document.layers[id]; } function getHeight(id) { if (typeof id == 'object') obj = id; else obj = getLayer(id); if(w3||ie) return obj.offsetHeight; if(ns) return obj.document.height; } function getWidth(id) { if (typeof id == 'object') obj = id; else obj = getLayer(id); if(w3||ie) return obj.offsetWidth; if(ns) return obj.document.width; } function getStyle(id) { if (typeof id == 'object') obj = id; else obj = getLayer(id); if(w3||ie) return obj.style; if(ns) return obj; } function makeLayer(id,width,html,bg) //add bg to layer right away for NS$ compatibility { if(w3) { el = document.createElement('DIV'); el.id =id; if (bg) el.style.backgroundImage="url("+bg.src+")"; el.style.width = width+"px"; el.style.position ="absolute"; el.style.visibility = "hidden"; el.innerHTML = html; document.body.appendChild(el); return el; } if(ie4) { divs=""; str = divs+html+dive; document.body.insertAdjacentHTML("beforeEnd",str); while(!document.all[id]){}; document.all[id].innerHTML=html; return document.all[id]; } if (ns) { if (bg) bgs = " background=\""+bg.src+"\" "; else bgs=""; templayer = new Layer(width); templayer.document.open(); templayer.document.write(""+html+""); templayer.document.close(); return templayer; } } // //end Utilities //----------------------------------------------------- //------------------------------------------------------- /* Constructor: AbstractGUI the base constructor for js objects to e used with the GuiMananger MEMBERS GUIS MUST HAVE: ********************************************************************************* * properties * * ------------------------------------------------------------------------- * * .layers >> Array of CSS objects * * .x .y >> xand y positions of the gui's top-left * * .clipW * * .clipH >> clip width and height from top-left * * .visible >> indicates whether gui layers are visible. * * * * functions * * ------------------------------------------------------------------------- * * .hide() --> must call killObject() * * .hideAll() --> for menus and other recursive containers * * .show() --> must call addObject() * * .focus(z) --> gui focus sets the zIndex CSS property starting at z * * .blur() --> gui blur * * .parseXY(x,y) --> gui's self parsing XY method for mousedown event. * * .init() --> init the gui * * .dragStart() --> setup the dragging GUI * * .drag() -->called on mousemove if gui is drag object * * .dragStop() -->called on mouseup if gui is dragobject * * * ********************************************************************************* */ function AbstractGUI(id,theme,html) { this.id = id; this.x=0;this.y=0; this.type = 'gui'; //type used sometimes by guiManager this.theme = theme; this.content = html this.layer = new Array(); this.xOffset=new Array(0,0); this.yOffset=new Array(0,0); this.show = show; this.hide = hide; this.visible = false; this.close = aGUIclose; this.focus = aGUIfocus; this.blur = emptyFunction; this.parseXY = aGUIparseXY; this.setXY = setXY; this.makeLayer = makeLayer; this.drag=aGUIdrag; this.dragType=null; this.dragStop = aGUIdragStop; this.dragStart = aGUIdragStart; this.setBgColor = aGUIsetBgColor; this.guiManager = guiManager; } function aGUIparseXY() { this.guiManager.dragObject = this; this.dragStart(); } function aGUIsetBgColor(layerObject,themeReference) { if (ns) layerObject.bgColor=this.theme[themeReference]; else layerObject.backgroundColor=this.theme[themeReference]; } function emptyFunction() { } function aGUIfocus(z) { for(i=0;i2){ if(this.layer[2].document.forms.length>0){ this.layer[2].visibility="hidden"; this.setBgColor(this.layer[0],'bgColor'); } } this.dragGUI = this; } } function aGUIdragStop() { if((w3||ie) && this.dragType==0) { this.dragGUI.hide(); this.setXY(); this.focus(this.layer[0].zIndex); } if(ns) { if(this.layer.length>2){ if(this.layer[2].document.forms.length>0){ this.layer[2].visibility="visible"; this.setBgColor(this.layer[0],'border'); } } } //this.dragType=0; this.dragGUI = null; } function aGUIdrag() { this.x += this.guiManager.dx; this.y += this.guiManager.dy; if(this.x<0)this.x=0; if(this.y<0)this.y=0; if(w3||ie) guiManager.dragBox.setXY(this.x,this.y); else if(ns) this.setXY() } function show() { for(i=0;i2 &&i<7)) continue; this.layer[i].visibility="visible"; } guiManager.addObject(this); this.visible = true; } function hide(nokill) { for(i=0;i= 1) { this.setXY(ox+xdis,oy+ydis) this.x=ox+xdis;this.y=oy+ydis; this.isMoving=false; return } else{ this.setXY(ox +xdis*ratio,oy +ydis*ratio); wastedTime = (new Date()).getTime() - now; this.stack=setTimeout(this.id+'.iMove('+ox+','+oy+','+xdis+','+ydis+','+ms+','+FatherTime+')',20+ wastedTime); } } function Spritehide(){ for (i=0;i= 1) { this.layer[0].width = width; this.layer[0].height = height; this.clipW = width; this.clipH = height; this.x = this.x + xoff; this.y = this.y + yoff; this.xOffset[0]=0; this.yOffset[0]=0; this.setXY(); return; } this.layer[0].width = parseInt(this.clipW+(width-this.clipW)*ratio); this.layer[0].height = parseInt(this.clipH+(height-this.clipH)*ratio); this.yOffset[0] = parseInt(yoff*ratio); this.xOffset[0] = parseInt(xoff*ratio); this.setXY(); wastedTime = (new Date()).getTime()-now; setTimeout(this.id+".regrow("+fatherTime+","+ms+","+width+","+height+","+xoff+","+yoff+")",25+wastedTime); } // //---end box object //--------------------------------------------------- guiManager = new GuiManager("guiManager"); // init function initializes complile-time objects function pageOnResize() { if (ns) window.location.reload(); } function init() { guiManager.init(0,0) } // compile-time inits and variable declarations ns = document.layers; // 4.0 < ns < 6.0 ie = document.all; // for all internet explorers ie4 = ie; // ie4 only w3 = document.getElementById; // ie5 and ns6 w3 consortium DOM ns6 = false; ie5 = false; if (ie && w3) { ie5 = true; ie4 = false; } else if (w3) ns6 = true;