PDA

View Full Version : DHTML window: any way to prevent positioning outside window?



marmachine
05-19-2014, 11:13 AM
DHTML Window widget
http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/index.htm

Issue:
I'm currently implementing the script on a multifunctionctional backoffice system with a large menu structure.
Since i want to keep the main page as a desktop with an overview, i'm opening all menu items/programs inside a DHTML Window, which is a great functionality... especially because it allows multiple floating panels, users feel familiar since it is like working in a "windows-like" environment.

However i have one problem rising here... opening a new Window inside a smaller browser window will place the controlbar outside the browser, also users dragging the windows outside the browserwindow will cause similar effect, causing the window to be unreachable. With the controlbar outside the window, users will never be able to reach it in order to move it back inside the window.

However i'm aware of the positioning function onclick="inlinewin.moveTo(400, 200); i would rather prefer to prevent moving outside in the first place, which actually might even be a nice additional setting to the script!?
Anyway, is there any way to prevent dragging a window to positions outside the browserwindow? Any help or ideas will be appreciated!

Many thanks
Marco

ddadmin
05-26-2014, 12:50 AM
Hey Marco:
You can try setting up some constraints inside the move() function to bound each DHTML window's draggable area to within the current viewpoint. Try replacing the following code inside the .js file:


move:function(t, e){
t.style.left=dhtmlwindow.distancex+dhtmlwindow.initx+"px"
t.style.top=dhtmlwindow.distancey+dhtmlwindow.inity+"px"
},


to:


move:function(t, e){
var d=dhtmlwindow //reference dhtml window object
var winleft = dhtmlwindow.distancex+dhtmlwindow.initx
var wintop = dhtmlwindow.distancey+dhtmlwindow.inity
var scroll_top=(document.all)? this.standardbody.scrollTop : window.pageYOffset
var scroll_left=(document.all)? this.standardbody.scrollLeft : window.pageXOffset
if ( winleft > scroll_left-10 && (winleft + d.width - 10) < scroll_left + this.docwidth){
t.style.left=winleft+"px"
}
if ( wintop > scroll_top && (wintop + t.offsetHeight) < scroll_top + this.docheight){
t.style.top=wintop+"px"
}
},

marmachine
07-17-2014, 07:53 AM
Super duper... this seems to work perfectly! Many many thanks man! cheers

marmachine
07-18-2014, 07:30 AM
I have one other issue:
To give the window a more "windows like" behaviour i think it would be nice to activate (set focus) the window by clicking inside it. Currently you can open multiple windows, the first opened will loose focus while the second goes on top. In order to switch between both windows you can now only click the top bar, clicking elsewhere inside it's window area doesn't do the same thing. Is there a way, maybe simply by adding an onclick behaviour?

Thanks, Marco.