PageSourceSearch

https://www.planetreg.com/admin/windowfiles/dhtmlwindow.js

js planetreg.com collected 2026-09-25 18:18:48 UTC 19,611 bytes, 400 lines download raw bytes

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