includes/clientside/static/windows.js
changeset 1227 bdac73ed481e
parent 420 301f546688d1
equal deleted inserted replaced
1226:de56132c008d 1227:bdac73ed481e
     3  * Sorry if I stole the name ;)
     3  * Sorry if I stole the name ;)
     4  * Copyright (C) 2006-2007 Dan Fuhry
     4  * Copyright (C) 2006-2007 Dan Fuhry
     5  * Yes, it's part of Enano, so it's GPL
     5  * Yes, it's part of Enano, so it's GPL
     6  */
     6  */
     7 
     7 
     8   var position;
     8 	var position;
     9   position = getScrollOffset();
     9 	position = getScrollOffset();
    10   
    10 	
    11   var jws = {
    11 	var jws = {
    12     position : position,
    12 		position : position,
    13     obj : null,
    13 		obj : null,
    14     startup : function() {
    14 		startup : function() {
    15       jws.debug('jws.startup()');
    15 			jws.debug('jws.startup()');
    16       var divs = document.getElementsByTagName('div');
    16 			var divs = document.getElementsByTagName('div');
    17       if(IE) { position = document.body.scrollTop; }
    17 			if(IE) { position = document.body.scrollTop; }
    18       else   { position = window.pageYOffset; }
    18 			else   { position = window.pageYOffset; }
    19       for(i=0;i<divs.length;i++) {
    19 			for(i=0;i<divs.length;i++) {
    20         if(divs[i].id && divs[i].id.substr(0, 4) == 'root') {
    20 				if(divs[i].id && divs[i].id.substr(0, 4) == 'root') {
    21           divs[i].onClick = 'jws.focus(\''+divs[i].id+'\')';
    21 					divs[i].onClick = 'jws.focus(\''+divs[i].id+'\')';
    22           var tb = i + 1
    22 					var tb = i + 1
    23           tb = divs[tb];
    23 					tb = divs[tb];
    24           tb.innerHTML = '<table border="0" width="100%"><tr><td>' + tb.innerHTML + '</td><td align="right"><div align="center" class="closebtn" onclick="jws.closeWin(\''+divs[i].id+'\');">X</div></td></tr></table>';
    24 					tb.innerHTML = '<table border="0" width="100%"><tr><td>' + tb.innerHTML + '</td><td align="right"><div align="center" class="closebtn" onclick="jws.closeWin(\''+divs[i].id+'\');">X</div></td></tr></table>';
    25           divs[i].style.width = '640px';
    25 					divs[i].style.width = '640px';
    26           divs[i].style.height = '480px';
    26 					divs[i].style.height = '480px';
    27           Drag.init(tb, divs[i]);
    27 					Drag.init(tb, divs[i]);
    28         }
    28 				}
    29       }
    29 			}
    30     },
    30 		},
    31     initWindow : function(o) {
    31 		initWindow : function(o) {
    32       jws.debug('jws.initWindow('+o+' ['+o.id+'])');
    32 			jws.debug('jws.initWindow('+o+' ['+o.id+'])');
    33       var divs = document.getElementsByTagName('div');
    33 			var divs = document.getElementsByTagName('div');
    34       for(i=0;i<divs.length;i++) {
    34 			for(i=0;i<divs.length;i++) {
    35         if(divs[i].id && divs[i].id == o.id) {
    35 				if(divs[i].id && divs[i].id == o.id) {
    36           var tb = i + 1
    36 					var tb = i + 1
    37           tb = divs[tb];
    37 					tb = divs[tb];
    38           tb.innerHTML = '<table border="0" width="100%"><tr><td>' + tb.innerHTML + '</td><td align="right"><div class="closebtn" onclick="jws.closeWin(\''+divs[i].id+'\');"></div></td></tr></table>';
    38 					tb.innerHTML = '<table border="0" width="100%"><tr><td>' + tb.innerHTML + '</td><td align="right"><div class="closebtn" onclick="jws.closeWin(\''+divs[i].id+'\');"></div></td></tr></table>';
    39           divs[i].style.width = '640px';
    39 					divs[i].style.width = '640px';
    40           divs[i].style.height = '480px';
    40 					divs[i].style.height = '480px';
    41           Drag.init(tb, divs[i]);
    41 					Drag.init(tb, divs[i]);
    42         }
    42 				}
    43       }
    43 			}
    44     },
    44 		},
    45     closeWin : function(id) {
    45 		closeWin : function(id) {
    46       jws.debug('jws.closeWin(\''+id+'\')');
    46 			jws.debug('jws.closeWin(\''+id+'\')');
    47       document.getElementById(id).style.display = 'none';
    47 			document.getElementById(id).style.display = 'none';
    48       enlighten();
    48 			enlighten();
    49     },
    49 		},
    50     openWin : function(id, x, y) {
    50 		openWin : function(id, x, y) {
    51       darken();
    51 			darken();
    52       var e = document.getElementById(id);
    52 			var e = document.getElementById(id);
    53       if(!x) x = 640;
    53 			if(!x) x = 640;
    54       if(!y) y = 480;
    54 			if(!y) y = 480;
    55       jws.debug('jws.openWin(\''+id+'\', '+x+', '+y+')');
    55 			jws.debug('jws.openWin(\''+id+'\', '+x+', '+y+')');
    56       e.style.display = 'block';
    56 			e.style.display = 'block';
    57       e.style.width   = x+'px';
    57 			e.style.width   = x+'px';
    58       e.style.height  = y+'px';
    58 			e.style.height  = y+'px';
    59       
    59 			
    60       var divs = document.getElementsByTagName('div');
    60 			var divs = document.getElementsByTagName('div');
    61       for(i=0;i<divs.length;i++) {
    61 			for(i=0;i<divs.length;i++) {
    62         if(divs[i].id && divs[i].id == e.id) {
    62 				if(divs[i].id && divs[i].id == e.id) {
    63           var cn = i + 3;
    63 					var cn = i + 3;
    64           cn = divs[cn];
    64 					cn = divs[cn];
    65           
    65 					
    66           var h = getElementHeight(e.id) - 53;
    66 					var h = getElementHeight(e.id) - 53;
    67           var w = getElementWidth(cn.id) - 20;
    67 					var w = getElementWidth(cn.id) - 20;
    68           cn.style.width   =  w + 'px';
    68 					cn.style.width   =  w + 'px';
    69           cn.style.height  =  h + 'px';
    69 					cn.style.height  =  h + 'px';
    70           cn.style.clip.top = 0 + 'px';
    70 					cn.style.clip.top = 0 + 'px';
    71           cn.style.clip.left = 0 + 'px';
    71 					cn.style.clip.left = 0 + 'px';
    72           cn.style.clip.right =  w + 'px';
    72 					cn.style.clip.right =  w + 'px';
    73           cn.style.clip.bottom = h + 'px';
    73 					cn.style.clip.bottom = h + 'px';
    74           cn.style.overflow = 'auto';
    74 					cn.style.overflow = 'auto';
    75         }
    75 				}
    76       }
    76 			}
    77       jws.setpos(id);
    77 			jws.setpos(id);
    78       jws.focus(id);
    78 			jws.focus(id);
    79     },
    79 		},
    80     setpos : function(el) {
    80 		setpos : function(el) {
    81       jws.debug('jws.setpos(\''+el+'\')');
    81 			jws.debug('jws.setpos(\''+el+'\')');
    82       el = document.getElementById(el);
    82 			el = document.getElementById(el);
    83       var w = getWidth();
    83 			var w = getWidth();
    84       var h = getHeight();
    84 			var h = getHeight();
    85       var ew = getElementWidth(el.id);
    85 			var ew = getElementWidth(el.id);
    86       var eh = getElementHeight(el.id);
    86 			var eh = getElementHeight(el.id);
    87       px = (w/2) - (ew/2);
    87 			px = (w/2) - (ew/2);
    88       py = (h/2) - (eh/2);
    88 			py = (h/2) - (eh/2);
    89       if (IE) { position = document.body.scrollTop; }
    89 			if (IE) { position = document.body.scrollTop; }
    90       else    { position = window.pageYOffset; }
    90 			else    { position = window.pageYOffset; }
    91       py=py+0;
    91 			py=py+0;
    92       if ( IE )
    92 			if ( IE )
    93         el.style.position = "absolute";
    93 				el.style.position = "absolute";
    94       else
    94 			else
    95         el.style.position = "fixed";
    95 				el.style.position = "fixed";
    96       el.style.left=px+'px';
    96 			el.style.left=px+'px';
    97       el.style.top =py+'px';
    97 			el.style.top =py+'px';
    98     },
    98 		},
    99     scrollHandler : function() {
    99 		scrollHandler : function() {
   100       var divs = document.getElementsByTagName('div');
   100 			var divs = document.getElementsByTagName('div');
   101       for(i=0;i<divs.length;i++) {
   101 			for(i=0;i<divs.length;i++) {
   102         if(divs[i].id && divs[i].id.substr(0, 4) == 'root' && divs[i].style.display == 'block') {
   102 				if(divs[i].id && divs[i].id.substr(0, 4) == 'root' && divs[i].style.display == 'block') {
   103           c = divs[i];
   103 					c = divs[i];
   104           jws.debug('jws.scrollHandler(): moving element: '+c.id);
   104 					jws.debug('jws.scrollHandler(): moving element: '+c.id);
   105           var t = c.style.top;
   105 					var t = c.style.top;
   106           var py = t.substr(0, t.length - 2);
   106 					var py = t.substr(0, t.length - 2);
   107           py = parseInt(py);
   107 					py = parseInt(py);
   108           if(jws.position) { py = py - jws.position; }
   108 					if(jws.position) { py = py - jws.position; }
   109           position = getScrollOffset();
   109 					position = getScrollOffset();
   110           py=py+position;                                                           
   110 					py=py+position;                                                           
   111           c.style.position = "absolute";
   111 					c.style.position = "absolute";
   112           if(!isNaN(py)) c.style.top =py+'px';
   112 					if(!isNaN(py)) c.style.top =py+'px';
   113           jws.debug('jws.scrollHandler(): value of py: '+py);
   113 					jws.debug('jws.scrollHandler(): value of py: '+py);
   114         }
   114 				}
   115       }
   115 			}
   116       jws.position = position;
   116 			jws.position = position;
   117     },
   117 		},
   118     focus : function(e) {
   118 		focus : function(e) {
   119       e = document.getElementById(e);
   119 			e = document.getElementById(e);
   120       if(e.style.zindex) z = e.style.zindex;
   120 			if(e.style.zindex) z = e.style.zindex;
   121       else z = 1;
   121 			else z = 1;
   122       z=z+5;
   122 			z=z+5;
   123       e.style.zIndex = z;
   123 			e.style.zIndex = z;
   124     },
   124 		},
   125     debug : function(t) {
   125 		debug : function(t) {
   126       if(document.getElementById('jsw-debug-console')) {
   126 			if(document.getElementById('jsw-debug-console')) {
   127         dbg = document.getElementById('jsw-debug-console');
   127 				dbg = document.getElementById('jsw-debug-console');
   128         debugdata = dbg.innerHTML;
   128 				debugdata = dbg.innerHTML;
   129         dbg.innerHTML = debugdata+"<br />"+t;
   129 				dbg.innerHTML = debugdata+"<br />"+t;
   130       }
   130 			}
   131     }
   131 		}
   132   } // class jws
   132 	} // class jws
   133 
   133 
   134 //window.onscroll=jws['scrollHandler'];
   134 //window.onscroll=jws['scrollHandler'];
   135 
   135 
   136 /**************************************************
   136 /**************************************************
   137  * dom-drag.js
   137  * dom-drag.js
   143  * Enano.
   143  * Enano.
   144  **************************************************/
   144  **************************************************/
   145 
   145 
   146 var Drag = {
   146 var Drag = {
   147 
   147 
   148   obj : null,
   148 	obj : null,
   149 
   149 
   150   init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
   150 	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
   151   {
   151 	{
   152     o.onmousedown	= Drag.start;
   152 		o.onmousedown	= Drag.start;
   153 
   153 
   154     o.hmode			= bSwapHorzRef ? false : true ;
   154 		o.hmode			= bSwapHorzRef ? false : true ;
   155     o.vmode			= bSwapVertRef ? false : true ;
   155 		o.vmode			= bSwapVertRef ? false : true ;
   156 
   156 
   157     o.root = oRoot && oRoot != null ? oRoot : o ;
   157 		o.root = oRoot && oRoot != null ? oRoot : o ;
   158 
   158 
   159     if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
   159 		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
   160     if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
   160 		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
   161     if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
   161 		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
   162     if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";
   162 		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";
   163 
   163 
   164     o.minX	= typeof minX != 'undefined' ? minX : null;
   164 		o.minX	= typeof minX != 'undefined' ? minX : null;
   165     o.minY	= typeof minY != 'undefined' ? minY : null;
   165 		o.minY	= typeof minY != 'undefined' ? minY : null;
   166     o.maxX	= typeof maxX != 'undefined' ? maxX : null;
   166 		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
   167     o.maxY	= typeof maxY != 'undefined' ? maxY : null;
   167 		o.maxY	= typeof maxY != 'undefined' ? maxY : null;
   168 
   168 
   169     o.xMapper = fXMapper ? fXMapper : null;
   169 		o.xMapper = fXMapper ? fXMapper : null;
   170     o.yMapper = fYMapper ? fYMapper : null;
   170 		o.yMapper = fYMapper ? fYMapper : null;
   171 
   171 
   172     o.root.onDragStart	= new Function();
   172 		o.root.onDragStart	= new Function();
   173     o.root.onDragEnd	= new Function();
   173 		o.root.onDragEnd	= new Function();
   174     o.root.onDrag		= new Function();
   174 		o.root.onDrag		= new Function();
   175   },
   175 	},
   176 
   176 
   177   start : function(e)
   177 	start : function(e)
   178   {
   178 	{
   179     var o = Drag.obj = this;
   179 		var o = Drag.obj = this;
   180     e = Drag.fixE(e);
   180 		e = Drag.fixE(e);
   181     var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
   181 		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
   182     var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
   182 		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
   183     o.root.onDragStart(x, y);
   183 		o.root.onDragStart(x, y);
   184 
   184 
   185     o.lastMouseX	= e.clientX;
   185 		o.lastMouseX	= e.clientX;
   186     o.lastMouseY	= e.clientY;
   186 		o.lastMouseY	= e.clientY;
   187 
   187 
   188     if (o.hmode) {
   188 		if (o.hmode) {
   189       if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
   189 			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
   190       if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
   190 			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
   191     } else {
   191 		} else {
   192       if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
   192 			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
   193       if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
   193 			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
   194     }
   194 		}
   195 
   195 
   196     if (o.vmode) {
   196 		if (o.vmode) {
   197       if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
   197 			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
   198       if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
   198 			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
   199     } else {
   199 		} else {
   200       if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
   200 			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
   201       if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
   201 			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
   202     }
   202 		}
   203 
   203 
   204     document.onmousemove	= Drag.drag;
   204 		document.onmousemove	= Drag.drag;
   205     document.onmouseup		= Drag.end;
   205 		document.onmouseup		= Drag.end;
   206 
   206 
   207     return false;
   207 		return false;
   208   },
   208 	},
   209 
   209 
   210   drag : function(e)
   210 	drag : function(e)
   211   {
   211 	{
   212     e = Drag.fixE(e);
   212 		e = Drag.fixE(e);
   213     var o = Drag.obj;
   213 		var o = Drag.obj;
   214 
   214 
   215     var ey	= e.clientY;
   215 		var ey	= e.clientY;
   216     var ex	= e.clientX;
   216 		var ex	= e.clientX;
   217     var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
   217 		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
   218     var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
   218 		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
   219     var nx, ny;
   219 		var nx, ny;
   220 
   220 
   221     if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
   221 		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
   222     if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
   222 		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
   223     if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
   223 		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
   224     if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);
   224 		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);
   225 
   225 
   226     nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
   226 		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
   227     ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));
   227 		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));
   228 
   228 
   229     if (o.xMapper)		nx = o.xMapper(y)
   229 		if (o.xMapper)		nx = o.xMapper(y)
   230     else if (o.yMapper)	ny = o.yMapper(x)
   230 		else if (o.yMapper)	ny = o.yMapper(x)
   231 
   231 
   232     Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
   232 		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
   233     Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
   233 		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
   234     Drag.obj.lastMouseX	= ex;
   234 		Drag.obj.lastMouseX	= ex;
   235     Drag.obj.lastMouseY	= ey;
   235 		Drag.obj.lastMouseY	= ey;
   236 
   236 
   237     Drag.obj.root.onDrag(nx, ny);
   237 		Drag.obj.root.onDrag(nx, ny);
   238     return false;
   238 		return false;
   239   },
   239 	},
   240 
   240 
   241   end : function()
   241 	end : function()
   242   {
   242 	{
   243     document.onmousemove = getMouseXY;
   243 		document.onmousemove = getMouseXY;
   244     document.onmouseup   = null;
   244 		document.onmouseup   = null;
   245     Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
   245 		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
   246                   parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
   246 									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
   247     Drag.obj = null;
   247 		Drag.obj = null;
   248   },
   248 	},
   249 
   249 
   250   fixE : function(e)
   250 	fixE : function(e)
   251   {
   251 	{
   252     if (typeof e == 'undefined') e = window.event;
   252 		if (typeof e == 'undefined') e = window.event;
   253     if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
   253 		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
   254     if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
   254 		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
   255     return e;
   255 		return e;
   256   }
   256 	}
   257 };
   257 };
   258 
   258