1// ------------------------------------------------------------------- 2// DHTML Window Widget- By Dynamic Drive, available at: http://www.dynamicdrive.com 3// v1.0: Script created Feb 15th, 07' 4// v1.01: Feb 21th, 07' (see changelog.txt) 5// v1.02: March 26th, 07' (see changelog.txt) 6// v1.03: May 5th, 07' (see changelog.txt) 7// v1.1: Oct 29th, 07' (see changelog.txt) 8// ------------------------------------------------------------------- 9 10var dhtmlwindow={ 11imagefiles:['modalwindow/min.gif', 'modalwindow/close-button.png', 'modalwindow/restore.gif', 'modalwindow/resize.gif'], //Path to 4 images used by script, in that order 12ajaxbustcache: true, //Bust caching when fetching a file via Ajax? 13ajaxloadinghtml: '<b>Loading Page. Please wait...</b>', //HTML to show while window fetches Ajax Content? 14 15minimizeorder: 0, 16zIndexvalue:100, 17tobjects: [], //object to contain references to dhtml window divs, for cleanup purposes 18lastactivet: {}, //reference to last active DHTML window 19 20init:function(t){ 21 var domwindow=document.createElement("div") //create dhtml window div 22 domwindow.id=t 23 domwindow.className="dhtmlwindow" 24 var domwindowdata='' 25 domwindowdata='<div class="drag-handle">' 26 domwindowdata+='DHTML Window <div class="drag-controls"><img src="'+this.imagefiles[0]+'" title="Minimize" /><img class="drag-close" src="'+this.imagefiles[1]+'" title="Close Modal Window" alt="Close Modal Window" /></div>' 27 domwindowdata+='</div>' 28 domwindowdata+='<div class="drag-contentarea"></div>' 29 domwindowdata+='<div class="drag-statusarea"><div class="drag-resizearea" style="background: transparent url('+this.imagefiles[3]+') top right no-repeat;"> </div></div>' 30 domwindowdata+='</div>' 31 domwindow.innerHTML=domwindowdata 32 document.getElementById("dhtmlwindowholder").appendChild(domwindow) 33 //this.zIndexvalue=(this.zIndexvalue)? this.zIndexvalue+1 : 100 //z-index value for DHTML window: starts at 0, increments whenever a window has focus 34 var t=document.getElementById(t) 35 var divs=t.getElementsByTagName("div") 36 for (var i=0; i<divs.length; i++){ //go through divs inside dhtml window and extract all those with class="drag-" prefix 37 if (/drag-/.test(divs[i].className)) 38 t[divs[i].className.replace(/drag-/, "")]=divs[i] //take out the "drag-" prefix for shorter access by name 39 } 40 //t.style.zIndex=this.zIndexvalue //set z-index of this dhtml window 41 t.handle._parent=t //store back reference to dhtml window 42 t.resizearea._parent=t //same 43 t.controls._parent=t //same 44 t.onclose=function(){return true} //custom event handler "onclose" 45 t.onmousedown=function(){dhtmlwindow.setfocus(this)} //Increase z-index of window when focus is on it 46 t.handle.onmousedown=dhtmlwindow.setupdrag //set up drag behavior when mouse down on handle div 47 t.resizearea.onmousedown=dhtmlwindow.setupdrag //set up drag behavior when mouse down on resize div 48 t.controls.onclick=dhtmlwindow.enablecontrols 49 t.show=function(){dhtmlwindow.show(this)} //public function for showing dhtml window 50 t.hide=function(){dhtmlwindow.hide(this)} //public function for hiding dhtml window 51 t.close=function(){dhtmlwindow.close(this)} //public function for closing dhtml window (also empties DHTML window content) 52 t.setSize=function(w, h){dhtmlwindow.setSize(this, w, h)} //public function for setting window dimensions 53 t.moveTo=function(x, y){dhtmlwindow.moveTo(this, x, y)} //public function for moving dhtml window (relative to viewpoint) 54 t.isResize=function(bol){dhtmlwindow.isResize(this, bol)} //public function for specifying if window is resizable 55 t.isScrolling=function(bol){dhtmlwindow.isScrolling(this, bol)} //public function for specifying if window content contains scrollbars 56 t.load=function(contenttype, contentsource, title){dhtmlwindow.load(this, contenttype, contentsource, title)} //public function for loading content into window 57 this.tobjects[this.tobjects.length]=t 58 return t //return reference to dhtml window div 59}, 60 61open:function(t, contenttype, contentsource, title, attr, recalonload){ 62 var d=dhtmlwindow //reference dhtml window object 63 function getValue(Name){ 64 var config=new RegExp(Name+"=([^,]+)", "i") //get name/value config pair (ie: width=400px,) 65 return (config.test(attr))? parseInt(RegExp.$1) : 0 //return value portion (int), or 0 (false) if none found 66 } 67 if (document.getElementById(t)==null) //if window doesn't exist yet, create it 68 t=this.init(t) //return reference to dhtml window div 69 else 70 t=document.getElementById(t) 71 this.setfocus(t) 72 t.setSize(getValue(("width")), (getValue("height"))) //Set dimensions of window 73 var xpos=getValue("center")? "middle" : getValue("left") //Get x coord of window 74 var ypos=getValue("center")? "middle" : getValue("top") //Get y coord of window 75 //t.moveTo(xpos, ypos) //Position window 76 if (typeof recalonload!="undefined" && recalonload=="recal" && this.scroll_top==0){ //reposition window when page fully loads with updated window viewpoints? 77 if (window.attachEvent && !window.opera) //In IE, add another 400 milisecs on page load (viewpoint properties may return 0 b4 then) 78 this.addEvent(window, function(){setTimeout(function(){t.moveTo(xpos, ypos)}, 400)}, "load") 79 else 80 this.addEvent(window, function(){t.moveTo(xpos, ypos)}, "load") 81 } 82 t.isResize(getValue("resize")) //Set whether window is resizable 83 t.isScrolling(getValue("scrolling")) //Set whether window should contain scrollbars 84 t.style.visibility="visible" 85 t.style.display="block" 86 t.contentarea.style.display="block" 87 t.moveTo(xpos, ypos) //Position window 88 t.load(contenttype, contentsource, title) 89 if (t.state=="minimized" && t.controls.firstChild.title=="Restore"){ //If window exists and is currently minimized? 90 t.controls.firstChild.setAttribute("src", dhtmlwindow.imagefiles[0]) //Change "restore" icon within window interface to "minimize" icon 91 t.controls.firstChild.setAttribute("title", "Minimize") 92 t.state="fullview" //indicate the state of the window as being "fullview" 93 } 94 return t 95}, 96 97setSize:function(t, w, h){ //set window size (min is 150px wide by 100px tall) 98 //alert(w); 99 if(w==1 && h==1){ 100 t.style.width="90%"; 101 t.style.height="90%"; 102 t.contentarea.style.height=Math.max(parseInt(h), 92)+"%"; 103 } else if(w==90 && h==90){ 104 t.style.width="90%"; 105 t.style.height="90%"; 106 t.contentarea.style.height=Math.max(parseInt(h), 92)+"%"; 107 } else if(w==80 && h==80){ 108 t.style.width="80%"; 109 t.style.height="80%"; 110 t.contentarea.style.height=Math.max(parseInt(h), 92)+"%"; 111 } else if(w==85 && h==85){ 112 t.style.width="85%"; 113 t.style.height="85%"; 114 t.contentarea.style.height=Math.max(parseInt(h), 92)+"%"; 115 } else if(w==70 && h==70){ 116 t.style.width="70%"; 117 t.style.height="70%"; 118 t.contentarea.style.height=Math.max(parseInt(h), 92)+"%"; 119 } else { 120 t.style.width=Math.max(parseInt(w), 150)+"px"; 121 t.contentarea.style.height=Math.max(parseInt(h), 100)+"px"; 122 } 123 //alert(t.style.width); 124 //alert(t.contentarea.style.height); 125}, 126 127moveTo:function(t, x, y){ //move window. Position includes current viewpoint of document 128 this.getviewpoint() //Get current viewpoint numbers 129 t.style.left=(x=="middle")? this.scroll_left+(this.docwidth-t.offsetWidth)/2+"px" : this.scroll_left+parseInt(x)+"px" 130 t.style.top=(y=="middle")? this.scroll_top+(this.docheight-t.offsetHeight)/2+"px" : this.scroll_top+parseInt(y)+"px" 131}, 132 133isResize:function(t, bol){ //show or hide resize inteface (part of the status bar) 134 t.statusarea.style.display=(bol)? "block" : "none" 135 t.resizeBool=(bol)? 1 : 0 136}, 137 138isScrolling:function(t, bol){ //set whether loaded content contains scrollbars 139 t.contentarea.style.overflow=(bol)? "auto" : "hidden" 140}, 141 142load:function(t, contenttype, contentsource, title){ //loads content into window plus set its title (3 content types: "inline", "iframe", or "ajax") 143 if (t.isClosed){ 144 alert("DHTML Window has been closed, so no window to load contents into. Open/Create the window again.") 145 return 146 } 147 var contenttype=contenttype.toLowerCase() //convert string to lower case 148 if (typeof title!="undefined") 149 t.handle.firstChild.nodeValue=title 150 if (contenttype=="inline") 151 t.contentarea.innerHTML=contentsource 152 else if (contenttype=="div"){ 153 var inlinedivref=document.getElementById(contentsource) 154 t.contentarea.innerHTML=(inlinedivref.defaultHTML || inlinedivref.innerHTML) //Populate window with contents of inline div on page 155 if (!inlinedivref.defaultHTML) 156 inlinedivref.defaultHTML=inlinedivref.innerHTML //save HTML within inline DIV 157 inlinedivref.innerHTML="" //then, remove HTML within inline DIV (to prevent duplicate IDs, NAME attributes etc in contents of DHTML window 158 inlinedivref.style.display="none" //hide that div 159 } 160 else if (contenttype=="iframe"){ 161 t.contentarea.style.overflow="hidden" //disable window scrollbars, as iframe already contains scrollbars 162 if (!t.contentarea.firstChild || t.contentarea.firstChild.tagName!="IFRAME") //If iframe tag doesn't exist already, create it first 163 t.contentarea.innerHTML='<iframe src="" style="margin:0; padding:0; width:100%; height: 100%" name="_iframe-'+t.id+'"></iframe>' 164 window.frames["_iframe-"+t.id].location.replace(contentsource) //set location of iframe window to specified URL 165 } 166 else if (contenttype=="ajax"){ 167 this.ajax_connect(contentsource, t) //populate window with external
167contents fetched via Ajax 168 } 169 t.contentarea.datatype=contenttype //store contenttype of current window for future reference 170}, 171 172setupdrag:function(e){ 173 var d=dhtmlwindow //reference dhtml window object 174 var t=this._parent //reference dhtml window div 175 d.etarget=this //remember div mouse is currently held down on ("handle" or "resize" div) 176 var e=window.event || e 177 d.initmousex=e.clientX //store x position of mouse onmousedown 178 d.initmousey=e.clientY 179 d.initx=parseInt(t.offsetLeft) //store offset x of window div onmousedown 180 d.inity=parseInt(t.offsetTop) 181 d.width=parseInt(t.offsetWidth) //store width of window div 182 d.contentheight=parseInt(t.contentarea.offsetHeight) //store height of window div's content div 183 if (t.contentarea.datatype=="iframe"){ //if content of this window div is "iframe" 184 t.style.backgroundColor="#F8F8F8" //colorize and hide content div (while window is being dragged) 185 t.contentarea.style.visibility="hidden" 186 } 187 document.onmousemove=d.getdistance //get distance travelled by mouse as it moves 188 document.onmouseup=function(){ 189 if (t.contentarea.datatype=="iframe"){ //restore color and visibility of content div onmouseup 190 t.contentarea.style.backgroundColor="white" 191 t.contentarea.style.visibility="visible" 192 } 193 d.stop() 194 } 195 return false 196}, 197 198getdistance:function(e){ 199 var d=dhtmlwindow 200 var etarget=d.etarget 201 var e=window.event || e 202 d.distancex=e.clientX-d.initmousex //horizontal distance travelled relative to starting point 203 d.distancey=e.clientY-d.initmousey 204 if (etarget.className=="drag-handle") //if target element is "handle" div 205 d.move(etarget._parent, e) 206 else if (etarget.className=="drag-resizearea") //if target element is "resize" div 207 d.resize(etarget._parent, e) 208 return false //cancel default dragging behavior 209}, 210 211getviewpoint:function(){ //get window viewpoint numbers 212 var ie=document.all && !window.opera 213 var domclientWidth=document.documentElement && parseInt(document.documentElement.clientWidth) || 100000 //Preliminary doc width in non IE browsers 214 this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes 215 this.scroll_top=(ie)? this.standardbody.scrollTop : window.pageYOffset 216 this.scroll_left=(ie)? this.standardbody.scrollLeft : window.pageXOffset 217 this.docwidth=(ie)? this.standardbody.clientWidth : (/Safari/i.test(navigator.userAgent))? window.innerWidth : Math.min(domclientWidth, window.innerWidth-16) 218 this.docheight=(ie)? this.standardbody.clientHeight: window.innerHeight 219}, 220 221rememberattrs:function(t){ //remember certain attributes of the window when it's minimized or closed, such as dimensions, position on page 222 this.getviewpoint() //Get current window viewpoint numbers 223 t.lastx=parseInt((t.style.left || t.offsetLeft))-dhtmlwindow.scroll_left //store last known x coord of window just before minimizing 224 t.lasty=parseInt((t.style.top || t.offsetTop))-dhtmlwindow.scroll_top 225 t.lastwidth=parseInt(t.style.width) //store last known width of window just before minimizing/ closing 226}, 227 228move:function(t, e){ 229 t.style.left=dhtmlwindow.distancex+dhtmlwindow.initx+"px" 230 t.style.top=dhtmlwindow.distancey+dhtmlwindow.inity+"px" 231}, 232 233resize:function(t, e){ 234 t.style.width=Math.max(dhtmlwindow.width+dhtmlwindow.distancex, 150)+"px" 235 t.contentarea.style.height=Math.max(dhtmlwindow.contentheight+dhtmlwindow.distancey, 100)+"px" 236}, 237 238enablecontrols:function(e){ 239 var d=dhtmlwindow 240 var sourceobj=window.event? window.event.srcElement : e.target //Get element within "handle" div mouse is currently on (the controls) 241 if (/Minimize/i.test(sourceobj.getAttribute("title"))) //if this is the "minimize" control 242 d.minimize(sourceobj, this._parent) 243 else if (/Restore/i.test(sourceobj.getAttribute("title"))) //if this is the "restore" control 244 d.restore(sourceobj, this._parent) 245 else if (/Close/i.test(sourceobj.getAttribute("title"))) //if this is the "close" control 246 d.close(this._parent) 247 return false 248}, 249 250minimize:function(button, t){ 251 dhtmlwindow.rememberattrs(t) 252 button.setAttribute("src", dhtmlwindow.imagefiles[2]) 253 button.setAttribute("title", "Restore") 254 t.state="minimized" //indicate the state of the window as being "minimized" 255 t.contentarea.style.display="none" 256 t.statusarea.style.display="none" 257 if (typeof t.minimizeorder=="undefined"){ //stack order of minmized window on screen relative to any other minimized windows 258 dhtmlwindow.minimizeorder++ //increment order 259 t.minimizeorder=dhtmlwindow.minimizeorder 260 } 261 t.style.left="10px" //left coord of minmized window 262 t.style.width="200px" 263 var windowspacing=t.minimizeorder*10 //spacing (gap) between each minmized window(s) 264 t.style.top=dhtmlwindow.scroll_top+dhtmlwindow.docheight-(t.handle.offsetHeight*t.minimizeorder)-windowspacing+"px" 265}, 266 267restore:function(button, t){ 268 dhtmlwindow.getviewpoint() 269 button.setAttribute("src", dhtmlwindow.imagefiles[0]) 270 button.setAttribute("title", "Minimize") 271 t.state="fullview" //indicate the state of the window as being "fullview" 272 t.style.display="block" 273 t.contentarea.style.display="block" 274 if (t.resizeBool) //if this window is resizable, enable the resize icon 275 t.statusarea.style.display="block" 276 t.style.left=parseInt(t.lastx)+dhtmlwindow.scroll_left+"px" //position window to last known x coord just before minimizing 277 t.style.top=parseInt(t.lasty)+dhtmlwindow.scroll_top+"px" 278 t.style.width=parseInt(t.lastwidth)+"px" 279}, 280 281 282close:function(t){ 283 try{ 284 var closewinbol=t.onclose() 285 } 286 catch(err){ //In non IE browsers, all errors are caught, so just run the below 287 var closewinbol=true 288 } 289 finally{ //In IE, not all errors are caught, so check if variable isn't defined in IE in those cases 290 if (typeof closewinbol=="undefined"){ 291 alert("An error has occured somwhere inside your \"onclose\" event handler") 292 var closewinbol=true 293 } 294 } 295 if (closewinbol){ //if custom event handler function returns true 296 if (t.state!="minimized") //if this window isn't currently minimized 297 dhtmlwindow.rememberattrs(t) //remember window's dimensions/position on the page before closing 298 if (window.frames["_iframe-"+t.id]) //if this is an IFRAME DHTML window 299 window.frames["_iframe-"+t.id].location.replace("about:blank") 300 else 301 t.contentarea.innerHTML="" 302 t.style.display="none" 303 t.isClosed=true //tell script this window is closed (for detection in t.show()) 304 } 305 return closewinbol 306}, 307 308 309setopacity:function(targetobject, value){ //Sets the opacity of targetobject based on the passed in value setting (0 to 1 and in between) 310 if (!targetobject) 311 return 312 if (targetobject.filters && targetobject.filters[0]){ //IE syntax 313 if (typeof targetobject.filters[0].opacity=="number") //IE6 314 targetobject.filters[0].opacity=value*100 315 else //IE 5.5 316 targetobject.style.filter="alpha(opacity="+value*100+")" 317 } 318 else if (typeof targetobject.style.MozOpacity!="undefined") //Old Mozilla syntax 319 targetobject.style.MozOpacity=value 320 else if (typeof targetobject.style.opacity!="undefined") //Standard opacity syntax 321 targetobject.style.opacity=value 322}, 323 324setfocus:function(t){ //Sets focus to the currently active window 325 this.zIndexvalue++ 326 t.style.zIndex=this.zIndexvalue 327 t.isClosed=false //tell script this window isn't closed (for detection in t.show()) 328 this.setopacity(this.lastactivet.handle, 0.5) //unfocus last active window 329 this.setopacity(t.handle, 1) //focus currently active window 330 this.lastactivet=t //remember last active window 331}, 332 333 334show:function(t){ 335 if (t.isClosed){ 336 alert("DHTML Window has been closed, so nothing to show. Open/Create the window again.") 337 return 338 } 339 if (t.lastx) //If there exists previously stored information such as last x position on window attributes (meaning it's been minimized or closed) 340 dhtmlwindow.restore(t.controls.firstChild, t) //restore the window using that info 341 else 342 t.style.display="block" 343 this.setfocus(t) 344 t.state="fullview" //indicate the state of the window as being "fullview" 345}, 346 347hide:function(t){ 348 t.style.display="none" 349}, 350 351ajax_connect:function(url, t){ 352 var page_request = false 353 var bustcacheparameter="" 354 if (window.XMLHttpRequest) // if Mozilla, IE7, Safari etc 355 page_request = new XMLHttpRequest() 356 else if (window.ActiveXObject){ // if IE6 or below 357 try { 358 page_request = new ActiveXObject("Msxml2.XMLHTTP") 359 } 360 catch (e){ 361 try{ 362 page_request = new ActiveXObject("Microsoft.XMLHTTP") 363 } 364 catch (e){} 365 } 366 } 367 else 368 return false 369 t.contentarea.innerHTML=this.ajaxloadinghtml 370 page_request.onreadystatechange=function(){dhtmlwindow.ajax_loadpage(page_request, t)} 371 if (this.ajaxbustcache) //if bust caching of external page 372 bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime() 373 page_request.open('GET', url+bustcacheparameter, true) 374 page_request.send(null) 375}, 376 377ajax_loadpage:function(page_request, t){ 378 if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){ 379 t.contentarea.innerHTML=page_request.responseText 380 } 381}, 382 383 384stop:function(){ 385 dhtmlwindow.etarget=null //clean up 386 document.onmousemove=null 387 document.onmouseup=null 388}, 389 390addEvent:function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload) 391 var tasktype=(window.addEventListener)? tasktype : "on"+tasktype 392 if (target.addEventListener) 393 target.addEventListener(tasktype, functionref, false) 394 else if (target.attachEvent) 395 target.attachEvent(tasktype, functionref) 396}, 397 398cleanup:function(){ 399 for (var i=0; i<dhtmlwindow.tobjects.length; i++){ 400 dhtmlwindow.tobjects[i].handle._parent=dhtmlwindow.tobjects[i].resizearea._parent=dhtmlwindow.tobjects[i].controls._parent=null 401 } 402 window.onload=null 403} 404 405} //End dhtmlwindow object 406
407document.write('<div id="dhtmlwindowholder"><span style="display:none">.</span></div>') //container that holds all dhtml window divs on page 408window.onunload=dhtmlwindow.cleanup
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.