// DynWindow Object // a widget-object that creates a draggable window with a Scroll2 to mimic an OS window // 19991007 // - Modified by Jordi Ministral // - Now you can resize the window by dragging itīs botton-right corner. // - Modified so that when you load an external file with a defined bgcolor, the window // actually changes to that background color // - Added setContent() method, which allows you to write contents into the window. You can specify // if you want to scroll back to the top of the document or not // - Option to set window to be 'Always on Top' when dragging // - Fixed a few bugs ( at least I dindn't like them ) regarding the ugly text selections when // scrolling windows. // - There were some events that were not behaving properly, too // - Optimized writings to the layers so they only are done when absolutely needed // - Added onBlur() and onFocus() methods. Not customizable ( but you can always rewrite them ) // // There has been a lot of work involved in the Scroll2, drag, dynlayer and mouseevents too. See there for details // // Copyright (C) 1999 Dan Steinman // Distributed under the terms of the GNU Library General Public License // Available at http://www.dansteinman.com/dynapi/ function DynWindow(x,y,width,height) { this.name = "DynWindow"+(DynWindow.count++) this.x = x this.y = y this.w = width this.h = height this.title = '' this.visibility = 'inherit' this.zIndex = null this.obj = this.name+"Object" eval(this.obj + "=this") this.content = null; this.mustRewrite = false; this.title = '' this.border = 6 this.titleH = 20 this.corner = 16 this.iconW = 20 this.separator = 1 this.OnTop = false this.content = ''; // Variables that can be set by the user 'before' building the widget ////////////////////////// this.bgtext = '#cdceff' // Titlebar's color this.text = 'white' // Color of the window's title this.bgcolor = 'black' // Background color this.useV = true // Not used anymore since addScroll() was introduced this.useH = false // Same for this one // I changed the events so they match the names I'm used to. Eventhough these can // be changed on the fly, If they are not set to something before building, the corresponding // icon won't appear. this.minclick = new Function() // What happens when the minimize icon is pressed this.minclickparameter = new Function() // This parameter will be passed to the above event this.closeclick = new Function() // What happens when the close icon is pressed. // Notice that by default the close icon DOESN'T close the window this.closeclickparameter = null // This parameter will be passed to the above event this.maxclick = new Function() // What happens when the maximize icon is pressed this.maxclickparameter = null // This parameter will be passed to the above event this.onLoad = DynWindowOnLoad // Use this to activate() everything when you load an external page this.loadEvent = new Function() // This event is called everytime the content in the window changes // It is caused by external loads() and SetContents() // Now you can have a menulist associated to the window which is toggled by pressing // the top-left icon in the window. Again it can be changed on the fly but if it is not set before // building, the icon won't be clicable this.winlist = null // Reference to the menulist object this.minW = 200 // When resizing a window, it won't go any smaller than these values this.minH = 100 // Someone might want to add max values as well. // To do so edit DynWindowDragUp() method // Methods to be called 'before' build() //////////////////////////////////////// this.addScroll = DynWindowAddScroll // These two behave as usual this.setImages = DynWindowSetImages // Methods usable all the time ////////////////////// this.alwaysOnTop = DynWindowAlwaysOnTop // Set the window to be Always on Top of other windows this.setTitle = DynWindowSetTitle // Changes title of window. Hasn't been changed this.show = DynWindowShow // Shows this.hide = DynWindowHide // Hides this.moveTo = DynWindowMoveTo // As usual this.moveBy = DynWindowMoveBy // As usual this.load = DynWindowLoad // Loads an external URL into the window this.setContent = DynWindowSetContent // Writes a dynamic content inside the window // Nothing usable behond this point. These methods are only for interal use ///////////////////////////////////// this.roll = DynWindowRoll this.onMinimize = new Function(this.obj+".minclick("+this.obj+".minclickparameter)"); this.onMaximize = new Function(this.obj+".maxclick("+this.obj+".maxclickparameter)"); this.onClose = new Function(this.obj+".closeclick("+this.obj+".closeclickparameter)"); this.winClick = DynWindowWinClick // Dragging and dropping events this.onDrag = DynWindowOnDrag; this.onDrop = DynWindowOnDrop; this.onScrollEnd = new Function(); this.blur = DynWindowBlur; this.focus = DynWindowFocus; // These events relate to the resizing this.dragOver = DynWindowDragOver this.dragOut = DynWindowDragOut this.dragDown = DynWindowDragDown this.dragUp = DynWindowDragUp this.resize = DynWindowResize // I'm doing this all the time anyway this.setImages('') // Last of all this.build = DynWindowBuild this.activate = DynWindowActivate } function DynWindowAlwaysOnTop(value) { this.onTop = value; if(this.lyr) this.lyr.bringTop = value; } function DynWindowWinClick() { if(this.winlist) if(!this.winlist.shown) { this.winlist.lyr.moveTo(this.lyr.x+this.border+1,this.lyr.y+this.border+this.titleH+2); this.winlist.show(); this.winlist.shown = true; this.winlist.lyr.css.zIndex = this.lyr.css.zIndex+1; if(this.scroll && this.scroll.window.hasForms) this.scroll.window.contentlyr.hide(); } } function DynWindowAddScroll(scrollbarW,useH) { this.hasScroll = true this.sbW = scrollbarW this.scroll = new Scroll(0,0,this.w-2*this.border-scrollbarW,this.h-2*this.border-this.titleH-1-(useH?scrollbarW:0)) if (useH) this.scroll.useH = true this.scroll.imgSet('',16,16,37,-1,2,-1,2,1,1) this.scroll.window.setMargins(5,5,5,5) this.scroll.onScrollEnd = new Function(this.obj+".onScrollEnd()"); } function DynWindowSetImages(dir) { this.imgDir = dir||"" this.min0 = new Image() this.min0.src = this.imgDir+"min0.gif" this.min1 = new Image() this.min1.src = this.imgDir+"min1.gif" this.max0 = new Image() this.max0.src = this.imgDir+"max0.gif" this.max1 = new Image() this.max1.src = this.imgDir+"max1.gif" this.close0 = new Image() this.close0.src = this.imgDir+"close0.gif" this.close1 = new Image() this.close1.src = this.imgDir+"close1.gif" this.icon = this.imgDir+"icon.gif" this.borderH = 'layer-background-image:URL('+this.imgDir+'border-h.gif); background-image:URL('+this.imgDir+'border-h.gif); repeat:yes;' this.borderV = 'layer-background-image:URL('+this.imgDir+'border-v.gif); background-image:URL('+this.imgDir+'border-v.gif); repeat:yes;' this.titleBG = 'layer-background-image:URL('+this.imgDir+'title-bg.gif); background-image:URL('+this.imgDir+'title-bg.gif); repeat:yes;' } function DynWindowBuild() { this.color = new Object() this.color.title = this.bgtext this.color.separator = this.bgcolor this.color.content = this.text if (this.hasScroll) this.scroll.build() this.titlebarW = this.w-2*this.border var n = this.name var b = this.border var c = this.corner this.css = css(n,this.x,this.y,this.w,this.h,null,this.visibility,this.zIndex)+ css(n+'TitleSep',b,this.border+this.titleH,this.titlebarW,this.separator,this.color.separator)+ css(n+'CornerTL',0,0,c,c)+ css(n+'CornerTR',this.w-c,0,c,c)+ css(n+'CornerBL',0,this.h-c,c,c)+ css(n+'CornerBR',this.w-c,this.h-c,c,c)+ css(n+'DragAnchor',this.w-c,this.h-c,30,30,null,'hidden')+ css(n+'Anchor',this.w-c,this.h-c,c,c,'#cdceff')+ css(n+'BorderT',c,0,this.w-2*c,b,null,null,null,this.borderH)+ css(n+'BorderB',c,this.h-b,this.w-2*c,b,null,null,null,this.borderH)+ css(n+'BorderL',0,c,b,this.h-2*c,null,null,null,this.borderV)+ css(n+'BorderR',this.w-b,c,b,this.h-2*c,null,null,null,this.borderV)+ css(n+'Titlebar',b,b,this.titlebarW,this.titleH,this.color.title)+ css(n+'Icon',0,0)+ css(n+'Title',this.iconW,0)+ css(n+'TitleBG',0,0,0,this.titleH)+ css(n+'Min',this.titlebarW-3*this.iconW,0,null,null,'#cdceff')+ css(n+'Max',this.titlebarW-2*this.iconW,0,null,null,'#cdceff')+ css(n+'Close',this.titlebarW-this.iconW,0,null,null,'#cdceff')+ css(n+'Content',b,b+this.titleH+this.separator,this.w-2*b,this.h-2*b-this.titleH-1,this.color.content) if (this.hasScroll) this.css += this.scroll.css this.divStart = '
\n'+ '
\n'+ '
\n'+ '
\n'+ '
\n'+ '
\n'+ '
 
