| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 /* 2 * Limb PHP Framework 3 * 4 * @link http://limb-project.com 5 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 6 * @license LGPL http://www.gnu.org/copyleft/lesser.html 7 */ 8 9 Limb.namespace('Limb.Window'); 10 11 var LIMB_WINDOW_WIDTH = null; 12 var LIMB_WINDOW_HEIGHT = null; 13 var LIMB_WINDOW_DEFAULT_PARAMS = {}; 14 15 Limb.Class('Limb.Window', 16 { 17 __construct: function() 18 { 19 this.parentWindow = null; 20 this.windowName = this._generateName(); 21 this.onLoadEvents = []; 22 this.onUnloadEvents = []; 23 this.params = {}; 24 25 if(arguments.length == 0) 26 this.window = window; 27 28 // arguments[0] instanceof Window does not work in IE 29 if(typeof(arguments[0]) == 'object') 30 this.window = win; 31 32 if(arguments.length > 0) 33 { 34 this.window = this._createWindow(arguments[0], arguments[1], arguments[2]); 35 jQuery(this.window).ready(this.onOpen.bind(this)); 36 jQuery(this.window).load(this.onLoad.bind(this)); 37 jQuery(this.window).bind(this.window, 'close', this.onClose.bind(this)); 38 } 39 }, 40 41 getWindowObject: function() 42 { 43 return this.window; 44 }, 45 46 centreWindow: function(width, height) 47 { 48 var newWindowRect = this._getRectInParentCenter(width, height); 49 this.setRect(newWindowRect); 50 }, 51 52 _getRectInParentCenter: function(width, height) 53 { 54 var windowRect = this.parentWindow.getRect(); 55 56 var result = new Limb.Coordinates.Rect(); 57 result.createWithCenter(windowRect.getCenter(), width, height); 58 59 return result; 60 }, 61 62 _getDefaultParams: function() 63 { 64 var width = 150; 65 var height = 100; 66 67 var newWindowRect = this._getRectInParentCenter(width, height); 68 69 var params = new Limb.Window.Params(); 70 71 params.addParameter('left', newWindowRect.getX()); 72 params.addParameter('top', newWindowRect.getY()); 73 params.addParameter('width', width); 74 params.addParameter('height', height); 75 76 params.addParameter('scrollbars', 'yes'); 77 params.addParameter('resizable', 'yes'); 78 params.addParameter('help', 'no'); 79 params.addParameter('status', 'yes'); 80 81 return params; 82 }, 83 84 _generateName: function() 85 { 86 return Math.round(Math.random() * 1000) + '_generate'; 87 }, 88 89 _createWindow: function(href, windowName, createParams) 90 { 91 this.parentWindow = new Limb.Window(); 92 93 if(windowName) 94 this.windowName = windowName; 95 96 this.params = this._getDefaultParams(); 97 this.params.merge(createParams || LIMB_WINDOW_DEFAULT_PARAMS); 98 99 var win = window.open(href, this.windowName, this.params.asString()); 100 return win; 101 }, 102 103 getRect: function() 104 { 105 if(Limb.Browser.is_ie) 106 return new Limb.Coordinates.Rect(this.window.screenLeft, 107 this.window.screenTop, 108 this.window.document.body.clientWidth, 109 this.window.document.body.clientHeight); 110 else 111 return new Limb.Coordinates.Rect(this.window.screenX + this.window.outerWidth - this.window.innerWidth, 112 this.window.screenY + this.window.outerHeight - this.window.innerHeight, 113 this.window.innerWidth, 114 this.window.innerHeight); 115 }, 116 117 setRect: function(rect) 118 { 119 if(!rect) 120 return false; 121 122 this.window.moveTo(rect.getX(), rect.getY()); 123 this.window.resizeTo(rect.getWidth(), rect.getHeight()); 124 125 return true; 126 }, 127 128 close: function() 129 { 130 this.window.close(); 131 }, 132 133 onOpen: function() 134 { 135 Limb.Window.register(this.windowName, this); 136 137 this.autoResize(); 138 139 this.centreWindow(this.params.getParameter('width'), this.params.getParameter('height')); 140 141 this.openHandler(); 142 }, 143 144 onLoad: function() 145 { 146 this.autoResize(); 147 148 this.centreWindow(this.params.getParameter('width'), this.params.getParameter('height')); 149 }, 150 151 autoResize: function() 152 { 153 if(!(this.params && !this.params.getParameter('noautoresize')) && 154 !(this.window.LIMB_WINDOW_WIDTH || this.window.LIMB_WINDOW_HEIGHT)) 155 return; 156 157 if(this.window.LIMB_WINDOW_WIDTH) 158 this.params.setParameter('width', this.window.LIMB_WINDOW_WIDTH); 159 else 160 this.params.setParameter('width', this.parentWindow.getRect().getWidth() * 0.85); 161 162 if(this.window.LIMB_WINDOW_HEIGHT) 163 this.params.setParameter('height', this.window.LIMB_WINDOW_HEIGHT); 164 else 165 this.params.setParameter('height', this.parentWindow.getRect().getHeight() * 0.9); 166 }, 167 168 onClose: function() 169 { 170 Limb.Window.remove(this.windowName); 171 172 this.closeHandler(); 173 }, 174 175 openHandler: function() {}, 176 closeHandler: function() {}, 177 178 static: 179 { 180 register: function(windowName, win) 181 { 182 if(!Limb.isset(Limb.Window.createdWindows)) 183 Limb.Window.createdWindows = []; 184 185 Limb.Window.createdWindows[windowName] = win; 186 }, 187 188 remove: function(windowName) 189 { 190 if(!Limb.isset(Limb.Window.createdWindows)|| 191 !Limb.isset(Limb.Window.createdWindows[windowName])) 192 return; 193 194 Limb.Window.createdWindows[windowName] = null; 195 delete Limb.Window.createdWindows[windowName]; 196 }, 197 198 current: function() 199 { 200 if(!Limb.isset(Limb.Window.createdWindows)) 201 return null; 202 203 for(var i in Limb.Window.createdWindows) 204 if(Limb.Window.createdWindows[i].getWindowObject() == window) 205 return Limb.Window.createdWindows[i]; 206 207 return null; 208 } 209 } 210 }); 211 212 Limb.Class('Limb.Window.Params', 213 { 214 __construct: function(initArray) 215 { 216 this.params = initArray || []; 217 }, 218 219 setParameter: function(name, value) 220 { 221 this.params[name] = value; 222 }, 223 224 addParameter: function(name, value) 225 { 226 if(Limb.isset(this.params[name])) 227 return; 228 229 this.setParameter(name, value); 230 }, 231 232 getParameter: function(name) 233 { 234 return this.params[name]; 235 }, 236 237 merge: function(params) 238 { 239 for(var name in params) 240 this.params[name] = params[name]; 241 }, 242 243 asString: function() 244 { 245 var result = ''; 246 247 for(var name in this.params) 248 { 249 if(Limb.isFunction(this.params[name])) 250 continue; 251 252 result += name + '=' + this.params[name] + ','; 253 } 254 255 return result.slice(0, -1); 256 }, 257 258 toArray: function() 259 { 260 return this.params; 261 } 262 }); 263 264 Limb.namespace('Limb.Coordinates'); 265 266 Limb.Class('Limb.Coordinates.Point', 267 { 268 __construct: function(x, y) 269 { 270 this.x = x || 0; 271 this.y = y || 0; 272 }, 273 274 setX: function(x) 275 { 276 this.x = x; 277 }, 278 279 setY: function(y) 280 { 281 this.y = y; 282 }, 283 284 getX: function() 285 { 286 return this.x; 287 }, 288 289 getY: function() 290 { 291 return this.y; 292 } 293 }); 294 295 Limb.Class('Limb.Coordinates.Rect').inherits('Limb.Coordinates.Point', 296 { 297 __construct: function(x, y, width, height) 298 { 299 this.parent.__construct(x, y); 300 301 this.width = width || 0; 302 this.height = height || 0; 303 }, 304 305 setWidth: function(width) 306 { 307 this.width = width; 308 }, 309 310 setHeight: function(height) 311 { 312 this.height = height; 313 }, 314 315 getWidth: function() 316 { 317 return this.width; 318 }, 319 320 getHeight: function() 321 { 322 return this.height; 323 }, 324 325 getRight: function() 326 { 327 return this.x + this.width; 328 }, 329 330 getBottom: function() 331 { 332 return this.y + this.height; 333 }, 334 335 setSize: function(width, height) 336 { 337 this.width = width || 0; 338 this.height = height || 0; 339 }, 340 341 createWithCenter: function(point, width, height) 342 { 343 if(!point) 344 return; 345 346 this.setSize(width, height); 347 this.alignToCenter(point); 348 }, 349 350 alignToCenter: function(point) 351 { 352 this.x = point.x - this.width / 2; 353 this.y = point.y - this.height / 2; 354 }, 355 356 getCenter: function() 357 { 358 return new Limb.Coordinates.Point(this.x + (this.width / 2), this.y + (this.height / 2)); 359 } 360 });
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Nov 22 03:48:54 2008 | Cross-referenced by PHPXref 0.7 |