PageSourceSearch

https://dhsprogram.com/js/dhtmlwindow.js

js dhsprogram.com collected 2026-09-24 08:31:44 UTC 18,703 bytes, 383 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', '/assets/images/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?
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 src="'+this.imagefiles[1]+'" title="Close" /></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;">&nbsp;</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 
43	t.controls._parent=t 
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	t.style.width=Math.max(parseInt(w), 150)+"px"
99	t.contentarea.style.height=Math.max(parseInt(h), 100)+"px"
100},
101
102moveTo:function(t, x, y){ //move window. Position includes current viewpoint of document
103	this.getviewpoint() //Get current viewpoint numbers
104	t.style.left=(x=="middle")? this.scroll_left+(this.docwidth-t.offsetWidth)/2+"px" : this.scroll_left+parseInt(x)+"px"
105	t.style.top=(y=="middle")? this.scroll_top+(this.docheight-t.offsetHeight)/2+"px" : this.scroll_top+parseInt(y)+"px"
106},
107
108isResize:function(t, bol){ //show or hide resize inteface (part of the status bar)
109	t.statusarea.style.display=(bol)? "block" : "none"
110	t.resizeBool=(bol)? 1 : 0
111},
112
113isScrolling:function(t, bol){ //set whether loaded content contains scrollbars
114	t.contentarea.style.overflow=(bol)? "auto" : "hidden"
115},
116
117load:function(t, contenttype, contentsource, title){ //loads content into window plus set its title (3 content types: "inline", "iframe", or "ajax")
118	if (t.isClosed){
119		alert("DHTML Window has been closed, so no window to load contents into. Open/Create the window again.")
120		return
121	}
122	var contenttype=contenttype.toLowerCase() //convert string to lower case
123	if (typeof title!="undefined")
124		t.handle.firstChild.nodeValue=title
125	if (contenttype=="inline")
126		t.contentarea.innerHTML=contentsource
127	else if (contenttype=="div"){
128		var inlinedivref=document.getElementById(contentsource)
129		t.contentarea.innerHTML=(inlinedivref.defaultHTML || inlinedivref.innerHTML) //Populate window with contents of inline div on page
130		if (!inlinedivref.defaultHTML)
131			inlinedivref.defaultHTML=inlinedivref.innerHTML //save HTML within inline DIV
132		inlinedivref.innerHTML="" //then, remove HTML within inline DIV (to prevent duplicate IDs, NAME attributes etc in contents of DHTML window
133		inlinedivref.style.display="none" //hide that div
134	}
135	else if (contenttype=="iframe"){
136		t.contentarea.style.overflow="hidden" //disable window scrollbars, as iframe already contains scrollbars
137		if (!t.contentarea.firstChild || t.contentarea.firstChild.tagName!="IFRAME") //If iframe tag doesn't exist already, create it first
138			t.contentarea.innerHTML='<iframe src="" style="margin:0; padding:0; width:100%; height: 100%" name="_iframe-'+t.id+'"></iframe>'
139		window.frames["_iframe-"+t.id].location.replace(contentsource) //set location of iframe window to specified URL
140		}
141	else if (contenttype=="ajax"){
142		this.ajax_connect(contentsource, t) //populate window with external 
142contents fetched via Ajax
143	}
144	t.contentarea.datatype=contenttype //store contenttype of current window for future reference
145},
146
147setupdrag:function(e){
148	var d=dhtmlwindow //reference dhtml window object
149	var t=this._parent //reference dhtml window div
150	d.etarget=this //remember div mouse is currently held down on ("handle" or "resize" div)
151	var e=window.event || e
152	d.initmousex=e.clientX //store x position of mouse onmousedown
153	d.initmousey=e.clientY
154	d.initx=parseInt(t.offsetLeft) //store offset x of window div onmousedown
155	d.inity=parseInt(t.offsetTop)
156	d.width=parseInt(t.offsetWidth) //store width of window div
157	d.contentheight=parseInt(t.contentarea.offsetHeight) //store height of window div's content div
158	if (t.contentarea.datatype=="iframe"){ //if content of this window div is "iframe"
159		t.style.backgroundColor="#F8F8F8" //colorize and hide content div (while window is being dragged)
160		t.contentarea.style.visibility="hidden"
161	}
162	document.onmousemove=d.getdistance //get distance travelled by mouse as it moves
163	document.onmouseup=function(){
164		if (t.contentarea.datatype=="iframe"){ //restore color and visibility of content div onmouseup
165			t.contentarea.style.backgroundColor="white"
166			t.contentarea.style.visibility="visible"
167		}
168		d.stop()
169	}
170	return false
171},
172
173getdistance:function(e){
174	var d=dhtmlwindow
175	var etarget=d.etarget
176	var e=window.event || e
177	d.distancex=e.clientX-d.initmousex //horizontal distance travelled relative to starting point
178	d.distancey=e.clientY-d.initmousey
179	if (etarget.className=="drag-handle") //if target element is "handle" div
180		d.move(etarget._parent, e)
181	else if (etarget.className=="drag-resizearea") //if target element is "resize" div
182		d.resize(etarget._parent, e)
183	return false //cancel default dragging behavior
184},
185
186getviewpoint:function(){ //get window viewpoint numbers
187	var ie=document.all && !window.opera
188	var domclientWidth=document.documentElement && parseInt(document.documentElement.clientWidth) || 100000 //Preliminary doc width in non IE browsers
189	this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
190	this.scroll_top=(ie)? this.standardbody.scrollTop : window.pageYOffset
191	this.scroll_left=(ie)? this.standardbody.scrollLeft : window.pageXOffset
192	this.docwidth=(ie)? this.standardbody.clientWidth : (/Safari/i.test(navigator.userAgent))? window.innerWidth : Math.min(domclientWidth, window.innerWidth-16)
193	this.docheight=(ie)? this.standardbody.clientHeight: window.innerHeight
194},
195
196rememberattrs:function(t){ //remember certain attributes of the window when it's minimized or closed, such as dimensions, position on page
197	this.getviewpoint() //Get current window viewpoint numbers
198	t.lastx=parseInt((t.style.left || t.offsetLeft))-dhtmlwindow.scroll_left //store last known x coord of window just before minimizing
199	t.lasty=parseInt((t.style.top || t.offsetTop))-dhtmlwindow.scroll_top
200	t.lastwidth=parseInt(t.style.width) //store last known width of window just before minimizing/ closing
201},
202
203move:function(t, e){
204	t.style.left=dhtmlwindow.distancex+dhtmlwindow.initx+"px"
205	t.style.top=dhtmlwindow.distancey+dhtmlwindow.inity+"px"
206},
207
208resize:function(t, e){
209	t.style.width=Math.max(dhtmlwindow.width+dhtmlwindow.distancex, 150)+"px"
210	t.contentarea.style.height=Math.max(dhtmlwindow.contentheight+dhtmlwindow.distancey, 100)+"px"
211},
212
213enablecontrols:function(e){
214	var d=dhtmlwindow
215	var sourceobj=window.event? window.event.srcElement : e.target //Get element within "handle" div mouse is currently on (the controls)
216	if (/Minimize/i.test(sourceobj.getAttribute("title"))) //if this is the "minimize" control
217		d.minimize(sourceobj, this._parent)
218	else if (/Restore/i.test(sourceobj.getAttribute("title"))) //if this is the "restore" control
219		d.restore(sourceobj, this._parent)
220	else if (/Close/i.test(sourceobj.getAttribute("title"))) //if this is the "close" control
221		d.close(this._parent)
222	return false
223},
224
225minimize:function(button, t){
226	dhtmlwindow.rememberattrs(t)
227	button.setAttribute("src", dhtmlwindow.imagefiles[2])
228	button.setAttribute("title", "Restore")
229	t.state="minimized" //indicate the state of the window as being "minimized"
230	t.contentarea.style.display="none"
231	t.statusarea.style.display="none"
232	if (typeof t.minimizeorder=="undefined"){ //stack order of minmized window on screen relative to any other minimized windows
233		dhtmlwindow.minimizeorder++ //increment order
234		t.minimizeorder=dhtmlwindow.minimizeorder
235	}
236	t.style.left="10px" //left coord of minmized window
237	t.style.width="200px"
238	var windowspacing=t.minimizeorder*10 //spacing (gap) between each minmized window(s)
239	t.style.top=dhtmlwindow.scroll_top+dhtmlwindow.docheight-(t.handle.offsetHeight*t.minimizeorder)-windowspacing+"px"
240},
241
242restore:function(button, t){
243	dhtmlwindow.getviewpoint()
244	button.setAttribute("src", dhtmlwindow.imagefiles[0])
245	button.setAttribute("title", "Minimize")
246	t.state="fullview" //indicate the state of the window as being "fullview"
247	t.style.display="block"
248	t.contentarea.style.display="block"
249	if (t.resizeBool) //if this window is resizable, enable the resize icon
250		t.statusarea.style.display="block"
251	t.style.left=parseInt(t.lastx)+dhtmlwindow.scroll_left+"px" //position window to last known x coord just before minimizing
252	t.style.top=parseInt(t.lasty)+dhtmlwindow.scroll_top+"px"
253	t.style.width=parseInt(t.lastwidth)+"px"
254},
255
256
257close:function(t){
258	try{
259		var closewinbol=t.onclose()
260	}
261	catch(err){ //In non IE browsers, all errors are caught, so just run the below
262		var closewinbol=true
263 }
264	finally{ //In IE, not all errors are caught, so check if variable isn't defined in IE in those cases
265		if (typeof closewinbol=="undefined"){
266			alert("An error has occured somwhere inside your \"onclose\" event handler")
267			var closewinbol=true
268		}
269	}
270	if (closewinbol){ //if custom event handler function returns true
271		if (t.state!="minimized") //if this window isn't currently minimized
272			dhtmlwindow.rememberattrs(t) //remember window's dimensions/position on the page before closing
273		if (window.frames["_iframe-"+t.id]) //if this is an IFRAME DHTML window
274			window.frames["_iframe-"+t.id].location.replace("about:blank")
275		else
276			t.contentarea.innerHTML=""
277		t.style.display="none"
278		t.isClosed=true //tell script this window is closed (for detection in t.show())
279	}
280	return closewinbol
281},
282
283
284setopacity:function(targetobject, value){ //Sets the opacity of targetobject based on the passed in value setting (0 to 1 and in between)
285	if (!targetobject)
286		return
287	if (targetobject.filters && targetobject.filters[0]){ //IE syntax
288		if (typeof targetobject.filters[0].opacity=="number") //IE6
289			targetobject.filters[0].opacity=value*100
290		else //IE 5.5
291			targetobject.style.filter="alpha(opacity="+value*100+")"
292		}
293	else if (typeof targetobject.style.MozOpacity!="undefined") //Old Mozilla syntax
294		targetobject.style.MozOpacity=value
295	else if (typeof targetobject.style.opacity!="undefined") //Standard opacity syntax
296		targetobject.style.opacity=value
297},
298
299setfocus:function(t){ //Sets focus to the currently active window
300	this.zIndexvalue++
301	t.style.zIndex=this.zIndexvalue
302	t.isClosed=false //tell script this window isn't closed (for detection in t.show())
303	this.setopacity(this.lastactivet.handle, 0.5) //unfocus last active window
304	this.setopacity(t.handle, 1) //focus currently active window
305	this.lastactivet=t //remember last active window
306},
307
308
309show:function(t){
310	if (t.isClosed){
311		alert("DHTML Window has been closed, so nothing to show. Open/Create the window again.")
312		return
313	}
314	if (t.lastx) //If there exists previously stored information such as last x position on window attributes (meaning it's been minimized or closed)
315		dhtmlwindow.restore(t.controls.firstChild, t) //restore the window using that info
316	else
317		t.style.display="block"
318	this.setfocus(t)
319	t.state="fullview" //indicate the state of the window as being "fullview"
320},
321
322hide:function(t){
323	t.style.display="none"
324},
325
326ajax_connect:function(url, t){
327	var page_request = false
328	var bustcacheparameter=""
329	if (window.XMLHttpRequest) // if Mozilla, IE7, Safari etc
330		page_request = new XMLHttpRequest()
331	else if (window.ActiveXObject){ // if IE6 or below
332		try {
333		page_request = new ActiveXObject("Msxml2.XMLHTTP")
334		} 
335		catch (e){
336			try{
337			page_request = new ActiveXObject("Microsoft.XMLHTTP")
338			}
339			catch (e){}
340		}
341	}
342	else
343		return false
344	t.contentarea.innerHTML=this.ajaxloadinghtml
345	page_request.onreadystatechange=function(){dhtmlwindow.ajax_loadpage(page_request, t)}
346	if (this.ajaxbustcache) //if bust caching of external page
347		bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
348	page_request.open('GET', url+bustcacheparameter, true)
349	page_request.send(null)
350},
351
352ajax_loadpage:function(page_request, t){
353	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
354	t.contentarea.innerHTML=page_request.responseText
355	}
356},
357
358
359stop:function(){
360	dhtmlwindow.etarget=null //clean up
361	document.onmousemove=null
362	document.onmouseup=null
363},
364
365addEvent:function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
366	var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
367	if (target.addEventListener)
368		target.addEventListener(tasktype, functionref, false)
369	else if (target.attachEvent)
370		target.attachEvent(tasktype, functionref)
371},
372
373cleanup:function(){
374	for (var i=0; i<dhtmlwindow.tobjects.length; i++){
375		dhtmlwindow.tobjects[i].handle._parent=dhtmlwindow.tobjects[i].resizearea._parent=dhtmlwindow.tobjects[i].controls._parent=null
376	}
377	window.onload=null
378}
379
380} //End dhtmlwindow object
381
382document.write('<div id="dhtmlwindowholder"><span style="display:none">.</span></div>') //container that holds all dhtml window divs on page
383window.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.