\n'+ '
\n'+ '
\n'+ '
\n'+ '
\n'+ '
\n'+ '
\n'+ '
\n'+ '
\n'; if(this.minclick!=null) this.divStart += '
\n' if(this.maxclick!=null) this.divStart += '
\n' if(this.closeclick!=null) this.divStart += '
\n' this.divStart += '
\n'+ '
\n'+ '
' if (this.hasScroll) this.divStart += this.scroll.divStart this.divEnd = '' if (this.hasScroll) this.divEnd += this.scroll.divEnd this.divEnd += '
\n' this.div = this.divStart+'\n' } function DynWindowActivate() { this.lyr = new DynLayer(this.name) this.lyr.bringTop = this.onTop this.lyr.onClick=new Function(this.obj+".focus()"); this.lyr.onOtherClick=new Function(this.obj+".blur()"); this.titlelyr = new DynLayer(this.name+'Title') this.titlebarlyr = new DynLayer(this.name+'Titlebar') this.titlebarsep = new DynLayer(this.name+'TitleSep') this.titlebglyr = new DynLayer(this.name+'TitleBG') this.contentlyr = new DynLayer(this.name+'Content') this.anchorlyr = new DynLayer(this.name+'Anchor') this.draglyr = new DynLayer(this.name+'DragAnchor') this.lyrBT = new DynLayer(this.name+'BorderT') this.lyrBB = new DynLayer(this.name+'BorderB') this.lyrBL = new DynLayer(this.name+'BorderL') this.lyrBR = new DynLayer(this.name+'BorderR') this.lyrCBR = new DynLayer(this.name+'CornerBR') this.lyrCBL = new DynLayer(this.name+'CornerBL') this.lyrCTR = new DynLayer(this.name+'CornerTR') this.lyrCTL = new DynLayer(this.name+'CornerTL') this.setTitle(this.title) if(this.minclick!=null) this.minlyr = new DynLayer(this.name+'Min') if(this.maxclick!=null) this.maxlyr = new DynLayer(this.name+'Max') if(this.closeclick!=null) this.closelyr = new DynLayer(this.name+'Close') if (is.ns) this.anchorlyr.event.captureEvents(Event.MOUSEOVER) this.anchorlyr.elm.onmouseover = new Function(this.obj+'.dragOver(); return false;') if (is.ns) this.draglyr.event.captureEvents(Event.MOUSEOUT) this.draglyr.elm.onmouseout = new Function(this.obj+'.dragOut(); return false;') this.draglyr.onDrag = new Function(this.obj+'.dragDown()'); this.draglyr.onDrop = new Function(this.obj+'.dragUp()'); this.lyr.onDrag = new Function(this.obj+'.onDrag()'); this.lyr.onDrop = new Function(this.obj+'.onDrop()'); } function DynWindowSetTitle(title) { this.title = title this.titlelyr.write(''+this.title+'') var titlew = this.titlelyr.getContentWidth() this.titlebglyr.moveTo(titlew+this.iconW+5,0) this.titlebglyr.clipTo(0,this.titlebarW-this.iconW*4-titlew-7,this.titleH,0) } function DynWindowRoll(which,state) { if (state==1) { if (which=="min") status = "Minimize" else if (which=="max") status = "Maximize" else if (which=="close") status = "Close" } else status = "" eval('this.'+which+'lyr.doc.images["'+this.name+which+'Img"].src = this.'+which+state+'.src') } // Methods added by Jordi Ministral function DynWindowOnDrag() { if(this.scroll.lyr) { this.scroll.lyr.hide(); this.scroll.window.contentlyr.hide(); } this.anchorlyr.hide(); } function DynWindowOnDrop() { if(this.scroll.lyr) { this.scroll.lyr.show(); this.scroll.window.contentlyr.show(); } this.anchorlyr.show(); } function DynWindowBlur() { if(this.scroll && this.scroll.window.hasForms) this.scroll.window.contentlyr.hide(); if(this.winlist) { this.winlist.hide(); this.winlist.shown = false; } } function DynWindowFocus() { if(this.scroll && this.scroll.window.hasForms) this.scroll.window.contentlyr.show(); if(this.winlist) { this.winlist.hide(); this.winlist.shown = false; } } function DynWindowDragOver() { this.draglyr.moveTo(this.lyr.x+this.lyr.w-this.anchorlyr.w,this.lyr.y+this.lyr.h-this.anchorlyr.h+(is.ie?3:0)); this.draglyr.css.zIndex = this.lyr.css.zIndex + 1; eval('drag.add('+this.obj+'.draglyr)') this.draglyr.show(); } function DynWindowDragOut() { if(!this.resizing) { eval('drag.remove('+this.obj+'.draglyr)') this.draglyr.hide(); } } function DynWindowDragDown() { this.resizing = true // this.contentlyr.hide(); this.titlebglyr.hide(); this.anchorlyr.hide(); if(this.scroll.lyr) { this.scroll.lyr.hide(); this.scroll.window.contentlyr.hide(); } } function DynWindowDragUp() { var newW = this.draglyr.x - this.lyr.x; var newH = this.draglyr.y - this.lyr.y; this.resizing = false // this.contentlyr.show(); this.titlebglyr.show(); this.anchorlyr.show(); if(this.scroll.lyr) { this.scroll.lyr.show(); this.scroll.window.contentlyr.show(); } eval('drag.remove('+this.obj+'.draglyr)') this.draglyr.hide(); if(newW var referencia = parent; '+this.content); else this.scroll.setContent(this.content); this.mustRewrite = false; } function DynWindowHide() { this.visibility = 'hidden' this.lyr.hide() this.contentlyr.hide(); this.titlebglyr.hide(); this.anchorlyr.hide(); this.draglyr.hide(); if(this.scroll.lyr) this.scroll.lyr.hide(); if(this.scroll.window.contentlyr) this.scroll.window.contentlyr.hide(); eval('drag.remove('+this.obj+'.lyr)') } function DynWindowMoveTo(x,y) { this.lyr.moveTo(x,y) } function DynWindowMoveBy(x,y) { this.lyr.moveBy(x,y) } function DynWindowSetContent(cnt,gotop) { if(gotop!=true) gotop=false; this.content = cnt; if(this.visibility=='visible') { if(is.ie5) this.scroll.setContent('
Make your own free website on Tripod.com