Best JavaScript code snippet using cypress
dialog.js
Source:dialog.js
1/*2Copyright (c) 2012 Tony Germaneri3Permission is hereby granted,4 free of charge, to any person obtaining a copy of this software 5and associated documentation files (the "Software"), to deal in 6the Software without restriction, including without limitation the7 rights to use, copy, modify, merge, publish, distribute, 8sublicense, and/or sell copies of the Software, and to permit 9persons to whom the Software is furnished to do so, subject to the10 following conditions:11The above copyright notice and this 12permission notice shall be included in all copies or substantial 13portions of the Software.14THE SOFTWARE IS PROVIDED "AS IS", 15WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 16NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 17PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 19OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20OTHERWISE, AR21SING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE22 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.23*/24/**25* Style of the dialog.26* @constructor27* @name Rendition.UI.DialogWindowStyle28*/29Rendition.UI.DialogWindowStyle = function () {30 var instance = {}31 instance.id = 'uid_' + Rendition.UI.createId();32 instance.type = 'RenditionDialogWindowStyle';33 instance.titleCenterRect = {x:0,y:0,h:22,w:0}34 instance.titleLeftRect = {x:0,y:0,h:22,w:6}35 instance.titleRightRect = {x:0,y:0,h:22,w:6}36 instance.titleTextRect = {x:0,y:0,h:17,w:0}37 instance.contentRect = {x:0,y:0,h:0,w:0}38 instance.minRect = {x:-80,y:3,h:15,w:15}39 instance.maxRect = {x:-60,y:3,h:15,w:15}40 instance.restoreRect = {x:-60,y:3,h:15,w:15}41 instance.closeRect = {x:-40,y:3,h:15,w:15}42 instance.statusBarCenterRect = {x:0,y:0,h:17,w:0}43 instance.statusBarLeftRect = {x:0,y:0,h:17,w:6}44 instance.statusBarRightRect = {x:0,y:0,h:17,w:6}45 instance.menuBarRect = {x:0,y:0,h:0,w:0}46 instance.toolBarRect = {x:0,y:0,h:0,w:0}47 instance.nRect = {x:0,y:0,h:4,w:0}48 instance.sRect = {x:0,y:0,h:4,w:0}49 instance.eRect = {x:0,y:0,h:0,w:4}50 instance.wRect = {x:0,y:0,h:0,w:4}51 instance.nwRect = {x:0,y:0,h:10,w:10}52 instance.neRect = {x:0,y:0,h:10,w:10}53 instance.seRect = {x:0,y:0,h:10,w:10}54 instance.swRect = {x:0,y:0,h:10,w:10}55 instance.minimumRect = {x:0,y:0,h:10,w:10}56 instance.charToPx = 6;57 instance.nwBackground = '#99CC00';58 instance.nBackground = '#FF9900';59 instance.neBackground = '#CC0033';60 instance.eBackground = '#660066';61 instance.seBackground = '#3300CC';62 instance.sBackground = '#0099FF';63 instance.swBackground = '#00CC99';64 instance.wBackground = '#33CC33';65 instance.titleCenterBackground = '#FFFF00';66 instance.titleLeftBackground = '#CC6600';67 instance.titleRightBackground = '#99FFCC';68 instance.statusBarCenterBackground = '#33FF99';69 instance.statusBarLeftBackground = '#FF0000';70 instance.statusBarRightBackground = '#FF0000';71 instance.dialogBackground = '#CCCCCC';72 instance.contentBackground = '#DDDDDD';73 instance.restoreBackground = '#CCFFFF';74 instance.closeBackground = '#CCFFFF';75 instance.minBackground = '#CC9999';76 instance.maxBackground = '#999966';77 instance.restoreHoverBackground = '#0099FF';78 instance.closeHoverBackground = '#0099FF';79 instance.minHoverBackground = '#6600CC';80 instance.maxHoverBackground = '#FF3333';81 instance.restoreBorder = 'none';82 instance.closeBorder = 'none';83 instance.minBorder = 'none';84 instance.maxBorder = 'none';85 instance.titleFont = 'normal 12px \'Trebuchet MS\',\'Arial\',\'Helvetica\',\'Sans-serif\'';86 instance.titleTextAlignment = 'left';87 instance.titleColor = '#000';88 instance.taskElement = null;89 instance.modalBackground = 'url(img/50PctAlphaBlackDot.png)';90 instance.previewBackground = 'url(img/50PctAlphaBlackDot.png)';91 instance.boxShadow = '2px 2px 2px #AAA';92 return instance;93}94/**95* Creates a DHTML based dialog. The dialog contains control boxes, a title bar, an entry in the task bar if visible, resize controls and dozens of events to attach to.96* @constructor97* @name Rendition.UI.Dialog98* @param {Native.Object} [args] Parameters for the dialog.99* @param {Native.Boolean} [args.alwaysOnTop=false] When true the dialog will always appear above other dialogs not set alwaysOnTop=true.100* @param {Native.Boolean} [args.hidden=false] When true the dialog will be hidden. Hidden means displayed off screen at left:-10,000px top:10,000px.101* @param {Native.Boolean} [args.modalCloseable=false] When true and the dialog is in modal mode, the control box for close will still work.102* @param {Native.Boolean} [args.modal=false] When true and the dialog the dialog will appear in modal mode. No other dialogs or controls will be accessable until this dialog closes.103* @param {Native.String} [args.title] The title that will appear in the title bar of the dialog.104* @param {Native.Boolean} [args.resizeable=true] When true the dialog can be resized by the user when not in maximized mode.105* @param {Native.Object} [args.rect={x:centered,y:75,h:350,w:400}] An object that looks like {x:Integer,y:Integer,h:Integer,w:Integer} that represents the position and dimentions of the dialog. When not defined a dialog 350x400 will be created and centered in the current browser.106* @param {Native.Boolean} [args.dontInit=false] Don't initialize the dialog until you call the dialogs init method.107* @example ///Create a simple refrence to a new dialog, set the title and make it modal.///108*var myDialog = Rendition.UI.Dialog({109* title:'My Dialog',110* modal: true111*});112* @example ///Attach to an event when you create the dialog.///113*var myDialog = Rendition.UI.Dialog({114* title:'My Dialog',115* close:function(e,dialog){116* dialog.title('Can\'t close me.');117* dialog.preventDefault();118* return119* }120*});121* @example ///Attach to an event after you create the dialog///122*var myDialog = Rendition.UI.Dialog({123* title:'My Dialog'124*});125*myDialog.addEventListener('close',function(e,dialog){126* dialog.title('Can\'t close me.');127* dialog.preventDefault();128* return129*},false);130*/131Rendition.UI.Dialog = Rendition.UI.dialogWindow = function (args) {132 if (args === undefined) { args = {} }133 var instance = {}134 /**135 * The type of object. returns 'RenditionGrid'136 * @name Dialog.type137 * @memberOf Rendition.UI.Dialog.prototype138 * @type Native.String139 * @public140 * @property141 * @memberOf Rendition.UI.Dialog.prototype142 */143 instance.type = 'RenditionDialogWindow';144 /**145 * unique id of this object. Assigned automatcilly in this reg format /uid_UUID/146 * @name Dialog.id147 * @memberOf Rendition.UI.Dialog.prototype148 * @type Native.String149 * @public150 * @property151 * @memberOf Rendition.UI.Dialog.prototype152 */153 instance.id = 'uid_' + Rendition.UI.createId();154 /**155 * The desktop object this dialog is a memeber of. This is always Rendition.UI.desktops[0].156 * @name Dialog.desktop157 * @memberOf Rendition.UI.Dialog.prototype158 * @type Native.Object159 * @public160 * @property161 * @memberOf Rendition.UI.Dialog.prototype162 */163 instance.desktop = args.desktop || Rendition.UI.desktops[0];164 /**165 * If true, this dialog is set to be 'always on top'.166 * @name Dialog.alwaysOnTop167 * @memberOf Rendition.UI.Dialog.prototype168 * @type Native.Boolean169 * @public170 * @property171 * @readOnly172 * @memberOf Rendition.UI.Dialog.prototype173 */174 instance.alwaysOnTop = args.alwaysOnTop || false;175 /**176 * If true, this dialog is hidden.177 * @name Dialog.hidden178 * @memberOf Rendition.UI.Dialog.prototype179 * @type Native.Boolean180 * @public181 * @property182 * @readOnly183 * @memberOf Rendition.UI.Dialog.prototype184 */185 instance.hidden = args.hidden || false;186 /**187 * If true, this dialog is closeable while in modal mode.188 * @name Dialog.modalCloseable189 * @memberOf Rendition.UI.Dialog.prototype190 * @type Native.Boolean191 * @public192 * @property193 * @readOnly194 * @memberOf Rendition.UI.Dialog.prototype195 */196 instance.modalCloseable = args.modalCloseable == false ? false : true;197 /**198 * If true, this dialog is in modal mode.199 * @name Dialog.modal200 * @memberOf Rendition.UI.Dialog.prototype201 * @type Native.Boolean202 * @public203 * @property204 * @readOnly205 * @memberOf Rendition.UI.Dialog.prototype206 */207 instance.modal = args.modal || false;208 args.title = args.title || '';209 /**210 * If true, this dialog can be resized.211 * @name Dialog.resizeable212 * @memberOf Rendition.UI.Dialog.prototype213 * @type Native.Boolean214 * @public215 * @property216 * @readOnly217 * @memberOf Rendition.UI.Dialog.prototype218 */219 instance.resizeable = args.resizeable || true;220 /*events */221 /**222 * Executes event subscriptions.223 * @function224 * @name Dialog.executeEvents225 * @memberOf Rendition.UI.Dialog.prototype226 * @returns {Native.Boolean} false if cancel default was called.227 * @private228 * @param {Native.Array} events to execute.229 * @param {Native.Object} e The DOM event object.230 * @param {Native.String} element the related DHTML element.231 * @param {Native.String} arguments The arguments to add to the event signature.232 * @memberOf Rendition.UI.Dialog.prototype233 */234 instance.executeEvents = function (events, e, element, arguments) {235 var fLength = events.length;236 if (fLength < 1) { return false; }237 if (arguments === undefined) { arguments = []; }238 instance.cancelDefault = false;239 arguments.unshift(e, instance, element);240 for (var x = 0; fLength > x; x++) {241 if (events[x] !== undefined) {242 events[x].apply(this, arguments);243 }244 }245 return instance.cancelDefault;246 }247 /**248 * Prevent the default event from occuring. For use within an event handler. For example, when used in within a function subscribed to the close event, running dialog.preventDefault() will prevent the dialog from closing.249 * @function250 * @name Dialog.preventDefault251 * @memberOf Rendition.UI.Dialog.prototype252 * @type Native.undefined253 * @public254 * @memberOf Rendition.UI.Dialog.prototype255 */256 instance.preventDefault = function () {257 instance.cancelDefault = true;258 }259 /**260 * Attach a procedure to an event. Usage dialog.addEventListener('cellmousedown',function(e,grid,element,row,column,selection,data,header){/*your procedure code},false)261 * @function262 * @name Dialog.addEventListener263 * @memberOf Rendition.UI.Dialog.prototype264 * @type Native.undefined265 * @param {Native.String} type The type of event to subscribe to.266 * @param {Native.Function} proc The function to call when the event is fired.267 * @param {Native.Boolean} [capture=false] What phase of the event will occur on. This is not used.268 * @public269 * @memberOf Rendition.UI.Dialog.prototype270 */271 instance.addEventListener = function (type, proc, capture) {272 if (instance.events[type]) {273 if (instance.events[type].indexOf(proc) == -1) {274 instance.events[type].push(proc);275 }276 } else {277 if (console) {278 console.log('can\'t attach to event handler ' + type);279 }280 }281 return null;282 }283 /**284 * Removes an event from subscription list. The [proc] must match exactly the [proc] subscribed with.285 * @function286 * @name Dialog.removeEventListener287 * @memberOf Rendition.UI.Dialog.prototype288 * @type Native.undefined289 * @param {Native.String} type The type of event to subscribe to.290 * @param {Native.Function} proc The function to call when the event is fired.291 * @param {Native.Boolean} [capture=false] What phase of the event will occur on. This is not used.292 * @public293 * @memberOf Rendition.UI.Dialog.prototype294 */295 instance.removeEventListener = function (type, proc, capture) {296 var evts = instance.events[type];297 for (var x = 0; evts.length > x; x++) {298 if (evts[x] == proc) {299 evts.splice(x, 1);300 }301 }302 return null;303 }304 /**305 * Used internally to add events used in the arugments of this instance.306 * @function307 * @name Dialog.addInitalEvents308 * @memberOf Rendition.UI.Dialog.prototype309 * @type Native.undefined310 * @param {Native.Function} eventProc The event to add.311 * @private312 * @memberOf Rendition.UI.Dialog.prototype313 */314 instance.addInitalEvents = function (eventProc) {315 if (eventProc) {316 return [eventProc];317 } else {318 return [];319 }320 }321 instance.events = {322 /**323 * Occurs when the dialog is closed.324 * @event325 * @name Dialog.onclose326 * @memberOf Rendition.UI.Dialog.prototype327 * @public328 * @param {Native.Object} e Browser event object.329 * @param {Native.Object} dialog dialog.330 */331 close: instance.addInitalEvents(args.close),332 /**333 * Occurs when the dialog is being resized.334 * @event335 * @name Dialog.onresize336 * @memberOf Rendition.UI.Dialog.prototype337 * @public338 * @param {Native.Object} e Browser event object.339 * @param {Native.Object} dialog dialog.340 */341 resize: instance.addInitalEvents(args.resize),342 /**343 * Occurs when the dialog is maximized.344 * @event345 * @name Dialog.onmaximize346 * @memberOf Rendition.UI.Dialog.prototype347 * @public348 * @param {Native.Object} e Browser event object.349 * @param {Native.Object} dialog dialog.350 */351 maximize: instance.addInitalEvents(args.maximize),352 /**353 * Occurs when the dialog is minimized.354 * @event355 * @name Dialog.onminimize356 * @memberOf Rendition.UI.Dialog.prototype357 * @public358 * @param {Native.Object} e Browser event object.359 * @param {Native.Object} dialog dialog.360 */361 minimize: instance.addInitalEvents(args.minimize),362 /**363 * Occurs when the dialog is restored.364 * @event365 * @name Dialog.onrestore366 * @memberOf Rendition.UI.Dialog.prototype367 * @public368 * @param {Native.Object} e Browser event object.369 * @param {Native.Object} dialog dialog.370 */371 restore: instance.addInitalEvents(args.restore),372 /**373 * Occurs when the dialog is moving.374 * @event375 * @name Dialog.onmove376 * @memberOf Rendition.UI.Dialog.prototype377 * @public378 * @param {Native.Object} e Browser event object.379 * @param {Native.Object} dialog dialog.380 */381 move: instance.addInitalEvents(args.move),382 /**383 * Occurs when the is starting to be resized.384 * @event385 * @name Dialog.onstartingResize386 * @memberOf Rendition.UI.Dialog.prototype387 * @public388 * @param {Native.Object} e Browser event object.389 * @param {Native.Object} dialog dialog.390 */391 startingResize: instance.addInitalEvents(args.startingResize),392 /**393 * Occurs when the is starting to be moved.394 * @event395 * @name Dialog.onstartingMove396 * @memberOf Rendition.UI.Dialog.prototype397 * @public398 * @param {Native.Object} e Browser event object.399 * @param {Native.Object} dialog dialog.400 */401 startingMove: instance.addInitalEvents(args.startingMove),402 /**403 * Occurs when the is dialog is finished resizing.404 * @event405 * @name Dialog.onfinishedResize406 * @memberOf Rendition.UI.Dialog.prototype407 * @public408 * @param {Native.Object} e Browser event object.409 * @param {Native.Object} dialog dialog.410 */411 finishedResize: instance.addInitalEvents(args.finishedResize),412 /**413 * Occurs when the is dialog is finished moving.414 * @event415 * @name Dialog.onfinishedMove416 * @memberOf Rendition.UI.Dialog.prototype417 * @public418 * @param {Native.Object} e Browser event object.419 * @param {Native.Object} dialog dialog.420 */421 finishedMove: instance.addInitalEvents(args.finishedMove),422 /**423 * Occurs when the is dialog's title has changed.424 * @event425 * @name Dialog.ontitleChanged426 * @memberOf Rendition.UI.Dialog.prototype427 * @public428 * @param {Native.Object} e Browser event object.429 * @param {Native.Object} dialog dialog.430 */431 titleChanged: instance.addInitalEvents(args.titleChanged),432 /**433 * Occurs when the is dialog is activated.434 * @event435 * @name Dialog.onactivate436 * @memberOf Rendition.UI.Dialog.prototype437 * @public438 * @param {Native.Object} e Browser event object.439 * @param {Native.Object} dialog dialog.440 */441 activate: instance.addInitalEvents(args.activate),442 /**443 * Occurs when the is dialog is hidden.444 * @event445 * @name Dialog.onhide446 * @memberOf Rendition.UI.Dialog.prototype447 * @public448 * @param {Native.Object} e Browser event object.449 * @param {Native.Object} dialog dialog.450 */451 hide: instance.addInitalEvents(args.hide),452 /**453 * Occurs when the is dialog is shown.454 * @event455 * @name Dialog.onshow456 * @memberOf Rendition.UI.Dialog.prototype457 * @public458 * @param {Native.Object} e Browser event object.459 * @param {Native.Object} dialog dialog.460 */461 show: instance.addInitalEvents(args.show)462 }463 /**464 * Used internally to fire an event procedure.465 * @function466 * @name Dialog.eventlisteners_restore467 * @type Native.Boolean468 * @param {Native.Object} e The event object.469 * @private470 * @returns {Native.Boolean} If true the preventDefault function was not run.471 * @memberOf Rendition.UI.Dialog.prototype472 */473 instance.eventlisteners_restore = function (e) {474 if (instance.executeEvents(instance.events.show, e, this)) { return false }475 return true;476 }477 /**478 * Used internally to fire an event procedure.479 * @function480 * @name Dialog.eventlisteners_show481 * @type Native.Boolean482 * @param {Native.Object} e The event object.483 * @private484 * @returns {Native.Boolean} If true the preventDefault function was not run.485 * @memberOf Rendition.UI.Dialog.prototype486 */487 instance.eventlisteners_show = function (e) {488 if (instance.executeEvents(instance.events.show, e, this)) { return false }489 return true;490 }491 /**492 * Used internally to fire an event procedure.493 * @function494 * @name Dialog.eventlisteners_hide495 * @type Native.Boolean496 * @param {Native.Object} e The event object.497 * @private498 * @returns {Native.Boolean} If true the preventDefault function was not run.499 * @memberOf Rendition.UI.Dialog.prototype500 */501 instance.eventlisteners_hide = function (e) {502 if (instance.executeEvents(instance.events.hide, e, this)) { return false }503 return true;504 }505 /**506 * Used internally to fire an event procedure.507 * @function508 * @name Dialog.eventlisteners_activate509 * @type Native.Boolean510 * @param {Native.Object} e The event object.511 * @private512 * @returns {Native.Boolean} If true the preventDefault function was not run.513 * @memberOf Rendition.UI.Dialog.prototype514 */515 instance.eventlisteners_activate = function (e) {516 if (instance.executeEvents(instance.events.activate, e, this)) { return false }517 return true;518 }519 /**520 * Used internally to fire an event procedure.521 * @function522 * @name Dialog.eventlisteners_titleChanged523 * @type Native.Boolean524 * @param {Native.Object} e The event object.525 * @private526 * @returns {Native.Boolean} If true the preventDefault function was not run.527 * @memberOf Rendition.UI.Dialog.prototype528 */529 instance.eventlisteners_titleChanged = function (e) {530 if (instance.executeEvents(instance.events.titleChanged, e, this)) { return false }531 return true;532 }533 /**534 * Used internally to fire an event procedure.535 * @function536 * @name Dialog.eventlisteners_resize537 * @type Native.Boolean538 * @param {Native.Object} e The event object.539 * @private540 * @returns {Native.Boolean} If true the preventDefault function was not run.541 * @memberOf Rendition.UI.Dialog.prototype542 */543 instance.eventlisteners_resize = function (e) {544 if (instance.executeEvents(instance.events.resize, e, this)) { return false }545 return true;546 }547 /**548 * Used internally to fire an event procedure.549 * @function550 * @name Dialog.eventlisteners_close551 * @type Native.Boolean552 * @param {Native.Object} e The event object.553 * @private554 * @returns {Native.Boolean} If true the preventDefault function was not run.555 * @memberOf Rendition.UI.Dialog.prototype556 */557 instance.eventlisteners_close = function (e) {558 if (instance.executeEvents(instance.events.close, e, this)) { return false }559 return true;560 }561 /**562 * Used internally to fire an event procedure.563 * @function564 * @name Dialog.eventlisteners_maximize565 * @type Native.Boolean566 * @param {Native.Object} e The event object.567 * @private568 * @returns {Native.Boolean} If true the preventDefault function was not run.569 * @memberOf Rendition.UI.Dialog.prototype570 */571 instance.eventlisteners_maximize = function (e) {572 if (instance.executeEvents(instance.events.maximize, e, this)) { return false }573 return true;574 }575 /**576 * Used internally to fire an event procedure.577 * @function578 * @name Dialog.eventlisteners_minimize579 * @type Native.Boolean580 * @param {Native.Object} e The event object.581 * @private582 * @returns {Native.Boolean} If true the preventDefault function was not run.583 * @memberOf Rendition.UI.Dialog.prototype584 */585 instance.eventlisteners_minimize = function (e) {586 if (instance.executeEvents(instance.events.minimize, e, this)) { return false }587 return true;588 }589 /**590 * Used internally to fire an event procedure.591 * @function592 * @name Dialog.eventlisteners_move593 * @type Native.Boolean594 * @param {Native.Object} e The event object.595 * @private596 * @returns {Native.Boolean} If true the preventDefault function was not run.597 * @memberOf Rendition.UI.Dialog.prototype598 */599 instance.eventlisteners_move = function (e) {600 if (instance.executeEvents(instance.events.move, e, this)) { return false }601 return true;602 }603 /**604 * Used internally to fire an event procedure.605 * @function606 * @name Dialog.eventlisteners_startingResize607 * @type Native.Boolean608 * @param {Native.Object} e The event object.609 * @private610 * @returns {Native.Boolean} If true the preventDefault function was not run.611 * @memberOf Rendition.UI.Dialog.prototype612 */613 instance.eventlisteners_startingResize = function (e) {614 if (instance.executeEvents(instance.events.startingResize, e, this)) { return false }615 return true;616 }617 /**618 * Used internally to fire an event procedure.619 * @function620 * @name Dialog.eventlisteners_startingMove621 * @type Native.Boolean622 * @param {Native.Object} e The event object.623 * @private624 * @returns {Native.Boolean} If true the preventDefault function was not run.625 * @memberOf Rendition.UI.Dialog.prototype626 */627 instance.eventlisteners_startingMove = function (e) {628 if (instance.executeEvents(instance.events.startingMove, e, this)) { return false }629 return true;630 }631 /**632 * Used internally to fire an event procedure.633 * @function634 * @name Dialog.eventlisteners_finishedResize635 * @type Native.Boolean636 * @param {Native.Object} e The event object.637 * @private638 * @returns {Native.Boolean} If true the preventDefault function was not run.639 * @memberOf Rendition.UI.Dialog.prototype640 */641 instance.eventlisteners_finishedResize = function (e) {642 if (instance.executeEvents(instance.events.finishedResize, e, this)) { return false }643 return true;644 }645 /**646 * Used internally to fire an event procedure.647 * @function648 * @name Dialog.eventlisteners_finishedMove649 * @type Native.Boolean650 * @param {Native.Object} e The event object.651 * @private652 * @returns {Native.Boolean} If true the preventDefault function was not run.653 * @memberOf Rendition.UI.Dialog.prototype654 */655 instance.eventlisteners_finishedMove = function (e) {656 if (instance.executeEvents(instance.events.finishedMove, e, this)) { return false }657 return true;658 }659 /**660 * Initalizes the dialog adding it to the current desktop.661 * @function662 * @name Dialog.init663 * @memberOf Rendition.UI.Dialog.prototype664 * @private665 * @returns {Native.Object} dialog.666 * @memberOf Rendition.UI.Dialog.prototype667 */668 instance.init = function () {669 if (args.rect === undefined) {670 args.rect = { x: (document.documentElement.clientWidth / 2) - 200, y: 75, h: 350, w: 400 }671 }672 /**673 * The rectangle of this dialog. Looks like {x:Integer,y:Integer,h:Integer,w:Integer}.674 * @name Dialog.rect675 * @memberOf Rendition.UI.Dialog.prototype676 * @type Native.Object677 * @public678 * @property679 * @readOnly680 */681 instance.rect = {682 x: Math.floor(args.rect.x),683 y: Math.floor(args.rect.y),684 h: Math.floor(args.rect.h),685 w: Math.floor(args.rect.w)686 }687 /**688 * The dimentions of the DIV that appears when the dialog is being moved.689 * @name Dialog.previewRect690 * @memberOf Rendition.UI.Dialog.prototype691 * @type Native.Object692 * @private693 * @property694 * @readOnly695 */696 instance.previewRect = args.rect;697 /**698 * The state of the window. 0 = Restored (normal), 1 = Maximized, 2 = Minimized699 * @name Dialog.windowState700 * @memberOf Rendition.UI.Dialog.prototype701 * @type Native.Object702 * @public703 * @property704 * @readOnly705 */706 instance.windowState = 0;707 /**708 * Used interally to track the offset of the mouse.709 * @name Dialog.mouseOffset710 * @memberOf Rendition.UI.Dialog.prototype711 * @type Native.Object712 * @private713 * @property714 * @readOnly715 */716 instance.mouseOffset = { x: 0, y: 0 }717 /**718 * Used interally to track the previous rect state while entering other rect modes (e.g.: hidden, maximized).719 * @name Dialog.previousRect720 * @memberOf Rendition.UI.Dialog.prototype721 * @type Native.Object722 * @private723 * @property724 * @readOnly725 */726 instance.previousRect = null;727 /**728 * Used interally to track the previous state while entering other rect modes (e.g.: hidden, maximized).729 * @name Dialog.previousState730 * @memberOf Rendition.UI.Dialog.prototype731 * @type Native.Integer732 * @private733 * @property734 * @readOnly735 */736 instance.previousState = null;737 /**738 * The index of this grid amongst other grids on this grids desktop.739 * @name Dialog.index740 * @memberOf Rendition.UI.Dialog.prototype741 * @type Native.Integer742 * @private743 * @property744 * @readOnly745 */746 instance.index = null;747 /**748 * The original value of the title.749 * @name Dialog.originalTitleText750 * @memberOf Rendition.UI.Dialog.prototype751 * @type Native.String752 * @private753 * @property754 * @readOnly755 */756 instance.originalTitleText = args.title;757 /**758 * When the dialog is closed then true.759 * @name Dialog.closed760 * @memberOf Rendition.UI.Dialog.prototype761 * @type Native.Boolean762 * @private763 * @property764 * @readOnly765 */766 instance.closed = false;767 /**768 * The style of the dialog.769 * @name Dialog.style770 * @memberOf Rendition.UI.Dialog.prototype771 * @type Native.Object772 * @private773 * @property774 * @readOnly775 */776 instance.style = Rendition.UI.dialogStyle;777 /**778 * The preview DIV element.779 * @name Dialog.preview780 * @memberOf Rendition.UI.Dialog.prototype781 * @type Native.DHTMLElement782 * @private783 * @property784 * @readOnly785 */786 instance.preview = document.createElement('div');787 instance.preview.style.visibility = 'hidden';788 instance.preview.style.display = 'none';789 instance.preview.style.position = 'absolute';790 instance.preview.style.zIndex = '1000000';791 /**792 * The title text node.793 * @name Dialog.titleTextNode794 * @memberOf Rendition.UI.Dialog.prototype795 * @type Native.DHTMLElement796 * @private797 * @property798 * @readOnly799 */800 instance.titleTextNode = document.createTextNode('');801 /**802 * The main dialog container element.803 * @name Dialog.dialog804 * @memberOf Rendition.UI.Dialog.prototype805 * @type Native.DHTMLElement806 * @private807 * @property808 * @readOnly809 */810 instance.dialog = document.createElement('div');811 instance.dialog.style.position = 'absolute';812 instance.dialog.style.id = 'dialog_' + instance.id;813 instance.dialog.style.top = instance.rect.y + 'px';814 instance.dialog.style.left = instance.rect.x + 'px';815 instance.dialog.style.height = instance.rect.h + 'px';816 instance.dialog.style.width = instance.rect.w + 'px';817 /**818 * Resize the modal dialog background.819 * @function820 * @name Dialog.resizeModalBackground821 * @memberOf Rendition.UI.Dialog.prototype822 * @private823 * @param {Native.Object} [e] The event object.824 */825 instance.resizeModalBackground = function (e) {826 instance.modalBackground.style.height = document.documentElement.clientHeight + 'px';827 instance.modalBackground.style.width = document.documentElement.clientWidth + 'px';828 }829 if (instance.modal) {830 instance.modalBackground = document.createElement('div');831 instance.modalBackground.style.position = 'absolute';832 instance.modalBackground.style.top = '0';833 instance.modalBackground.style.left = '0';834 instance.modalBackground.style.background = instance.style.modalBackground;835 Rendition.UI.appendEvent('resize', window, instance.resizeModalBackground, false);836 instance.modalBackground.style.zIndex = Rendition.UI.topModalzindex + 1; Rendition.UI.topModalzindex++;837 instance.dialog.style.zIndex = Rendition.UI.topModalzindex + 2; Rendition.UI.topModalzindex++;838 instance.resizeModalBackground();839 } else if (instance.alwaysOnTop) {840 instance.dialog.style.zIndex = Rendition.UI.topModalzindex + 2; Rendition.UI.topModalzindex++;841 } else {842 instance.dialog.style.zIndex = Rendition.UI.topzindex + 1; Rendition.UI.topzindex++;843 }844 Rendition.UI.appendEvent('mousedown', instance.dialog, function () {845 instance.activate();846 }, false);847 /**848 * The content element. This is where the dialog content should be appended.849 * @name Dialog.content850 * @memberOf Rendition.UI.Dialog.prototype851 * @type Native.DHTMLElement852 * @public853 * @property854 * @readOnly855 */856 instance.content = document.createElement('div');857 instance.content.style.position = 'absolute';858 instance.content.style.overflow = 'hidden';859 instance.content.parentObject = instance;860 instance.content.addEventListener = instance.addEventListener;861 instance.content.setAttribute('windowId', instance.id);862 instance.dialog.appendChild(instance.content);863 /**864 * The center of the title bar.865 * @name Dialog.titleBarCenter866 * @memberOf Rendition.UI.Dialog.prototype867 * @type Native.DHTMLElement868 * @private869 * @property870 * @readOnly871 */872 instance.titleBarCenter = document.createElement('div');873 instance.titleBarCenter.style.position = 'absolute';874 instance.titleBarCenter.ondblclick = function (e) {875 if (!instance.modal) {876 if (instance.windowState == 1) {877 instance.unmaximize();878 } else {879 instance.maximize();880 }881 }882 }883 instance.dialog.appendChild(instance.titleBarCenter);884 /**885 * The element to the left of the title.886 * @name Dialog.titleBarLeft887 * @memberOf Rendition.UI.Dialog.prototype888 * @type Native.DHTMLElement889 * @private890 * @property891 * @readOnly892 */893 instance.titleBarLeft = document.createElement('div');894 instance.titleBarLeft.style.position = 'absolute';895 instance.dialog.appendChild(instance.titleBarLeft);896 /**897 * The element to the right of the title.898 * @name Dialog.titleBarRight899 * @memberOf Rendition.UI.Dialog.prototype900 * @type Native.DHTMLElement901 * @private902 * @property903 * @readOnly904 */905 instance.titleBarRight = document.createElement('div');906 instance.titleBarRight.style.position = 'absolute';907 instance.dialog.appendChild(instance.titleBarRight);908 /**909 * The element that holds the title textNode.910 * @name Dialog.titleBarText911 * @memberOf Rendition.UI.Dialog.prototype912 * @type Native.DHTMLElement913 * @private914 * @property915 * @readOnly916 */917 instance.titleBarText = document.createElement('div');918 instance.titleBarText.appendChild(instance.titleTextNode);919 instance.titleBarText.style.cursor = 'default';920 instance.titleBarText.style.position = 'absolute';921 instance.titleBarCenter.appendChild(instance.titleBarText);922 if (typeof instance.titleBarText.style.MozUserSelect != 'undefined') {923 instance.titleBarCenter.style.MozUserSelect = 'none';924 instance.titleBarText.style.MozUserSelect = 'none';925 } else {926 instance.titleBarCenter.onselectstart = function () { return false; }927 instance.titleBarText.onselectstart = function () { return false; }928 }929 /**930 * Center of the status bar.931 * @name Dialog.statusBarCenter932 * @memberOf Rendition.UI.Dialog.prototype933 * @type Native.DHTMLElement934 * @private935 * @property936 * @readOnly937 */938 instance.statusBarCenter = document.createElement('div');939 instance.statusBarCenter.style.position = 'absolute';940 instance.dialog.appendChild(instance.statusBarCenter);941 /**942 * Left of the status bar.943 * @name Dialog.statusBarLeft944 * @memberOf Rendition.UI.Dialog.prototype945 * @type Native.DHTMLElement946 * @private947 * @property948 * @readOnly949 */950 instance.statusBarLeft = document.createElement('div');951 instance.statusBarLeft.style.position = 'absolute';952 instance.dialog.appendChild(instance.statusBarLeft);953 /**954 * Right of the status bar.955 * @name Dialog.statusBarRight956 * @memberOf Rendition.UI.Dialog.prototype957 * @type Native.DHTMLElement958 * @private959 * @property960 * @readOnly961 */962 instance.statusBarRight = document.createElement('div');963 instance.statusBarRight.style.position = 'absolute';964 instance.dialog.appendChild(instance.statusBarRight);965 if (!instance.modal || instance.modalCloseable) {966 /**967 * Close button.968 * @name Dialog.closeButton969 * @memberOf Rendition.UI.Dialog.prototype970 * @type Native.DHTMLElement971 * @private972 * @property973 * @readOnly974 */975 instance.closeButton = document.createElement('button');976 instance.closeButton.style.position = 'absolute';977 instance.titleBarCenter.appendChild(instance.closeButton);978 }979 if (!instance.modal) {980 /**981 * Maximize button.982 * @name Dialog.maxButton983 * @memberOf Rendition.UI.Dialog.prototype984 * @type Native.DHTMLElement985 * @private986 * @property987 * @readOnly988 */989 instance.maxButton = document.createElement('button');990 instance.maxButton.style.position = 'absolute';991 instance.titleBarCenter.appendChild(instance.maxButton);992 /**993 * Restore button.994 * @name Dialog.restoreButton995 * @memberOf Rendition.UI.Dialog.prototype996 * @type Native.DHTMLElement997 * @private998 * @property999 * @readOnly1000 */1001 instance.restoreButton = document.createElement('button');1002 instance.restoreButton.style.position = 'absolute';1003 instance.restoreButton.style.visibility = 'hidden';1004 instance.restoreButton.style.display = 'none';1005 instance.titleBarCenter.appendChild(instance.restoreButton);1006 /**1007 * Minimize button.1008 * @name Dialog.minButton1009 * @memberOf Rendition.UI.Dialog.prototype1010 * @type Native.DHTMLElement1011 * @private1012 * @property1013 * @readOnly1014 */1015 instance.minButton = document.createElement('button');1016 instance.minButton.style.position = 'absolute';1017 instance.titleBarCenter.appendChild(instance.minButton);1018 }1019 /**1020 * The top border element.1021 * @name Dialog.n1022 * @memberOf Rendition.UI.Dialog.prototype1023 * @type Native.DHTMLElement1024 * @private1025 * @property1026 * @readOnly1027 */1028 instance.n = document.createElement('div');1029 instance.n.style.cursor = 'n-resize';1030 instance.n.onmousedown = function () { return false }1031 instance.n.style.position = 'absolute';1032 instance.dialog.appendChild(instance.n);1033 /**1034 * The right border element.1035 * @name Dialog.e1036 * @memberOf Rendition.UI.Dialog.prototype1037 * @type Native.DHTMLElement1038 * @private1039 * @property1040 * @readOnly1041 */1042 instance.e = document.createElement('div');1043 instance.e.style.cursor = 'e-resize';1044 instance.e.onmousedown = function () { return false }1045 instance.e.style.position = 'absolute';1046 instance.dialog.appendChild(instance.e);1047 /**1048 * The left border element.1049 * @name Dialog.w1050 * @memberOf Rendition.UI.Dialog.prototype1051 * @type Native.DHTMLElement1052 * @private1053 * @property1054 * @readOnly1055 */1056 instance.w = document.createElement('div');1057 instance.w.style.cursor = 'e-resize';1058 instance.w.onmousedown = function () { return false }1059 instance.w.style.position = 'absolute';1060 instance.dialog.appendChild(instance.w);1061 /**1062 * The bottom border element.1063 * @name Dialog.s1064 * @memberOf Rendition.UI.Dialog.prototype1065 * @type Native.DHTMLElement1066 * @private1067 * @property1068 * @readOnly1069 */1070 instance.s = document.createElement('div');1071 instance.s.style.cursor = 'n-resize';1072 instance.s.onmousedown = function () { return false }1073 instance.s.style.position = 'absolute';1074 instance.dialog.appendChild(instance.s);1075 /**1076 * The top left border element.1077 * @name Dialog.nw1078 * @memberOf Rendition.UI.Dialog.prototype1079 * @type Native.DHTMLElement1080 * @private1081 * @property1082 * @readOnly1083 */1084 instance.nw = document.createElement('div');1085 instance.nw.style.cursor = 'nw-resize';1086 instance.nw.onmousedown = function () { return false }1087 instance.nw.style.position = 'absolute';1088 instance.dialog.appendChild(instance.nw);1089 /**1090 * The top right border element.1091 * @name Dialog.ne1092 * @memberOf Rendition.UI.Dialog.prototype1093 * @type Native.DHTMLElement1094 * @private1095 * @property1096 * @readOnly1097 */1098 instance.ne = document.createElement('div');1099 instance.ne.style.cursor = 'ne-resize';1100 instance.ne.onmousedown = function () { return false }1101 instance.ne.style.position = 'absolute';1102 instance.dialog.appendChild(instance.ne);1103 /**1104 * The bottom right border element.1105 * @name Dialog.se1106 * @memberOf Rendition.UI.Dialog.prototype1107 * @type Native.DHTMLElement1108 * @private1109 * @property1110 * @readOnly1111 */1112 instance.se = document.createElement('div');1113 instance.se.style.cursor = 'nw-resize';1114 instance.se.onmousedown = function () { return false }1115 instance.se.style.position = 'absolute';1116 instance.dialog.appendChild(instance.se);1117 /**1118 * The bottom left element.1119 * @name Dialog.sw1120 * @memberOf Rendition.UI.Dialog.prototype1121 * @type Native.DHTMLElement1122 * @private1123 * @property1124 * @readOnly1125 */1126 instance.sw = document.createElement('div');1127 instance.sw.style.cursor = 'ne-resize';1128 instance.sw.onmousedown = function () { return false }1129 instance.sw.style.position = 'absolute';1130 instance.dialog.appendChild(instance.sw);1131 Rendition.UI.appendEvent('mousedown', instance.titleBarCenter, instance.startMoveDialog, false);1132 if (!instance.modal || instance.modalCloseable) {1133 Rendition.UI.appendEvent('mousedown', instance.closeButton, instance.beginButtonEvent, true);1134 Rendition.UI.appendEvent('click', instance.closeButton, instance.close, false);1135 }1136 if (!instance.modal) {1137 Rendition.UI.appendEvent('mousedown', instance.minButton, instance.beginButtonEvent, true);1138 Rendition.UI.appendEvent('click', instance.minButton, instance.minimize, false);1139 Rendition.UI.appendEvent('mousedown', instance.restoreButton, instance.beginButtonEvent, true);1140 Rendition.UI.appendEvent('click', instance.restoreButton, instance.unmaximize, false);1141 Rendition.UI.appendEvent('mousedown', instance.maxButton, instance.beginButtonEvent, true);1142 Rendition.UI.appendEvent('click', instance.maxButton, instance.maximize, false);1143 }1144 Rendition.UI.appendEvent('mousedown', instance.n, function (ev) {1145 instance.getResizeArrays(ev, instance.n);1146 Rendition.UI.appendEvent('mousemove', document.documentElement, instance.resizeDialog, true);1147 return false;1148 }, true);1149 Rendition.UI.appendEvent('mousedown', instance.s, function (ev) {1150 instance.getResizeArrays(ev, instance.s);1151 Rendition.UI.appendEvent('mousemove', document.documentElement, instance.resizeDialog, true);1152 return false;1153 }, true);1154 Rendition.UI.appendEvent('mousedown', instance.e, function (ev) {1155 instance.getResizeArrays(ev, instance.e);1156 instance.mouseOffset.x = instance.mouseOffset.x - instance.style.eRect.w;1157 Rendition.UI.appendEvent('mousemove', document.documentElement, instance.resizeDialog, true);1158 return false;1159 }, true);1160 Rendition.UI.appendEvent('mousedown', instance.w, function (ev) {1161 instance.getResizeArrays(ev, instance.w);1162 Rendition.UI.appendEvent('mousemove', document.documentElement, instance.resizeDialog, true);1163 return false;1164 }, true);1165 Rendition.UI.appendEvent('mousedown', instance.nw, function (ev) {1166 instance.getResizeArrays(ev, instance.nw);1167 Rendition.UI.appendEvent('mousemove', document.documentElement, instance.resizeDialog, true);1168 return false;1169 }, true);1170 Rendition.UI.appendEvent('mousedown', instance.ne, function (ev) {1171 instance.getResizeArrays(ev, instance.ne);1172 instance.mouseOffset.x = instance.mouseOffset.x - instance.style.neRect.w;1173 Rendition.UI.appendEvent('mousemove', document.documentElement, instance.resizeDialog, true);1174 return false;1175 }, true);1176 Rendition.UI.appendEvent('mousedown', instance.se, function (ev) {1177 instance.getResizeArrays(ev, instance.se);1178 instance.mouseOffset.x = instance.mouseOffset.x - instance.style.seRect.w;1179 instance.mouseOffset.y = instance.mouseOffset.y - instance.style.seRect.h;1180 Rendition.UI.appendEvent('mousemove', document.documentElement, instance.resizeDialog, true);1181 return false;1182 }, true);1183 Rendition.UI.appendEvent('mousedown', instance.sw, function (ev) {1184 instance.getResizeArrays(ev, instance.sw);1185 instance.mouseOffset.y = instance.mouseOffset.y - instance.style.swRect.h;1186 Rendition.UI.appendEvent('mousemove', document.documentElement, instance.resizeDialog, true);1187 return false;1188 }, true);1189 if (!instance.modal) {1190 instance.minButton.blur = function () {1191 return false;1192 }1193 instance.minButton.hover = function () {1194 return false;1195 }1196 Rendition.UI.appendEvent('mouseover', instance.minButton, instance.mousehover = function () {1197 Rendition.UI.hover(instance.minButton);1198 }, false);1199 Rendition.UI.appendEvent('mouseout', instance.minButton, instance.mousehover = function () {1200 instance.minButton.blur();1201 }, false);1202 }1203 instance.title(args.title);1204 instance.applyStyle();1205 if (instance.hidden) {1206 instance.hide();1207 }1208 if (instance.desktop) {1209 instance.desktop.addDialogWindow(instance);1210 } else {1211 Rendition.UI.dialogs.push(instance);1212 document.body.appendChild(instance.dialog);1213 document.body.appendChild(instance.preview);1214 if (instance.modal) {1215 document.body.appendChild(instance.modalBackground);1216 }1217 Rendition.UI.refreshTaskBars();1218 }1219 return instance;1220 }1221 /**1222 * Used interally to prevent dialog movments when the control boxes are used.1223 * @function1224 * @name Dialog.beginButtonEvent1225 * @memberOf Rendition.UI.Dialog.prototype1226 * @private1227 * @memberOf Rendition.UI.Dialog.prototype1228 */1229 instance.beginButtonEvent = function () {1230 instance.buttonEventOccuring = true;1231 instance.buttonEventOccuringProc = function () {1232 instance.buttonEventOccuring = false;1233 Rendition.UI.removeEvent('mouseup', document.documentElement, instance.buttonEventOccuringProc, true);1234 }1235 Rendition.UI.appendEvent('mouseup', document.documentElement, instance.buttonEventOccuringProc, true);1236 }1237 /**1238 * Used interally to process the end of move events.1239 * @function1240 * @name Dialog.stopMoving1241 * @memberOf Rendition.UI.Dialog.prototype1242 * @private1243 * @memberOf Rendition.UI.Dialog.prototype1244 */1245 instance.stopMoving = function () {1246 instance.preview.style.visibility = 'hidden';1247 instance.preview.style.display = 'none';1248 instance.dialog.style.left = instance.rect.x + 'px';1249 instance.dialog.style.top = instance.rect.y + 'px';1250 Rendition.UI.removeEvent('mousemove', document.documentElement, instance.moveDialog, true);1251 Rendition.UI.removeEvent('mouseup', document.documentElement, instance.stopMoving, true);1252 instance.eventlisteners_finishedMove(null);1253 }1254 /**1255 * Used interally to process the start moving events.1256 * @function1257 * @name Dialog.startMoveDialog1258 * @memberOf Rendition.UI.Dialog.prototype1259 * @private1260 * @returns {Native.Boolean} false.1261 * @param {Native.Object} ev The event object.1262 * @memberOf Rendition.UI.Dialog.prototype1263 */1264 instance.startMoveDialog = function (ev) {1265 if ((!instance.closed) && (!instance.buttonEventOccuring)) {1266 instance.mouseOffset = Rendition.UI.getMouseOffset(instance.titleBarCenter, ev);1267 instance.mouseOffset.x = instance.mouseOffset.x + instance.style.titleLeftRect.w + instance.style.titleCenterRect.x;1268 instance.mouseOffset.y = instance.mouseOffset.y + instance.style.titleCenterRect.y;1269 instance.previewRect = instance.rect;1270 instance.preview.style.left = instance.previewRect.x + 'px';1271 instance.preview.style.top = instance.previewRect.y + 'px';1272 instance.preview.style.width = instance.previewRect.w + 'px';1273 instance.preview.style.height = instance.previewRect.h + 'px';1274 Rendition.UI.appendEvent('mousemove', document.documentElement, instance.moveDialog, true);1275 Rendition.UI.appendEvent('mouseup', document.documentElement, instance.stopMoving, true);1276 instance.eventlisteners_startingMove(ev);1277 }1278 return false;1279 }1280 /**1281 * Used interally to process moving the dialog.1282 * @function1283 * @name Dialog.moveDialog1284 * @memberOf Rendition.UI.Dialog.prototype1285 * @private1286 * @returns {Native.Boolean} false.1287 * @param {Native.Object} ev The event object.1288 * @memberOf Rendition.UI.Dialog.prototype1289 */1290 instance.moveDialog = function (ev) {1291 if ((instance.mouseOffset.x < 2 && instance.mouseOffset.y < 2) || instance.windowState == 1) { return false }1292 var mousePos = Rendition.UI.mouseCoords(ev);1293 instance.preview.style.display = 'block';1294 instance.preview.style.visibility = 'visible';1295 instance.rect.x = mousePos.x - instance.mouseOffset.x;1296 instance.rect.y = mousePos.y - instance.mouseOffset.y;1297 instance.previewRect = instance.rect;1298 instance.preview.style.top = instance.previewRect.y + 'px';1299 instance.preview.style.left = instance.previewRect.x + 'px';1300 instance.eventlisteners_move(ev);1301 return false;1302 }1303 /**1304 * Used to check if the dialog is still alive and a decendant of the body.1305 * @function1306 * @name Dialog.alive1307 * @memberOf Rendition.UI.Dialog.prototype1308 * @public1309 * @returns {Native.Boolean} false.1310 * @memberOf Rendition.UI.Dialog.prototype1311 */1312 instance.alive = function () {1313 e = instance.dialog.parentNode;1314 while (e) {1315 if (e.tagName.toLowerCase() == 'body') {1316 return true;1317 }1318 e = e.parentNode;1319 }1320 return false;1321 }1322 /**1323 * Used interally apply all the CSS commands to the dialogs DHTML elements.1324 * @function1325 * @name Dialog.applyStyle1326 * @memberOf Rendition.UI.Dialog.prototype1327 * @private1328 * @memberOf Rendition.UI.Dialog.prototype1329 */1330 instance.applyStyle = function () {1331 instance.dialog.style.boxShadow = instance.style.boxShadow;1332 instance.titleBarCenter.style.top = instance.style.titleCenterRect.y + 'px';1333 instance.titleBarCenter.style.left = instance.style.titleCenterRect.x + instance.style.titleLeftRect.w + 'px';1334 instance.titleBarCenter.style.height = instance.style.titleCenterRect.h + 'px';1335 instance.titleBarCenter.style.background = instance.style.titleCenterBackground;1336 instance.titleBarLeft.style.top = instance.style.titleLeftRect.y + 'px';1337 instance.titleBarLeft.style.left = instance.style.titleLeftRect.x + 'px';1338 instance.titleBarLeft.style.height = instance.style.titleLeftRect.h + 'px';1339 instance.titleBarLeft.style.width = instance.style.titleLeftRect.w + 'px';1340 instance.titleBarLeft.style.background = instance.style.titleLeftBackground;1341 instance.titleBarRight.style.top = instance.style.titleRightRect.y + 'px';1342 instance.titleBarRight.style.height = instance.style.titleRightRect.h + 'px';1343 instance.titleBarRight.style.width = instance.style.titleRightRect.w + 'px';1344 instance.titleBarRight.style.background = instance.style.titleRightBackground;1345 instance.titleBarText.style.left = instance.style.titleTextRect.x + 'px';1346 instance.titleBarText.style.top = instance.style.titleTextRect.y + 'px';1347 instance.titleBarText.style.height = instance.style.titleTextRect.h + 'px';1348 instance.titleBarText.style.font = instance.style.titleFont;1349 instance.titleBarText.style.color = instance.style.titleColor;1350 instance.titleBarText.style.textAlign = instance.style.titleTextAlignment;1351 if (!instance.modal) {1352 instance.minButton.style.background = instance.style.minBackground;1353 instance.minButton.style.border = instance.style.minBorder;1354 instance.minButton.style.height = instance.style.minRect.h + 'px';1355 instance.minButton.style.width = instance.style.minRect.w + 'px';1356 instance.minButton.style.top = instance.style.minRect.y + 'px';1357 instance.restoreButton.style.background = instance.style.restoreBackground;1358 instance.restoreButton.style.border = instance.style.restoreBorder;1359 instance.restoreButton.style.height = instance.style.restoreRect.h + 'px';1360 instance.restoreButton.style.width = instance.style.restoreRect.w + 'px';1361 instance.restoreButton.style.top = instance.style.restoreRect.y + 'px';1362 instance.maxButton.style.background = instance.style.maxBackground;1363 instance.maxButton.style.border = instance.style.maxBorder;1364 instance.maxButton.style.height = instance.style.maxRect.h + 'px';1365 instance.maxButton.style.width = instance.style.maxRect.w + 'px';1366 instance.maxButton.style.top = instance.style.maxRect.y + 'px';1367 }1368 if (instance.modalCloseable || !instance.modal) {1369 instance.closeButton.style.background = instance.style.closeBackground;1370 instance.closeButton.style.border = instance.style.closeBorder;1371 instance.closeButton.style.height = instance.style.closeRect.h + 'px';1372 instance.closeButton.style.width = instance.style.closeRect.w + 'px';1373 instance.closeButton.style.top = instance.style.closeRect.y + 'px';1374 }1375 instance.preview.style.background = instance.style.previewBackground;1376 instance.dialog.style.background = instance.style.dialogBackground;1377 instance.content.style.left = instance.style.contentRect.x + 'px';1378 instance.content.style.backgroundColor = instance.style.contentBackground;1379 instance.statusBarRight.style.height = instance.style.statusBarRightRect.h + 'px';1380 instance.statusBarRight.style.width = instance.style.statusBarRightRect.w + 'px';1381 instance.statusBarRight.style.background = instance.style.statusBarRightBackground;1382 instance.statusBarLeft.style.left = instance.style.statusBarLeftRect.x + 'px';1383 instance.statusBarLeft.style.height = instance.style.statusBarLeftRect.h + 'px';1384 instance.statusBarLeft.style.width = instance.style.statusBarLeftRect.w + 'px';1385 instance.statusBarLeft.style.background = instance.style.statusBarLeftBackground;1386 instance.statusBarCenter.style.left = instance.style.statusBarCenterRect.x + instance.style.statusBarLeftRect.w + 'px';1387 instance.statusBarCenter.style.height = instance.style.statusBarCenterRect.h + 'px';1388 instance.statusBarCenter.style.background = instance.style.statusBarCenterBackground;1389 instance.n.style.background = instance.style.nBackground;1390 instance.n.style.height = instance.style.nRect.h + 'px';1391 instance.e.style.background = instance.style.eBackground;1392 instance.e.style.width = instance.style.eRect.w + 'px';1393 instance.w.style.background = instance.style.wBackground;1394 instance.w.style.width = instance.style.wRect.w + 'px';1395 instance.s.style.background = instance.style.sBackground;1396 instance.s.style.height = instance.style.sRect.h + 'px';1397 instance.nw.style.background = instance.style.nwBackground;1398 instance.nw.style.height = instance.style.nwRect.h + 'px';1399 instance.nw.style.width = instance.style.nwRect.w + 'px';1400 instance.ne.style.background = instance.style.neBackground;1401 instance.ne.style.height = instance.style.neRect.h + 'px';1402 instance.ne.style.width = instance.style.neRect.w + 'px';1403 instance.se.style.background = instance.style.seBackground;1404 instance.se.style.height = instance.style.seRect.h + 'px';1405 instance.se.style.width = instance.style.seRect.w + 'px';1406 instance.sw.style.background = instance.style.swBackground;1407 instance.sw.style.height = instance.style.swRect.h + 'px';1408 instance.sw.style.width = instance.style.swRect.w + 'px';1409 instance.e.style.top = instance.style.eRect.y + 'px';1410 instance.w.style.top = instance.style.wRect.y + 'px';1411 instance.w.style.left = instance.style.wRect.x + 'px';1412 instance.s.style.left = instance.style.sRect.x + 'px';1413 instance.nw.style.top = instance.style.nwRect.y + 'px';1414 instance.nw.style.left = instance.style.nwRect.x + 'px';1415 instance.ne.style.top = instance.style.neRect.y + 'px';1416 instance.n.style.top = instance.style.nRect.y + 'px';1417 instance.n.style.left = instance.style.nRect.x + 'px';1418 instance.sw.style.left = instance.style.swRect.x + 'px';1419 instance.updateRect(instance.rect);1420 return;1421 }1422 /**1423 * Automaticaly resize the dialog height to fit its content, optionally with the specified width or 90% of the client width.1424 * @function1425 * @name Dialog.autosize1426 * @memberOf Rendition.UI.Dialog.prototype1427 * @public1428 * @returns {Native.Boolean} false.1429 * @param {Native.Integer} [width=90% of the client width] Dialog width.1430 * @param {Native.Boolean} [makeYScroll] Cause the dialogs content area to have a scrollbar.1431 * @memberOf Rendition.UI.Dialog.prototype1432 */1433 instance.autosize = function (width, makeYScroll) {1434 if (instance.content.firstChild) {1435 var e = instance.content.firstChild;1436 var height = 0;1437 width = width || (document.documentElement.clientWidth * .9);1438 instance.updateRect({1439 h: 250,1440 w: instance.rect.w,1441 x: -1000,1442 y: -10001443 });1444 while (e) {1445 if (e.offsetLeft < 10) {1446 height += e.offsetHeight;1447 }1448 e = e.nextSibling;1449 }1450 height += instance.style.statusBarCenterRect.h;1451 height += instance.style.titleCenterRect.h + instance.style.titleCenterRect.y;1452 if (height > document.documentElement.clientHeight - 50) {1453 height = document.documentElement.clientHeight - 50;1454 makeYScroll = true;1455 }1456 if (makeYScroll) {1457 instance.content.style.overflow = 'hidden';1458 instance.content.style.overflowX = 'hidden';1459 instance.content.style.overflowY = 'scroll';1460 }1461 rect = {1462 w: width,1463 h: height + 30,1464 x: (document.documentElement.clientWidth * .5 - (width * .5)),1465 y: (document.documentElement.clientHeight * .4 - (height * .5))1466 }1467 instance.updateRect(rect);1468 }1469 return instance;1470 }1471 /**1472 * Minimizes the dialog.1473 * @function1474 * @name Dialog.minimize1475 * @memberOf Rendition.UI.Dialog.prototype1476 * @public1477 * @returns {Native.Object} dialog.1478 * @param {Native.Object} [e] The event object.1479 */1480 instance.minimize = function (e) {1481 instance.previousState = instance.windowState;1482 instance.windowState = 2;1483 instance.dialog.style.visibility = 'hidden';1484 instance.dialog.style.display = 'none';1485 instance.eventlisteners_minimize(null);1486 if (e !== undefined) {1487 e.cancelBubble = true;1488 }1489 return instance;1490 }1491 /**1492 * Activate the dialog. Brings the dialog to the top of the stack of dialogs. Threre are two sets of dialog stacks. The 'alwaysOnTop' stack and the normal stack. The always on top stack is always on top of the normal stack.1493 * @function1494 * @name Dialog.activate1495 * @memberOf Rendition.UI.Dialog.prototype1496 * @public1497 * @returns {Native.Object} dialog.1498 */1499 instance.activate = function () {1500 Rendition.UI.activeWindow = instance;1501 if (instance.windowState == 2) {1502 instance.restore();1503 }1504 if (parseInt(instance.dialog.style.zIndex) < Rendition.UI.topzindex) {1505 if (instance.modal || instance.alwaysOnTop) {1506 instance.dialog.style.zIndex = Rendition.UI.topModalzindex + 1; Rendition.UI.topModalzindex++;1507 } else {1508 instance.dialog.style.zIndex = Rendition.UI.topzindex + 1; Rendition.UI.topzindex++;1509 }1510 }1511 instance.eventlisteners_activate(null);1512 return instance;1513 }1514 /**1515 * Hides the dialog by moving it to top:-10,000px, left:-10,000px so even the largest dialogs will be hidden but still in the DOM and visible for functions to execute on the visible elements in the content area of the dialog.1516 * @function1517 * @name Dialog.hide1518 * @memberOf Rendition.UI.Dialog.prototype1519 * @public1520 * @returns {Native.Object} dialog.1521 */1522 instance.hide = function () {1523 instance.dialog.style.top = '-10000px';1524 instance.dialog.style.left = '-10000px';1525 if (instance.modal) {1526 instance.modalBackground.style.visibility = 'hidden';1527 instance.modalBackground.style.display = 'none';1528 }1529 Rendition.UI.dialogs.splice(instance.index, 1);1530 Rendition.UI.refreshTaskBars();1531 instance.eventlisteners_hide(null);1532 return instance;1533 }1534 /**1535 * Shows the dialog if it was in hidden mode by returning it to its previous position.1536 * @function1537 * @name Dialog.show1538 * @memberOf Rendition.UI.Dialog.prototype1539 * @public1540 * @returns {Native.Object} dialog.1541 */1542 instance.show = function () {1543 instance.dialog.style.top = instance.rect.y + 'px';1544 instance.dialog.style.left = instance.rect.x + 'px';1545 if (instance.modal) {1546 instance.modalBackground.style.visibility = 'visible';1547 instance.modalBackground.style.display = 'block';1548 }1549 instance.index = Rendition.UI.dialogs.length;1550 Rendition.UI.dialogs.push(instance);1551 Rendition.UI.refreshTaskBars();1552 instance.eventlisteners_show(null);1553 return instance;1554 }1555 /**1556 * Closes the dialog optionally firing a callback procedure.1557 * @function1558 * @name Dialog.close1559 * @memberOf Rendition.UI.Dialog.prototype1560 * @public1561 * @param {Native.Function} callbackProcedure The procedure to apply after the dialog has closed.1562 */1563 instance.close = function (callbackProcedure) {1564 if (instance.closed) { return null }1565 if (!instance.eventlisteners_close(null)) { return instance }1566 instance.closed = true;1567 if (instance.modal) {1568 try {1569 Rendition.UI.removeEvent('resize', window, instance.resizeModalBackground, false);1570 instance.modalBackground.parentNode.removeChild(instance.modalBackground);1571 } catch (e) {1572 }1573 }1574 if (instance.dialog.parentNode) {1575 instance.dialog.parentNode.removeChild(instance.dialog);1576 }1577 Rendition.UI.dialogs.splice(instance.index, 1);1578 Rendition.UI.refreshTaskBars();1579 if (typeof callbackProcedure == 'function') {1580 callbackProcedure.apply(instance, []);1581 }1582 return;1583 }1584 /**1585 * Restores the dialog.1586 * @function1587 * @name Dialog.restore1588 * @memberOf Rendition.UI.Dialog.prototype1589 * @public1590 * @returns {Native.Object} dialog.1591 */1592 instance.restore = function () {1593 instance.windowState = instance.previousState;1594 instance.dialog.style.visibility = 'visible';1595 instance.dialog.style.display = 'block';1596 instance.eventlisteners_restore(null);1597 return instance;1598 }1599 /**1600 * Restores the dialog by taking it out of maximize mode.1601 * @function1602 * @name Dialog.unmaximize1603 * @memberOf Rendition.UI.Dialog.prototype1604 * @public1605 * @returns {Native.Object} dialog.1606 */1607 instance.unmaximize = function () {1608 instance.windowState = 0;1609 instance.restoreButton.style.visibility = 'hidden';1610 instance.restoreButton.style.display = 'none';1611 instance.maxButton.style.visibility = 'visible';1612 instance.maxButton.style.display = 'block';1613 instance.rect = instance.previousRect;1614 instance.updateRect(instance.rect);1615 Rendition.UI.removeEvent('resize', window, instance.resizeWithWindow, false);1616 instance.eventlisteners_restore(null);1617 return instance;1618 }1619 /**1620 * Maximizes the dialog by matching the border to the dimentions of the client rectangle. When the client rectangle is updated the dialog will change dimentions to match the new client rectangle.1621 * @function1622 * @name Dialog.maximize1623 * @memberOf Rendition.UI.Dialog.prototype1624 * @public1625 * @returns {Native.Object} dialog.1626 */1627 instance.maximize = function () {1628 instance.previousRect = Rendition.UI.getRect(instance.dialog);1629 instance.previousState = instance.windowState;1630 instance.windowState = 1;1631 if (instance.modalCloseable || !instance.modal) {1632 instance.maxButton.style.visibility = 'hidden';1633 instance.maxButton.style.display = 'none';1634 instance.restoreButton.style.visibility = 'visible';1635 instance.restoreButton.style.display = 'block';1636 }1637 instance.updateRect(instance.rect);1638 Rendition.UI.appendEvent('resize', window, instance.resizeWithWindow = function (ev) { instance.updateRect(instance.rect) }, false);1639 instance.eventlisteners_maximize(null);1640 return instance;1641 }1642 /**1643 * Checks to see if this dialog is the topmost dialog.1644 * @function1645 * @name Dialog.isTopmostWindow1646 * @memberOf Rendition.UI.Dialog.prototype1647 * @public1648 * @returns {Native.Boolean} If true this dialog is the topmost dialog.1649 */1650 instance.isTopmostWindow = function () {1651 bolReturn = false;1652 var topIndex = 0;1653 var winLength = Rendition.UI.dialogs.length;1654 for (var x = 0; x < winLength; x++) {1655 var intIndex = parseInt(Rendition.UI.dialogs[x].dialog.style.zIndex);1656 if (topIndex < intIndex) {1657 topIndex = intIndex;1658 }1659 }1660 if (parseInt(instance.dialog.style.zIndex) == topIndex) {1661 bolReturn = true;1662 }1663 return bolReturn;1664 }1665 /**1666 * Used interally to resize the dialog.1667 * @function1668 * @name Dialog.resizeDialog1669 * @memberOf Rendition.UI.Dialog.prototype1670 * @private1671 * @param {Native.Object} ev The event object.1672 */1673 instance.resizeDialog = function (ev) {1674 if (!instance.resizeable) { return null }1675 instance.preview.style.display = 'block';1676 instance.preview.style.visibility = 'visible';1677 var mousePos = Rendition.UI.mouseCoords(ev);1678 var newRect = { x: null, y: null, h: null, w: null }1679 if (instance.resizeObject == instance.n) {1680 newRect.y = mousePos.y - instance.mouseOffset.y;1681 newRect.h = instance.resizeOffset.y - newRect.y + instance.resizeOffset.h;1682 newRect.w = null;1683 newRect.x = null;1684 } else if (instance.resizeObject == instance.w) {1685 newRect.x = mousePos.x - instance.mouseOffset.x;1686 newRect.w = instance.resizeOffset.x - newRect.x + instance.resizeOffset.w;1687 newRect.y = null;1688 newRect.h = null;1689 } else if (instance.resizeObject == instance.e) {1690 newRect.x = mousePos.x - instance.mouseOffset.x;1691 newRect.w = instance.resizeOffset.x - (newRect.x * -1) - instance.resizeOffset.x - instance.resizeOffset.x;1692 newRect.x = null;1693 newRect.y = null;1694 newRect.h = null;1695 } else if (instance.resizeObject == instance.s) {1696 newRect.y = mousePos.y - instance.mouseOffset.y;1697 newRect.h = instance.resizeOffset.y - (newRect.y * -1) - instance.resizeOffset.y - instance.resizeOffset.y;1698 newRect.x = null;1699 newRect.y = null;1700 newRect.w = null;1701 } else if (instance.resizeObject == instance.ne) {1702 newRect.x = mousePos.x - instance.mouseOffset.x;1703 newRect.y = mousePos.y - instance.mouseOffset.y;1704 newRect.w = instance.resizeOffset.x - (newRect.x * -1) - instance.resizeOffset.x - instance.resizeOffset.x;1705 newRect.h = (instance.resizeOffset.y - newRect.y) + instance.resizeOffset.h;1706 newRect.x = null;1707 } else if (instance.resizeObject == instance.se) {1708 newRect.x = mousePos.x - instance.mouseOffset.x;1709 newRect.y = mousePos.y - instance.mouseOffset.y;1710 newRect.w = instance.resizeOffset.x - (newRect.x * -1) - instance.resizeOffset.x - instance.resizeOffset.x;1711 newRect.h = instance.resizeOffset.y - (newRect.y * -1) - instance.resizeOffset.y - instance.resizeOffset.y;1712 newRect.x = null;1713 newRect.y = null;1714 } else if (instance.resizeObject == instance.sw) {1715 newRect.x = mousePos.x - instance.mouseOffset.x;1716 newRect.y = mousePos.y - instance.mouseOffset.y;1717 newRect.w = instance.resizeOffset.x - newRect.x + instance.resizeOffset.w;1718 newRect.h = instance.resizeOffset.y - (newRect.y * -1) - instance.resizeOffset.y - instance.resizeOffset.y;1719 newRect.y = null;1720 } else if (instance.resizeObject == instance.nw) {1721 newRect.x = mousePos.x - instance.mouseOffset.x;1722 newRect.y = mousePos.y - instance.mouseOffset.y;1723 newRect.w = instance.resizeOffset.x - newRect.x + instance.resizeOffset.w;1724 newRect.h = instance.resizeOffset.y - newRect.y + instance.resizeOffset.h;1725 }1726 instance.setDialogSize(newRect);1727 return;1728 }1729 /**1730 * Sets the dialog to a new size or fires off the resize events using the current rectangle.1731 * @function1732 * @name Dialog.setDialogSize1733 * @memberOf Rendition.UI.Dialog.prototype1734 * @public1735 * @param {Native.Object} [newRect] The new rectangle size to set the dialog to. Like {x:Integer,y:Integer,h:Integer,w:Integer}.1736 */1737 instance.setDialogSize = function (newRect) {1738 var rect = { x: null, y: null, h: null, w: null }1739 var oldRect = Rendition.UI.getRect(instance.dialog);1740 if (newRect.x) { if (newRect.x >= instance.style.minimumRect.x) { rect.x = newRect.x } } else { rect.x = oldRect.x }1741 if (newRect.y) { if (newRect.y >= instance.style.minimumRect.y) { rect.y = newRect.y } } else { rect.y = oldRect.y }1742 if (newRect.h) { if (newRect.h >= instance.style.minimumRect.h) { rect.h = newRect.h } } else { rect.h = oldRect.h }1743 if (newRect.w) { if (newRect.w >= instance.style.minimumRect.w) { rect.w = newRect.w } } else { rect.w = oldRect.w }1744 instance.previewRect = rect;1745 instance.preview.style.top = instance.previewRect.y + 'px';1746 instance.preview.style.left = instance.previewRect.x + 'px';1747 instance.preview.style.height = instance.previewRect.h + 'px';1748 instance.preview.style.width = instance.previewRect.w + 'px';1749 return;1750 }1751 /**1752 * Changes the title of the dialog.1753 * @function1754 * @name Dialog.title1755 * @memberOf Rendition.UI.Dialog.prototype1756 * @public1757 * @param {Native.String} newTitle The new title of the dialog.1758 */1759 instance.title = function (newTitle) {1760 var oldTitle = instance.titleValue;1761 if (newTitle) {1762 instance.titleValue = newTitle;1763 } else {1764 instance.titleValue = instance.originalTitleText;1765 }1766 if ((instance.titleValue.length * instance.style.charToPx) >1767 (instance.style.titleCenterRect.w + instance.rect.w - instance.style.titleLeftRect.w - instance.style.titleRightRect.w)) {1768 instance.titleTextNode.data = instance.titleValue.substring(0, instance.rect.w / instance.style.charToPx) + '...';1769 } else {1770 instance.titleTextNode.data = instance.titleValue;1771 if (instance.taskElement) {1772 instance.taskElement.updatetitle();1773 Rendition.UI.refreshTaskBars();1774 }1775 }1776 instance.eventlisteners_titleChanged([newTitle, oldTitle]);1777 return instance.titleValue;1778 }1779 /**1780 * Resize the dialog. Accepts one argument of type {Rendition.UI.Rect}.1781 * When no arguments are used the current instance's rect object is used.1782 * @function1783 * @name Dialog.updateRect1784 * @memberOf Rendition.UI.Dialog.prototype1785 * @public1786 * @returns {Native.Boolean} false.1787 * @param {Native.Object} ev The event object.1788 */1789 instance.updateRect = instance.resize = function (rect) {1790 if (rect !== undefined) {1791 instance.rect = rect;1792 } else {1793 rect = instance.rect;1794 }1795 var statusAdd = 0;1796 var tabAdd = 0;1797 var titleAdd = 0;1798 var menuAdd = 0;1799 statusAdd = instance.style.statusBarCenterRect.h;1800 titleAdd = instance.style.titleCenterRect.h + instance.style.titleCenterRect.y;1801 if (instance.windowState == 1) {1802 instance.rect.w = document.documentElement.clientWidth;1803 instance.rect.h = document.documentElement.clientHeight;1804 instance.rect.x = 0;1805 instance.rect.y = 0;1806 }1807 if ((instance.rect.x + 20) > document.documentElement.clientWidth) {1808 instance.rect.x = document.documentElement.clientWidth - (instance.rect.w / 2);1809 }1810 if ((instance.rect.y + 20) > document.documentElement.clientHeight) {1811 instance.rect.y = document.documentElement.clientHeight - (instance.rect.h / 2);1812 }1813 if (instance.rect.x >= instance.style.minimumRect.x) { instance.dialog.style.left = (instance.rect.x) + 'px'; }1814 if (instance.rect.y >= instance.style.minimumRect.y) { instance.dialog.style.top = (instance.rect.y) + 'px'; }1815 if (instance.rect.h >= instance.style.minimumRect.h) { instance.dialog.style.height = (instance.rect.h) + 'px'; }1816 if (instance.rect.w >= instance.style.minimumRect.w) { instance.dialog.style.width = (instance.rect.w) + 'px'; }1817 instance.title(instance.titleValue);1818 instance.contentRect = {1819 x: instance.style.contentRect.x,1820 y: (instance.style.contentRect.y + titleAdd + menuAdd),1821 h: (instance.rect.h + instance.style.contentRect.h - statusAdd - titleAdd - menuAdd),1822 w: (instance.rect.w + instance.style.contentRect.w)1823 }1824 instance.content.style.top = instance.contentRect.y + 'px';1825 instance.content.style.height = instance.contentRect.h + 'px';1826 instance.content.style.width = instance.contentRect.w + 'px';1827 instance.n.style.width = (instance.style.nRect.w + instance.rect.w) + 'px';1828 instance.e.style.height = (instance.style.eRect.h + instance.rect.h) + 'px';1829 instance.e.style.left = (instance.style.eRect.x + instance.rect.w - instance.style.eRect.w) + 'px';1830 instance.w.style.height = (instance.style.wRect.h + instance.rect.h) + 'px';1831 instance.s.style.width = (instance.style.sRect.w + instance.rect.w) + 'px';1832 instance.s.style.top = (instance.style.sRect.y + instance.rect.h - instance.style.sRect.h) + 'px';1833 instance.ne.style.left = (instance.style.neRect.x + instance.rect.w - instance.style.neRect.w) + 'px';1834 instance.se.style.top = (instance.style.seRect.y + instance.rect.h - instance.style.seRect.h) + 'px';1835 instance.se.style.left = (instance.style.seRect.x + instance.rect.w - instance.style.seRect.w) + 'px';1836 instance.sw.style.top = (instance.style.swRect.y + instance.rect.h - instance.style.swRect.h) + 'px';1837 instance.titleBarText.style.width = (instance.style.titleCenterRect.w + instance.rect.w - instance.style.titleLeftRect.w - instance.style.titleRightRect.w) + 'px';1838 instance.titleBarCenter.style.width = (instance.style.titleCenterRect.w + instance.rect.w - instance.style.titleLeftRect.w - instance.style.titleRightRect.w) + 'px';1839 instance.titleBarRight.style.left = (instance.style.titleRightRect.x + instance.rect.w - instance.style.titleRightRect.w) + 'px';1840 if (!instance.modal || instance.modalCloseable) {1841 instance.closeButton.style.left = (instance.style.closeRect.x + instance.rect.w) + 'px';1842 }1843 if (!instance.modal) {1844 instance.restoreButton.style.left = (instance.style.restoreRect.x + instance.rect.w) + 'px';1845 instance.maxButton.style.left = (instance.style.maxRect.x + instance.rect.w) + 'px';1846 instance.minButton.style.left = (instance.style.minRect.x + instance.rect.w) + 'px';1847 }1848 instance.statusBarCenter.style.top = (instance.style.statusBarCenterRect.y + instance.rect.h - instance.style.statusBarCenterRect.h) + 'px';1849 instance.statusBarCenter.style.width = (instance.style.statusBarCenterRect.w + instance.rect.w - instance.style.statusBarLeftRect.w - instance.style.statusBarRightRect.w) + 'px';1850 instance.statusBarLeft.style.top = (instance.style.statusBarLeftRect.y + instance.rect.h - instance.style.statusBarLeftRect.h) + 'px';1851 instance.statusBarRight.style.top = (instance.style.statusBarRightRect.y + instance.rect.h - instance.style.statusBarRightRect.h) + 'px';1852 instance.statusBarRight.style.left = (instance.style.statusBarRightRect.x + instance.rect.w - instance.style.statusBarRightRect.w) + 'px';1853 instance.eventlisteners_resize(null);1854 return;1855 }1856 /**1857 * Used interally handle the reisze mouse up events.1858 * @function1859 * @name Dialog.resizemouseup1860 * @memberOf Rendition.UI.Dialog.prototype1861 * @private1862 */1863 instance.resizemouseup = function () {1864 Rendition.UI.removeEvent('mousemove', document.documentElement, instance.resizeDialog, true);1865 Rendition.UI.removeEvent('mouseup', document.documentElement, instance.resizemouseup, true);1866 instance.updateRect(instance.previewRect);1867 document.documentElement.style.cursor = 'default';1868 instance.preview.style.visibility = 'hidden';1869 instance.preview.style.display = 'none';1870 instance.eventlisteners_finishedResize(null);1871 return;1872 }1873 /**1874 * Used interally handle the reisze mouse up events.1875 * @function1876 * @name Dialog.getResizeArrays1877 * @memberOf Rendition.UI.Dialog.prototype1878 * @private1879 * @param {Native.Object} ev The event object.1880 * @param {Native.DHTMLElement} obj The object related to this event.1881 */1882 instance.getResizeArrays = function (ev, obj) {1883 document.documentElement.style.cursor = obj.style.cursor;1884 Rendition.UI.appendEvent('mouseup', document.documentElement, instance.resizemouseup, true);1885 instance.mouseOffset = Rendition.UI.getMouseOffset(obj, ev);1886 instance.resizeOffset = Rendition.UI.getRect(instance.dialog);1887 instance.resizeObject = obj;1888 instance.eventlisteners_startingResize(ev);1889 return;1890 }1891 if (args.dontInit != true) {1892 instance.init();1893 }1894 return instance;...
legacy-2020-12-07.js
Source:legacy-2020-12-07.js
1/*2#TODO Abstract the Route object...functions are conflicting with array3*/4var RouteState = function () {};5RouteState.route = null;6RouteState.prevRoute = null;7RouteState.injectBodyClass = true;8RouteState.serializePathname = true;9RouteState.sustainHashHistory = true;10RouteState.previousStateToBody = true;11RouteState.ROUTE_CHANGE_EVENT = 'ROUTE_CHANGE_EVENT';12RouteState.LAST_SESSION_TAG = 'LAST_SESSION_TAG';13RouteState.config = {};14RouteState.config = function (config) {15 this.config = config;16};17RouteState.doneFunk = null;18RouteState.errorFunk = null;19RouteState.DOMs = [];20RouteState.diffListeners = {};21RouteState.diffClusters = {};22RouteState.propValueListeners = {};23RouteState.propValueClusters = {};24RouteState.valueSeparator = "/";25RouteState.nameSeparatorStart = "{";26RouteState.nameSeparatorEnd = "}";27RouteState.nameSeparator = ",";28RouteState.valueNameSeparator = RouteState.valueSeparator + RouteState.nameSeparatorStart;29RouteState.dependancySeparatorStart = "[";30RouteState.dependancySeparatorEnd = "]";31RouteState.nameRelationSeparator = RouteState.nameSeparatorEnd + RouteState.dependancySeparatorStart;32RouteState.dependancyConnectionSeparator = ":";33RouteState.dependancySeparator = ",";34RouteState.listenToHash = function (funk, isRoot) {35 // Establish this as a singleton (across frames)36 this.targetWindow = window;37 this.targetDocument = document;38 this.routeStack = []; // Routes can nest in a stack of routes39 // var isTopmostWindow = true;40 if (isRoot !== true) {41 // Need to walk up atainable parents...(at some point)42 if (43 window.top !== window.self44 ) {45 var parentWindow = window.parent;46 var currentWindow = window;47 var prevWindow;48 var passes;49 while (parentWindow !== window.top) {50 try {51 // Will error out when it is in different domain...52 passes = parentWindow.document.domain;53 prevWindow = currentWindow;54 currentWindow = parentWindow;55 parentWindow = currentWindow.parent;56 } catch (e) {57 currentWindow = prevWindow;58 break;59 }60 }61 // Loop doesn't catch this last condition...62 if (parentWindow === window.top) {63 try {64 // Will error out when it is in different domain...65 passes = parentWindow.document.domain;66 currentWindow = parentWindow;67 } catch (e) {68 currentWindow = currentWindow;69 }70 }71 this.targetWindow = currentWindow;72 this.targetDocument = currentWindow.document;73 // If there is some race condition...74 if (!this.targetWindow.RouteState) {75 this.targetWindow.RouteState = this;76 RouteState.DOMs.push(this.targetDocument);77 }78 window.RouteState = this.targetWindow.RouteState;79 }80 }81 RouteState.targetWindow = this.targetWindow;82 RouteState.targetDocument = this.targetDocument;83 RouteState.DOMs.push(document);84 var me = RouteState;85 // Grandparent in previous funks declared...86 if (RouteState.doneFunk) {87 var oldFunk = RouteState.doneFunk;88 RouteState.doneFunk = function (route, prevRoute) {89 oldFunk(route, prevRoute);90 funk(route, prevRoute);91 };92 } else {93 RouteState.doneFunk = funk;94 }95 if (!this.targetWindow.RouteState.hashchangedInitialized) {96 this.targetWindow.addEventListener('hashchange', function () {97 var clone = RouteState.routeFromPath(98 RouteState.targetDocument.location.hash99 );100 if (clone.toHashString() !== RouteState.route.toHashString()) {101 RouteState.updateRoute(clone);102 }103 });104 this.targetWindow.RouteState.hashchangedInitialized = true;105 if (RouteState.sustainHashHistory) {106 if (localStorage) {107 RouteState.sessionPrevRoute = {};108 var tag = RouteState.LAST_SESSION_TAG;109 RouteState.sessionPrevRoute.route = localStorage.getItem(110 'RouteState.' + tag + '.route'111 );112 RouteState.sessionPrevRoute.pathname = localStorage.getItem(113 'RouteState.' + tag + '.pathname'114 );115 RouteState.sessionPrevRoute.search = localStorage.getItem(116 'RouteState.' + tag + '.search'117 );118 }119 }120 }121 // Kick this off...122 RouteState.updateRoute(123 RouteState.routeFromPath(RouteState.targetDocument.location.hash)124 );125};126RouteState.unlistenHash = function () {127 window.removeEventListener('hashchange');128};129RouteState.kill = function () {130 this.unlistenHash();131 RouteState.diffListeners = {};132 RouteState.propValueListeners = {};133 delete RouteState.prevRoute;134 delete RouteState.route;135};136RouteState.updateRoute = function (newRoute) {137 // Clear out empty values and dependencies...138 newRoute.cleanRoute();139 if (this.route) {140 this.prevRoute = this.route;141 } else {142 this.prevRoute = this.factory();143 }144 this.route = newRoute;145 var me = this;146 this.DOMs.forEach(function(index) {147 me.route.toElementClass(index.querySelectorAll('body'), 's_');148 if (RouteState.previousStateToBody && me.prevRoute) {149 me.prevRoute.toElementClass(index.querySelectorAll('body'), 'sp_');150 }151 }, this);152 this.checkDiffListeners();153 this.checkPropValueListeners();154 if (this.doneFunk) {155 this.doneFunk(this.route, this.prevRoute);156 }157};158RouteState.toPath = function (pathname, overrides, replaceArrays) {159 var route = this.route.clone(overrides, replaceArrays);160 var routeStr = route.toHashString();161 // Document.location = pathname + document.location.search + routeStr;162 this.toLocation(pathname, document.location.search, routeStr);163};164RouteState.toPathAndReplace = function (pathname, state) {165 var route = RouteState.factory(state);166 var routeStr = route.toHashString();167 // Document.location = pathname + document.location.search + routeStr;168 this.toLocation(pathname, document.location.search, routeStr);169};170RouteState.tagSessionRoute = function (tagName) {171 this.saveSessionRoute(tagName);172};173RouteState.saveSessionRoute = function (tagName) {174 if (RouteState.sustainHashHistory) {175 if (localStorage) {176 if (!tagName) {177 tagName = RouteState.LAST_SESSION_TAG;178 }179 localStorage.setItem(180 'RouteState.' + tagName + '.route',181 RouteState.route.toHashString()182 );183 localStorage.setItem(184 'RouteState.' + tagName + '.pathname',185 document.location.pathname186 );187 localStorage.setItem(188 'RouteState.' + tagName + '.search',189 document.location.search190 );191 }192 }193};194RouteState.toLocation = function (pathname, search, routeStr) {195 if (RouteState.sustainHashHistory) {196 this.saveSessionRoute();197 }198 document.location = pathname + search + routeStr;199};200RouteState.isSessionPathnameSame = function () {201 return (RouteState.sessionPrevRoute.pathname ===202 document.location.pathname);203};204RouteState.toSessionRoute = function (tagName) {205 if (RouteState.sustainHashHistory) {206 if (!tagName) {207 tagName = RouteState.LAST_SESSION_TAG;208 }209 var sessionRoute = {};210 sessionRoute.route = localStorage.getItem(211 'RouteState.' + tagName + '.route'212 );213 sessionRoute.pathname = localStorage.getItem(214 'RouteState.' + tagName + '.pathname'215 );216 sessionRoute.search = localStorage.getItem(217 'RouteState.' + tagName + '.search'218 );219 if (sessionRoute.route) {220 this.toLocation(sessionRoute.pathname, sessionRoute.search, sessionRoute.route);221 return true;222 }223 }224 return false;225};226// Diff listener227RouteState.addDiffListener = function (228 prop,229 callback,230 clusterID231) {232 if (!this.diffListeners[prop]) {233 this.diffListeners[prop] = [];234 }235 this.diffListeners[prop].push(callback);236 if (clusterID) {237 if (!this.diffClusters[clusterID]) {238 this.diffClusters[clusterID] = [];239 }240 this.diffClusters[clusterID].push(callback);241 }242 return callback;243};244RouteState.addDiffListeners = function (245 props,246 callback,247 clusterID248) {249 var prop;250 for (var i = 0; i < props.length; i++) {251 prop = props[i];252 this.addDiffListener(prop, callback, clusterID);253 }254 return callback;255};256RouteState.checkDiffListeners = function () {257 if (this.route) {258 var callbacks;259 var callback;260 var triggerCallbacks;261 for (var prop in this.diffListeners) {262 if (!this.diffListeners.hasOwnProperty(prop)) {263 continue;264 }265 callbacks = this.diffListeners[prop];266 triggerCallbacks = false;267 if (this.prevRoute) {268 if (this.route[prop] !== this.prevRoute[prop]) {269 triggerCallbacks = true;270 }271 } else {272 triggerCallbacks = true;273 }274 if (triggerCallbacks) {275 for (var c = 0; c < callbacks.length; c++) {276 callback = callbacks[c];277 callback(this.route, this.prevRoute);278 }279 }280 }281 }282};283RouteState.removeDiffListener = function (difflistenerID) {284 for (var prop in this.diffListeners) {285 if (!this.diffListeners.hasOwnProperty(prop)) {286 continue;287 }288 var callbacks = this.diffListeners[prop];289 for (var c = 0; c < callbacks.length; c++) {290 var callback = callbacks[c];291 if (callback === difflistenerID) {292 callbacks.splice(c, 1);293 break;294 }295 }296 }297};298RouteState.removeDiffListenersViaClusterId = function (clusterID) {299 if (this.diffClusters[clusterID]) {300 var callbacks = this.diffClusters[clusterID];301 for (var c = 0; c < callbacks.length; c++) {302 var callback = callbacks[c];303 this.removeDiffListener(callback);304 }305 this.diffClusters[clusterID] = false;306 delete this.diffClusters[clusterID];307 }308};309RouteState.addPropValueListener = function (310 prop, value,311 callback, exitcallback,312 clusterID313) {314 if (!this.propValueListeners[prop]) {315 this.propValueListeners[prop] = [];316 }317 this.propValueListeners[prop].push({318 value: value,319 callback: callback,320 exitcallback: exitcallback321 });322 if (clusterID) {323 if (!this.propValueClusters[clusterID]) {324 this.propValueClusters[clusterID] = [];325 }326 this.propValueClusters[clusterID].push(callback);327 }328 return callback;329};330RouteState.checkPropValueListeners = function () {331 if (this.route) {332 var callbackObjs;333 var callbackObj;334 for (var prop in this.propValueListeners) {335 if (!this.propValueListeners.hasOwnProperty(prop)) {336 continue;337 }338 callbackObjs = this.propValueListeners[prop];339 if (this.prevRoute) {340 for (var c = 0; c < callbackObjs.length; c++) {341 callbackObj = callbackObjs[c];342 // Check for exit callback first...343 if (344 callbackObj.exitcallback &&345 this.prevRoute[prop] === callbackObj.value &&346 this.route[prop] !== callbackObj.value347 ) {348 callbackObj.exitcallback(349 this.route, this.prevRoute350 );351 }352 if (353 this.route[prop] === callbackObj.value &&354 this.prevRoute[prop] !== callbackObj.value355 ) {356 callbackObj.callback(357 this.route, this.prevRoute358 );359 }360 }361 } else {362 // Call them all there is no prev route....363 for (var c = 0; c < callbackObjs.length; c++) {364 callbackObj = callbackObjs[c];365 callbackObj.callback(366 this.route, this.prevRoute367 );368 }369 }370 }371 }372};373RouteState.removePropValueListener = function (valProplistenerID) {374 for (var prop in this.propValueListeners) {375 if (!this.propValueListeners.hasOwnProperty(prop)) {376 continue;377 }378 var callbackObjs = this.propValueListeners[prop];379 for (var c = 0; c < callbackObjs.length; c++) {380 var callbackObj = callbackObjs[c];381 if (callbackObj.callback === valProplistenerID) {382 callbackObjs.splice(c, 1);383 break;384 }385 }386 }387};388RouteState.removePropValueListenersViaClusterId = function (clusterID) {389 if (this.propValueClusters[clusterID]) {390 var callbacks = this.propValueClusters[clusterID];391 for (var c = 0; c < callbacks.length; c++) {392 var callback = callbacks[c];393 this.removePropValueListener(callback);394 }395 this.propValueClusters[clusterID] = false;396 delete this.propValueClusters[clusterID];397 }398};399RouteState.factory = function (state) {400 var routeStateRoute = new RouteStateRoute();401 for (var i in state) {402 if (!RouteState.isFunction(i)) {403 if (RouteState.isArray(state[i])) {404 routeStateRoute[i] = [].concat(state[i]);405 } else {406 routeStateRoute[i] = state[i];407 }408 }409 }410 return routeStateRoute;411};412RouteState.routeFromPath = function (path) {413 return this.factory(414 this.objectFromPath(path)415 );416};417RouteState.objectFromPath = function (path) {418 var routeStateRoute = {};419 // Get rid of shebang420 path = path.replace(/#!\//g, '');421 path = path.replace(RouteState.dependancySeparatorEnd, '');422 var dependencyArr = path.split(RouteState.nameRelationSeparator);423 path = dependencyArr[0];424 if (dependencyArr.length > 1) {425 dependencyArr = dependencyArr[1].split(',');426 } else {427 path = path.replace('}', '');428 dependencyArr = [];429 }430 var pathArr = path.split(RouteState.valueNameSeparator);431 if (pathArr.length < 2) {432 return routeStateRoute;433 }434 var names = pathArr[1];435 var vals = pathArr[0];436 var valsArr = vals.split('/');437 var namesArr = names.split(',');438 // var state = {};439 // var pair;440 var name;441 // var nameArr;442 var val;443 var dependency;444 var depnameArr;445 for (var a = 0; a < namesArr.length; a++) {446 name = namesArr[a];447 // Deal with dependencies...they are index based versus name448 dependency = dependencyArr[a];449 if (dependency) {450 if (!RouteState.config[name]) {451 RouteState.config[name] = {};452 }453 depnameArr = dependency.split(RouteState.dependancyConnectionSeparator );454 if (depnameArr.length > 1) {455 dependency = namesArr[depnameArr[0]] + RouteState.dependancyConnectionSeparator + depnameArr[1];456 } else {457 dependency = namesArr[dependency];458 }459 RouteState.config[name].dependency = dependency;460 }461 // Now put values together462 val = valsArr[a];463 if (val && val.length > 0 && name && name.length > 0) {464 if (val.indexOf(',') !== -1) { // Array465 routeStateRoute[name] = val.split(',');466 } else {467 routeStateRoute[name] = val;468 }469 }470 }471 return routeStateRoute;472};473// ===========HELPERS============474RouteState.isFunction = function (functionToCheck) {475 var getType = {};476 return functionToCheck && getType.toString.call(functionToCheck) ===477 '[object Function]';478};479RouteState.isArray = function (functionToCheck) {480 var getType = {};481 return functionToCheck && getType.toString.call(functionToCheck) ===482 '[object Array]';483};484RouteState.stateToObject = function (state) {485 var stateArr;486 var stateObj = {487 name: false,488 dependency: false,489 relation: 0 // 0 = none, 1 = exists, 2 = exists and value490 };491 if (state.indexOf(RouteState.dependancyConnectionSeparator) !== -1) {492 stateArr = state.split(RouteState.dependancyConnectionSeparator);493 stateObj.name = stateArr[1];494 stateObj.dependency = stateArr[0];495 stateObj.relation = 2;496 } else if (state.indexOf('.') !== -1) {497 stateArr = state.split('.');498 stateObj.name = stateArr[1];499 stateObj.dependency = stateArr[0];500 stateObj.relation = 1;501 } else {502 stateObj.name = state;503 stateObj.dependency = false;504 stateObj.relation = 0;505 }506 return stateObj;507};508// ===========ROUTE OPERATORS============509RouteState.merge = function (overrides, replaceArrays) {510 if (this.route) {511 overrides = RouteState.processObjectForDependencies(overrides);512 var newRoute = this.route.clone(overrides, replaceArrays);513 RouteState.updateRoute(newRoute);514 newRoute.toHash();515 }516};517RouteState.replace = function (state) {518 state = RouteState.processObjectForDependencies(state);519 var newRoute = RouteState.factory(state);520 RouteState.updateRoute(newRoute);521 newRoute.toHash();522};523RouteState.processObjectForDependencies = function (overrides) {524 var stateObj = {};525 var newOverrides = {};526 for (var name in overrides) {527 if (!overrides.hasOwnProperty(name)) {528 continue;529 }530 stateObj = RouteState.stateToObject(name);531 newOverrides[stateObj.name] = overrides[name];532 switch (stateObj.relation) {533 case 1:534 RouteState.tieToProp(535 stateObj.name,536 stateObj.dependency537 );538 break;539 case 2:540 RouteState.tieToPropAndValue(541 stateObj.name,542 stateObj.dependency,543 overrides544 );545 break;546 default:547 RouteState.removeTies(name);548 break;549 }550 }551 return newOverrides;552};553RouteState.removeTies = function (source) {554 if (!RouteState.config[source]) {555 RouteState.config[source] = {};556 }557 delete RouteState.config[source].dependency;558};559RouteState.tieToProp = function (source, target) {560 if (!RouteState.config[source]) {561 RouteState.config[source] = {};562 }563 RouteState.config[source].dependency = target;564};565RouteState.tieToPropAndValue = function (source, target, overrides) {566 if (!RouteState.config[source]) {567 RouteState.config[source] = {};568 }569 if (570 (RouteState.route && RouteState.route[target]) ||571 (overrides && overrides[target])572 ) {573 var targetValue;574 // Overrides should take precedence...575 // they are going to be a part of the new route.576 if (overrides[target]) {577 targetValue = overrides[target];578 } else {579 targetValue = RouteState.route[target];580 }581 RouteState.config[source].dependency =582 target + RouteState.dependancyConnectionSeparator + targetValue;583 } else {584 RouteState.tieToProp(source, target);585 }586};587// These are all operating on top of merge...588RouteState.toggle = function (state, otherState, replaceArrays) {589 var stateObj;590 for (var name in state) {591 if (!state.hasOwnProperty(name)) {592 continue;593 }594 stateObj = RouteState.stateToObject(name);595 if (this.isArray(state[name])) {596 if (!this.route[stateObj.name]) {597 this.route[stateObj.name] = [];598 }599 if (!RouteState.isArray(this.route[stateObj.name])) {600 this.route[stateObj.name] = [].concat(this.route[stateObj.name]);601 }602 var subName;603 for (var i = 0; i < state[name].length; i++) {604 subName = state[name][i];605 if (this.route[stateObj.name].indexOf(subName) === -1) {606 this.merge(state, replaceArrays);607 return;608 }609 }610 } else if (this.route[stateObj.name] !== state[name]) {611 this.merge(state, replaceArrays);612 return;613 }614 }615 // If it made it this far it is the latter state616 this.merge(otherState, replaceArrays);617};618// ===========END ROUTE OPERATORS============619RouteState.debug = function () {620 // $('.routestate_debug').remove();621 var routestateDebug = document.getElementsByClassName('routestate_debug');622 console.log(routestateDebug);623 if (routestateDebug.parentNode !== undefined) {624 routestateDebug.parentNode.removeChild(routestateDebug);625 }626 var html = ['width' + window.naturalWidth + ' | height' + window.naturalHeight];627 var depends;628 for (var i in this.route) {629 if (!RouteState.isFunction(this.route[i])) {630 depends = '';631 if (RouteState.config[i] && RouteState.config[i].dependency) {632 depends = ' (depends on \'' + RouteState.config[i].dependency + '\')';633 }634 if (RouteState.isArray(this.route[i])) {635 html.push(636 i + ' = ' +637 this.route[i].join(',<br/> ') +638 depends639 );640 } else {641 html.push(i + ' = ' + this.route[i] + depends);642 }643 }644 }645 var debugHTML = function (html) {646 return ('<div onclick="routestateDebug.parentNode.removeChild(routestateDebug);" class="routestate_debug" style="padding: 10px; border: 1px solid grey; width:300px; height: auto; background-color: #fff; position: fixed; top: 10px; right: 10px; z-index: 2000000;">' + html +'<br/></div>');647 }648 document.body.innerHTML = debugHTML;649 // document.body.innerHTML('<div onclick=\'routestateDebug.parentNode.removeChild(routestateDebug);\'' +650 // ' class=\'routestate_debug\'' +651 // ' style=\'padding: 10px; border: 1px solid grey;' +652 // ' width:300px; height: auto; background-color: #fff;' +653 // ' position: fixed; top: 10px;' +654 // ' right: 10px; z-index: 2000000;\'>' +655 // html.join('<br/>') +656 // '</div>');657};658// ===========ROUTE STACK==================659RouteState.push = function () {660 this.routeStack.push(this.route.clone());661 return this;662};663RouteState.pop = function () {664 if (this.routeStack.length > 0) {665 this.replace(this.routeStack.pop());666 } else {667 console.log('RouteState: nothing left in the stack.');668 if ( RouteState.errorFunk ) {669 RouteState.errorFunk( "popped empty stack" );670 }671 }672 return this;673};674// ============================================675// ========== RouteStateRoute =================676// ============================================677var RouteStateRoute = function () {};678RouteStateRoute.prototype.toHash = function () {679 var routeStr = this.toHashString();680 RouteState.targetDocument.location.hash = routeStr;681};682// ===========SERIALIZERS==================683RouteStateRoute.prototype.toHashString = function () {684 var routeConfig;685 var routeObj = this.toObject();686 var routeArr = [];687 var defaultWeight = 100000;688 for (var name in routeObj) {689 if (!routeObj.hasOwnProperty(name)) {690 continue;691 }692 // See if we are supposed to show this...693 // make sure to get the top most config...694 routeConfig = RouteState.config[name];695 if (routeConfig) {696 // ignore this if it shouldn't be in hash697 if (698 typeof routeConfig.show_in_hash !== 'undefined' &&699 routeConfig.show_in_hash === false700 ) {701 continue;702 }703 } else {704 routeConfig = {705 weight: defaultWeight706 };707 }708 var weight = (routeConfig.weight) ?709 routeConfig.weight : defaultWeight;710 if (RouteState.isArray(routeObj[name])) {711 routeArr.push({712 name: name,713 val: routeObj[name].join(','),714 weight: weight715 });716 } else {717 routeArr.push({718 name: name,719 val: routeObj[name],720 weight: weight721 });722 }723 }724 // Sort according to weight725 routeArr.sort(function (a, b) {726 if (a.weight < b.weight) {727 return -1;728 }729 if (a.weight > b.weight) {730 return 1;731 }732 return 0;733 });734 var nameArr = [];735 var nameLookup = {};736 var valArr = [];737 var dependancyArr = [];738 // Finally put it all together in correct order...739 for (var key in routeArr) {740 // Skip loop if the property is from prototype741 if (!routeArr.hasOwnProperty(key)) {742 continue;743 }744 var obj = routeArr[key];745 nameArr.push(obj.name);746 valArr.push(obj.val);747 nameLookup[obj.name] = key;748 }749 // Now add dependencies, but via index of the name...750 var depnameArr = false;751 var showDependencies = false;752 routeArr.forEach(function(value) {753 if (754 RouteState.config &&755 RouteState.config[value.name] &&756 RouteState.config[value.name].dependency757 ) {758 depnameArr = RouteState.config[value.name].dependency.split(RouteState.dependancyConnectionSeparator);759 if (depnameArr.length > 1) {760 dependancyArr.push(nameLookup[depnameArr[0]] + RouteState.dependancyConnectionSeparator + depnameArr[1]);761 showDependencies = true;762 } else {763 dependancyArr.push(nameLookup[depnameArr[0]]);764 showDependencies = true;765 }766 } else {767 dependancyArr.push('');768 }769 }, this);770 if (valArr.length > 0) {771 if (showDependencies) {772 return '#!/' + valArr.join('/') + RouteState.valueNameSeparator + nameArr.join(RouteState.nameSeparator) + RouteState.nameRelationSeparator + dependancyArr.join(RouteState.dependancySeparator) + RouteState.dependancySeparatorEnd;773 }774 return '#!/' + valArr.join('/') + RouteState.valueNameSeparator + nameArr.join(RouteState.nameSeparator) + RouteState.nameSeparatorEnd;775 }776 return '';777};778RouteStateRoute.prototype.serializedToBodyClasses = function (prefix) {779 var bodyClasses = [];780 // Put pathname in there...781 // pathname always has a preceeding slash782 if (RouteState.serializePathname && RouteState.targetDocument !== undefined) {783 bodyClasses.push(784 prefix + 'pathname' + RouteState.targetDocument.location.pathname.replace(/\//g, '_')785 );786 }787 var routeObj = this.toObject();788 for (var name in routeObj) {789 if (!routeObj.hasOwnProperty(name)) {790 continue;791 }792 // See if we are supposed to show this...793 var routeConfig = RouteState.config[name];794 if (routeConfig) {795 if (796 typeof routeConfig.show_in_body !== 'undefined' &&797 routeConfig.show_in_body === false798 ) {799 continue;800 }801 }802 if (RouteState.isArray(routeObj[name])) {803 var element;804 for (var e = 0; e < routeObj[name].length; e++) {805 element = routeObj[name][e];806 bodyClasses.push(prefix + name + '_' + element);807 }808 } else {809 bodyClasses.push(prefix + name + '_' + routeObj[name]);810 }811 // Just a name, boolean lookup thing812 bodyClasses.push(prefix + name);813 }814 if (bodyClasses.length === 0) {815 bodyClasses.push(prefix + 'empty');816 }817 return bodyClasses.join(' ');818};819RouteStateRoute.prototype.cleanRoute = function () {820 var dependancyHits = 0;821 var dependencyArr;822 for (var name in this) {823 if (!RouteState.isFunction(this[name])) {824 var routeConfig = RouteState.config[name];825 if (routeConfig && typeof routeConfig.dependency !== 'undefined') {826 // ignore this if it has a missing dependancy827 dependencyArr = routeConfig.dependency.split(RouteState.dependancyConnectionSeparator);828 if (dependencyArr.length > 1) {829 if (!this[dependencyArr[0]] ||830 String(this[dependencyArr[0]]) !== String(dependencyArr[1])831 ) {832 dependancyHits++;833 delete this[name];834 }835 } else if (!this[routeConfig.dependency]) {836 dependancyHits++;837 delete this[name];838 }839 }840 // Clean out empty values...841 if (!this[name] || this[name] === '') {842 delete this[name];843 }844 }845 }846 if (dependancyHits > 0) {847 this.cleanRoute();848 }849};850RouteStateRoute.prototype.toObject = function () {851 var routeObj = {};852 for (var name in this) {853 if (!RouteState.isFunction(this[name])) {854 routeObj[name] = this[name];855 }856 }857 return routeObj;858};859// ===============END SERIALIZERS=============860RouteStateRoute.prototype.toElementClass = function (element, prefix) {861 var bodyClass = element[0].classList.value;862 if (bodyClass) {863 var bodyClassList = bodyClass.split(/\s+/);864 bodyClassList.forEach(function(index, item) {865 if (index.indexOf(prefix) === 0) {866 element[0].classList.remove(index);867 }868 }, this);869 }870 var serializedClasses = this.serializedToBodyClasses(prefix);871 var serializedClassList = serializedClasses.split(/\s+/);872 serializedClassList.forEach(function(item, index) {873 element[0].classList.add(item);874 }, this);875};876RouteStateRoute.prototype.clone = function (overrides, replaceArrays) {877 var routeState = RouteState.factory(this);878 if (!replaceArrays) {879 replaceArrays = false;880 }881 if (overrides) {882 for (var i in overrides) {883 if (!RouteState.isFunction(overrides[i])) {884 if (RouteState.isArray(overrides[i])) {885 if (replaceArrays) {886 routeState[i] = [].concat(overrides[i]);887 } else {888 if (!routeState[i]) {889 routeState[i] = [];890 }891 if (!RouteState.isArray(routeState[i])) {892 routeState[i] = [].concat(routeState[i]);893 }894 var override;895 for (var p = 0; p < overrides[i].length; p++) {896 override = String(overrides[i][p]);897 if (override.indexOf('-') === 0) {898 override = override.replace('-', '');899 var index = routeState[i].indexOf(override);900 if (index > -1) {901 routeState[i].splice(index, 1);902 }903 } else if (routeState[i].indexOf(override) === -1) {904 routeState[i].push(override);905 }906 }907 }908 } else {909 routeState[i] = overrides[i];910 }911 }912 }913 }914 return routeState;...
index.js
Source:index.js
1/*2#TODO Abstract the Route object...functions are conflicting with array3*/4var RouteState = function () {};5RouteState.route = null;6RouteState.prevRoute = null;7RouteState.injectBodyClass = true;8RouteState.serializePathname = true;9RouteState.sustainHashHistory = true;10RouteState.previousStateToBody = true;11RouteState.ROUTE_CHANGE_EVENT = 'ROUTE_CHANGE_EVENT';12RouteState.LAST_SESSION_TAG = 'LAST_SESSION_TAG';13RouteState.config = {};14RouteState.config = function (config) {15 this.config = config;16};17RouteState.doneFunk = null;18RouteState.errorFunk = null;19RouteState.DOMs = [];20RouteState.diffListeners = {};21RouteState.diffClusters = {};22RouteState.propValueListeners = {};23RouteState.propValueClusters = {};24RouteState.listenToHash = function (funk, isRoot) {25 // Establish this as a singleton (across frames)26 this.targetWindow = window;27 this.targetDocument = document;28 this.routeStack = []; // Routes can nest in a stack of routes29 // var isTopmostWindow = true;30 if (isRoot !== true) {31 // Need to walk up atainable parents...(at some point)32 if (33 window.top !== window.self34 ) {35 var parentWindow = window.parent;36 var currentWindow = window;37 var prevWindow;38 var passes;39 while (parentWindow !== window.top) {40 try {41 // Will error out when it is in different domain...42 passes = parentWindow.document.domain;43 prevWindow = currentWindow;44 currentWindow = parentWindow;45 parentWindow = currentWindow.parent;46 } catch (e) {47 currentWindow = prevWindow;48 break;49 }50 }51 // Loop doesn't catch this last condition...52 if (parentWindow === window.top) {53 try {54 // Will error out when it is in different domain...55 passes = parentWindow.document.domain;56 currentWindow = parentWindow;57 } catch (e) {58 currentWindow = currentWindow;59 }60 }61 this.targetWindow = currentWindow;62 this.targetDocument = currentWindow.document;63 // If there is some race condition...64 if (!this.targetWindow.RouteState) {65 this.targetWindow.RouteState = this;66 RouteState.DOMs.push(this.targetDocument);67 }68 window.RouteState = this.targetWindow.RouteState;69 }70 }71 RouteState.targetWindow = this.targetWindow;72 RouteState.targetDocument = this.targetDocument;73 RouteState.DOMs.push(document);74 var me = RouteState;75 // Grandparent in previous funks declared...76 if (RouteState.doneFunk) {77 var oldFunk = RouteState.doneFunk;78 RouteState.doneFunk = function (route, prevRoute) {79 oldFunk(route, prevRoute);80 funk(route, prevRoute);81 };82 } else {83 RouteState.doneFunk = funk;84 }85 if (!this.targetWindow.RouteState.hashchangedInitialized) {86 this.targetWindow.addEventListener('hashchange', function () {87 var clone = RouteState.routeFromPath(88 RouteState.targetDocument.location.hash89 );90 if (clone.toHashString() !== RouteState.route.toHashString()) {91 RouteState.updateRoute(clone);92 }93 });94 this.targetWindow.RouteState.hashchangedInitialized = true;95 if (RouteState.sustainHashHistory) {96 if (localStorage) {97 RouteState.sessionPrevRoute = {};98 var tag = RouteState.LAST_SESSION_TAG;99 RouteState.sessionPrevRoute.route = localStorage.getItem(100 'RouteState.' + tag + '.route'101 );102 RouteState.sessionPrevRoute.pathname = localStorage.getItem(103 'RouteState.' + tag + '.pathname'104 );105 RouteState.sessionPrevRoute.search = localStorage.getItem(106 'RouteState.' + tag + '.search'107 );108 }109 }110 }111 // Kick this off...112 if (RouteState.targetDocument.location.hash.indexOf('%7B') !== -1 ) {113 RouteState.targetDocument.location.hash = decodeURIComponent( RouteState.targetDocument.location.hash );114 RouteState.targetDocument.location.reload();115 }else{116 RouteState.updateRoute(117 RouteState.routeFromPath(RouteState.targetDocument.location.hash)118 );119 }120};121RouteState.unlistenHash = function () {122 window.removeEventListener('hashchange');123};124RouteState.kill = function () {125 this.unlistenHash();126 RouteState.diffListeners = {};127 RouteState.propValueListeners = {};128 delete RouteState.prevRoute;129 delete RouteState.route;130};131RouteState.updateRoute = function (newRoute) {132 // Clear out empty values and dependencies...133 newRoute.cleanRoute();134 if (this.route) {135 this.prevRoute = this.route;136 } else {137 this.prevRoute = this.factory();138 }139 this.route = newRoute;140 var me = this;141 this.DOMs.forEach(function(index) {142 me.route.toElementClass(index.querySelectorAll('body'), 's_');143 if (RouteState.previousStateToBody && me.prevRoute) {144 me.prevRoute.toElementClass(index.querySelectorAll('body'), 'sp_');145 }146 }, this);147 this.checkDiffListeners();148 this.checkPropValueListeners();149 if (this.doneFunk) {150 this.doneFunk(this.route, this.prevRoute);151 }152};153RouteState.toPath = function (pathname, overrides, replaceArrays) {154 var route = this.route.clone(overrides, replaceArrays);155 var routeStr = route.toHashString();156 // Document.location = pathname + document.location.search + routeStr;157 this.toLocation(pathname, document.location.search, routeStr);158};159RouteState.toPathAndReplace = function (pathname, state) {160 var route = RouteState.factory(state);161 var routeStr = route.toHashString();162 // Document.location = pathname + document.location.search + routeStr;163 this.toLocation(pathname, document.location.search, routeStr);164};165RouteState.tagSessionRoute = function (tagName) {166 this.saveSessionRoute(tagName);167};168RouteState.saveSessionRoute = function (tagName) {169 if (RouteState.sustainHashHistory) {170 if (localStorage) {171 if (!tagName) {172 tagName = RouteState.LAST_SESSION_TAG;173 }174 localStorage.setItem(175 'RouteState.' + tagName + '.route',176 RouteState.route.toHashString()177 );178 localStorage.setItem(179 'RouteState.' + tagName + '.pathname',180 document.location.pathname181 );182 localStorage.setItem(183 'RouteState.' + tagName + '.search',184 document.location.search185 );186 }187 }188};189RouteState.toLocation = function (pathname, search, routeStr) {190 if (RouteState.sustainHashHistory) {191 this.saveSessionRoute();192 }193 document.location = pathname + search + routeStr;194};195RouteState.isSessionPathnameSame = function () {196 return (RouteState.sessionPrevRoute.pathname ===197 document.location.pathname);198};199RouteState.toSessionRoute = function (tagName) {200 if (RouteState.sustainHashHistory) {201 if (!tagName) {202 tagName = RouteState.LAST_SESSION_TAG;203 }204 var sessionRoute = {};205 sessionRoute.route = localStorage.getItem(206 'RouteState.' + tagName + '.route'207 );208 sessionRoute.pathname = localStorage.getItem(209 'RouteState.' + tagName + '.pathname'210 );211 sessionRoute.search = localStorage.getItem(212 'RouteState.' + tagName + '.search'213 );214 if (sessionRoute.route) {215 this.toLocation(sessionRoute.pathname, sessionRoute.search, sessionRoute.route);216 return true;217 }218 }219 return false;220};221// Diff listener222RouteState.addDiffListener = function (223 prop,224 callback,225 clusterID226) {227 if (!this.diffListeners[prop]) {228 this.diffListeners[prop] = [];229 }230 this.diffListeners[prop].push(callback);231 if (clusterID) {232 if (!this.diffClusters[clusterID]) {233 this.diffClusters[clusterID] = [];234 }235 this.diffClusters[clusterID].push(callback);236 }237 return callback;238};239RouteState.addDiffListeners = function (240 props,241 callback,242 clusterID243) {244 var prop;245 for (var i = 0; i < props.length; i++) {246 prop = props[i];247 this.addDiffListener(prop, callback, clusterID);248 }249 return callback;250};251RouteState.checkDiffListeners = function () {252 if (this.route) {253 var callbacks;254 var callback;255 var triggerCallbacks;256 for (var prop in this.diffListeners) {257 if (!this.diffListeners.hasOwnProperty(prop)) {258 continue;259 }260 callbacks = this.diffListeners[prop];261 triggerCallbacks = false;262 if (this.prevRoute) {263 if (this.route[prop] !== this.prevRoute[prop]) {264 triggerCallbacks = true;265 }266 } else {267 triggerCallbacks = true;268 }269 if (triggerCallbacks) {270 for (var c = 0; c < callbacks.length; c++) {271 callback = callbacks[c];272 callback(this.route, this.prevRoute);273 }274 }275 }276 }277};278RouteState.removeDiffListener = function (difflistenerID) {279 for (var prop in this.diffListeners) {280 if (!this.diffListeners.hasOwnProperty(prop)) {281 continue;282 }283 var callbacks = this.diffListeners[prop];284 for (var c = 0; c < callbacks.length; c++) {285 var callback = callbacks[c];286 if (callback === difflistenerID) {287 callbacks.splice(c, 1);288 break;289 }290 }291 }292};293RouteState.removeDiffListenersViaClusterId = function (clusterID) {294 if (this.diffClusters[clusterID]) {295 var callbacks = this.diffClusters[clusterID];296 for (var c = 0; c < callbacks.length; c++) {297 var callback = callbacks[c];298 this.removeDiffListener(callback);299 }300 this.diffClusters[clusterID] = false;301 delete this.diffClusters[clusterID];302 }303};304RouteState.addPropValueListener = function (305 prop, value,306 callback, exitcallback,307 clusterID308) {309 if (!this.propValueListeners[prop]) {310 this.propValueListeners[prop] = [];311 }312 this.propValueListeners[prop].push({313 value: value,314 callback: callback,315 exitcallback: exitcallback316 });317 if (clusterID) {318 if (!this.propValueClusters[clusterID]) {319 this.propValueClusters[clusterID] = [];320 }321 this.propValueClusters[clusterID].push(callback);322 }323 return callback;324};325RouteState.checkPropValueListeners = function () {326 if (this.route) {327 var callbackObjs;328 var callbackObj;329 for (var prop in this.propValueListeners) {330 if (!this.propValueListeners.hasOwnProperty(prop)) {331 continue;332 }333 callbackObjs = this.propValueListeners[prop];334 if (this.prevRoute) {335 for (var c = 0; c < callbackObjs.length; c++) {336 callbackObj = callbackObjs[c];337 // Check for exit callback first...338 if (339 callbackObj.exitcallback &&340 this.prevRoute[prop] === callbackObj.value &&341 this.route[prop] !== callbackObj.value342 ) {343 callbackObj.exitcallback(344 this.route, this.prevRoute345 );346 }347 if (348 this.route[prop] === callbackObj.value &&349 this.prevRoute[prop] !== callbackObj.value350 ) {351 callbackObj.callback(352 this.route, this.prevRoute353 );354 }355 }356 } else {357 // Call them all there is no prev route....358 for (var c = 0; c < callbackObjs.length; c++) {359 callbackObj = callbackObjs[c];360 callbackObj.callback(361 this.route, this.prevRoute362 );363 }364 }365 }366 }367};368RouteState.removePropValueListener = function (valProplistenerID) {369 for (var prop in this.propValueListeners) {370 if (!this.propValueListeners.hasOwnProperty(prop)) {371 continue;372 }373 var callbackObjs = this.propValueListeners[prop];374 for (var c = 0; c < callbackObjs.length; c++) {375 var callbackObj = callbackObjs[c];376 if (callbackObj.callback === valProplistenerID) {377 callbackObjs.splice(c, 1);378 break;379 }380 }381 }382};383RouteState.removePropValueListenersViaClusterId = function (clusterID) {384 if (this.propValueClusters[clusterID]) {385 var callbacks = this.propValueClusters[clusterID];386 for (var c = 0; c < callbacks.length; c++) {387 var callback = callbacks[c];388 this.removePropValueListener(callback);389 }390 this.propValueClusters[clusterID] = false;391 delete this.propValueClusters[clusterID];392 }393};394RouteState.factory = function (state) {395 var routeStateRoute = new RouteStateRoute();396 for (var i in state) {397 if (!RouteState.isFunction(i)) {398 if (RouteState.isArray(state[i])) {399 routeStateRoute[i] = [].concat(state[i]);400 } else {401 routeStateRoute[i] = state[i];402 }403 }404 }405 return routeStateRoute;406};407RouteState.routeFromPath = function (path) {408 return this.factory(409 this.objectFromPath(path)410 );411};412RouteState.objectFromPath = function (path) {413 var routeStateRoute = {};414 // Get rid of shebang415 path = path.replace(/#!\//g, '');416 path = path.replace(']', '');417 var dependencyArr = path.split('}[');418 path = dependencyArr[0];419 if (dependencyArr.length > 1) {420 dependencyArr = dependencyArr[1].split(',');421 } else {422 path = path.replace('}', '');423 dependencyArr = [];424 }425 var pathArr = path.split('/{');426 if (pathArr.length < 2) {427 return routeStateRoute;428 }429 var names = pathArr[1];430 var vals = pathArr[0];431 var valsArr = vals.split('/');432 var namesArr = names.split(',');433 // var state = {};434 // var pair;435 var name;436 // var nameArr;437 var val;438 var dependency;439 var depnameArr;440 for (var a = 0; a < namesArr.length; a++) {441 name = namesArr[a];442 // Deal with dependencies...they are index based versus name443 dependency = dependencyArr[a];444 if (dependency) {445 if (!RouteState.config[name]) {446 RouteState.config[name] = {};447 }448 depnameArr = dependency.split(':');449 if (depnameArr.length > 1) {450 dependency = namesArr[depnameArr[0]] + ':' + depnameArr[1];451 } else {452 dependency = namesArr[dependency];453 }454 RouteState.config[name].dependency = dependency;455 }456 // Now put values together457 val = valsArr[a];458 if (val && val.length > 0 && name && name.length > 0) {459 if (val.indexOf(',') !== -1) { // Array460 routeStateRoute[name] = val.split(',');461 } else {462 routeStateRoute[name] = val;463 }464 }465 }466 return routeStateRoute;467};468// ===========HELPERS============469RouteState.isFunction = function (functionToCheck) {470 var getType = {};471 return functionToCheck && getType.toString.call(functionToCheck) ===472 '[object Function]';473};474RouteState.isArray = function (functionToCheck) {475 var getType = {};476 return functionToCheck && getType.toString.call(functionToCheck) ===477 '[object Array]';478};479RouteState.stateToObject = function (state) {480 var stateArr;481 var stateObj = {482 name: false,483 dependency: false,484 relation: 0 // 0 = none, 1 = exists, 2 = exists and value485 };486 if (state.indexOf(':') !== -1) {487 stateArr = state.split(':');488 stateObj.name = stateArr[1];489 stateObj.dependency = stateArr[0];490 stateObj.relation = 2;491 } else if (state.indexOf('.') !== -1) {492 stateArr = state.split('.');493 stateObj.name = stateArr[1];494 stateObj.dependency = stateArr[0];495 stateObj.relation = 1;496 } else {497 stateObj.name = state;498 stateObj.dependency = false;499 stateObj.relation = 0;500 }501 return stateObj;502};503// ===========ROUTE OPERATORS============504RouteState.merge = function (overrides, replaceArrays) {505 if (this.route) {506 overrides = RouteState.processObjectForDependencies(overrides);507 var newRoute = this.route.clone(overrides, replaceArrays);508 RouteState.updateRoute(newRoute);509 newRoute.toHash();510 }511};512RouteState.replace = function (state) {513 state = RouteState.processObjectForDependencies(state);514 var newRoute = RouteState.factory(state);515 RouteState.updateRoute(newRoute);516 newRoute.toHash();517};518RouteState.processObjectForDependencies = function (overrides) {519 var stateObj = {};520 var newOverrides = {};521 for (var name in overrides) {522 if (!overrides.hasOwnProperty(name)) {523 continue;524 }525 stateObj = RouteState.stateToObject(name);526 newOverrides[stateObj.name] = overrides[name];527 switch (stateObj.relation) {528 case 1:529 RouteState.tieToProp(530 stateObj.name,531 stateObj.dependency532 );533 break;534 case 2:535 RouteState.tieToPropAndValue(536 stateObj.name,537 stateObj.dependency,538 overrides539 );540 break;541 default:542 RouteState.removeTies(name);543 break;544 }545 }546 return newOverrides;547};548RouteState.removeTies = function (source) {549 if (!RouteState.config[source]) {550 RouteState.config[source] = {};551 }552 delete RouteState.config[source].dependency;553};554RouteState.tieToProp = function (source, target) {555 if (!RouteState.config[source]) {556 RouteState.config[source] = {};557 }558 RouteState.config[source].dependency = target;559};560RouteState.tieToPropAndValue = function (source, target, overrides) {561 if (!RouteState.config[source]) {562 RouteState.config[source] = {};563 }564 if (565 (RouteState.route && RouteState.route[target]) ||566 (overrides && overrides[target])567 ) {568 var targetValue;569 // Overrides should take precedence...570 // they are going to be a part of the new route.571 if (overrides[target]) {572 targetValue = overrides[target];573 } else {574 targetValue = RouteState.route[target];575 }576 RouteState.config[source].dependency =577 target + ':' + targetValue;578 } else {579 RouteState.tieToProp(source, target);580 }581};582// These are all operating on top of merge...583RouteState.toggle = function (state, otherState, replaceArrays) {584 var stateObj;585 for (var name in state) {586 if (!state.hasOwnProperty(name)) {587 continue;588 }589 stateObj = RouteState.stateToObject(name);590 if (this.isArray(state[name])) {591 if (!this.route[stateObj.name]) {592 this.route[stateObj.name] = [];593 }594 if (!RouteState.isArray(this.route[stateObj.name])) {595 this.route[stateObj.name] = [].concat(this.route[stateObj.name]);596 }597 var subName;598 for (var i = 0; i < state[name].length; i++) {599 subName = state[name][i];600 if (this.route[stateObj.name].indexOf(subName) === -1) {601 this.merge(state, replaceArrays);602 return;603 }604 }605 } else if (this.route[stateObj.name] !== state[name]) {606 this.merge(state, replaceArrays);607 return;608 }609 }610 // If it made it this far it is the latter state611 this.merge(otherState, replaceArrays);612};613// ===========END ROUTE OPERATORS============614RouteState.debug = function () {615 // $('.routestate_debug').remove();616 var routestateDebug = document.getElementsByClassName('routestate_debug');617 console.log(routestateDebug);618 if (routestateDebug.parentNode !== undefined) {619 routestateDebug.parentNode.removeChild(routestateDebug);620 }621 var html = ['width' + window.naturalWidth + ' | height' + window.naturalHeight];622 var depends;623 for (var i in this.route) {624 if (!RouteState.isFunction(this.route[i])) {625 depends = '';626 if (RouteState.config[i] && RouteState.config[i].dependency) {627 depends = ' (depends on \'' + RouteState.config[i].dependency + '\')';628 }629 if (RouteState.isArray(this.route[i])) {630 html.push(631 i + ' = ' +632 this.route[i].join(',<br/> ') +633 depends634 );635 } else {636 html.push(i + ' = ' + this.route[i] + depends);637 }638 }639 }640 var debugHTML = function (html) {641 return ('<div onclick="routestateDebug.parentNode.removeChild(routestateDebug);" class="routestate_debug" style="padding: 10px; border: 1px solid grey; width:300px; height: auto; background-color: #fff; position: fixed; top: 10px; right: 10px; z-index: 2000000;">' + html +'<br/></div>');642 }643 document.body.innerHTML = debugHTML;644 // document.body.innerHTML('<div onclick=\'routestateDebug.parentNode.removeChild(routestateDebug);\'' +645 // ' class=\'routestate_debug\'' +646 // ' style=\'padding: 10px; border: 1px solid grey;' +647 // ' width:300px; height: auto; background-color: #fff;' +648 // ' position: fixed; top: 10px;' +649 // ' right: 10px; z-index: 2000000;\'>' +650 // html.join('<br/>') +651 // '</div>');652};653// ===========ROUTE STACK==================654RouteState.push = function () {655 this.routeStack.push(this.route.clone());656 return this;657};658RouteState.pop = function () {659 if (this.routeStack.length > 0) {660 this.replace(this.routeStack.pop());661 } else {662 console.log('RouteState: nothing left in the stack.');663 if ( RouteState.errorFunk ) {664 RouteState.errorFunk( "popped empty stack" );665 }666 }667 return this;668};669// ============================================670// ========== RouteStateRoute =================671// ============================================672var RouteStateRoute = function () {};673RouteStateRoute.prototype.toHash = function () {674 var routeStr = this.toHashString();675 RouteState.targetDocument.location.hash = routeStr;676};677// ===========SERIALIZERS==================678RouteStateRoute.prototype.toHashString = function () {679 var routeConfig;680 var routeObj = this.toObject();681 var routeArr = [];682 var defaultWeight = 100000;683 for (var name in routeObj) {684 if (!routeObj.hasOwnProperty(name)) {685 continue;686 }687 // See if we are supposed to show this...688 // make sure to get the top most config...689 routeConfig = RouteState.config[name];690 if (routeConfig) {691 // ignore this if it shouldn't be in hash692 if (693 typeof routeConfig.show_in_hash !== 'undefined' &&694 routeConfig.show_in_hash === false695 ) {696 continue;697 }698 } else {699 routeConfig = {700 weight: defaultWeight701 };702 }703 var weight = (routeConfig.weight) ?704 routeConfig.weight : defaultWeight;705 if (RouteState.isArray(routeObj[name])) {706 routeArr.push({707 name: name,708 val: routeObj[name].join(','),709 weight: weight710 });711 } else {712 routeArr.push({713 name: name,714 val: routeObj[name],715 weight: weight716 });717 }718 }719 // Sort according to weight720 routeArr.sort(function (a, b) {721 if (a.weight < b.weight) {722 return -1;723 }724 if (a.weight > b.weight) {725 return 1;726 }727 return 0;728 });729 var nameArr = [];730 var nameLookup = {};731 var valArr = [];732 var dependancyArr = [];733 // Finally put it all together in correct order...734 for (var key in routeArr) {735 // Skip loop if the property is from prototype736 if (!routeArr.hasOwnProperty(key)) {737 continue;738 }739 var obj = routeArr[key];740 nameArr.push(obj.name);741 valArr.push(obj.val);742 nameLookup[obj.name] = key;743 }744 // Now add dependencies, but via index of the name...745 var depnameArr = false;746 var showDependencies = false;747 routeArr.forEach(function(value) {748 if (749 RouteState.config &&750 RouteState.config[value.name] &&751 RouteState.config[value.name].dependency752 ) {753 depnameArr = RouteState.config[value.name].dependency.split(':');754 if (depnameArr.length > 1) {755 dependancyArr.push(nameLookup[depnameArr[0]] + ':' + depnameArr[1]);756 showDependencies = true;757 } else {758 dependancyArr.push(nameLookup[depnameArr[0]]);759 showDependencies = true;760 }761 } else {762 dependancyArr.push('');763 }764 }, this);765 if (valArr.length > 0) {766 if (showDependencies) {767 return '#!/' + valArr.join('/') + '/{' + nameArr.join(',') + '}[' + dependancyArr.join(',') + ']';768 }769 return '#!/' + valArr.join('/') + '/{' + nameArr.join(',') + '}';770 }771 return '';772};773RouteStateRoute.prototype.serializedToBodyClasses = function (prefix) {774 var bodyClasses = [];775 // Put pathname in there...776 // pathname always has a preceeding slash777 if (RouteState.serializePathname && RouteState.targetDocument !== undefined) {778 bodyClasses.push(779 prefix + 'pathname' + RouteState.targetDocument.location.pathname.replace(/\//g, '_')780 );781 }782 var routeObj = this.toObject();783 for (var name in routeObj) {784 if (!routeObj.hasOwnProperty(name)) {785 continue;786 }787 // See if we are supposed to show this...788 var routeConfig = RouteState.config[name];789 if (routeConfig) {790 if (791 typeof routeConfig.show_in_body !== 'undefined' &&792 routeConfig.show_in_body === false793 ) {794 continue;795 }796 }797 if (RouteState.isArray(routeObj[name])) {798 var element;799 for (var e = 0; e < routeObj[name].length; e++) {800 element = routeObj[name][e];801 bodyClasses.push(prefix + name + '_' + element);802 }803 } else {804 bodyClasses.push(prefix + name + '_' + routeObj[name]);805 }806 // Just a name, boolean lookup thing807 bodyClasses.push(prefix + name);808 }809 if (bodyClasses.length === 0) {810 bodyClasses.push(prefix + 'empty');811 }812 return bodyClasses.join(' ');813};814RouteStateRoute.prototype.cleanRoute = function () {815 var dependancyHits = 0;816 var dependencyArr;817 for (var name in this) {818 if (!RouteState.isFunction(this[name])) {819 var routeConfig = RouteState.config[name];820 if (routeConfig && typeof routeConfig.dependency !== 'undefined') {821 // ignore this if it has a missing dependancy822 dependencyArr = routeConfig.dependency.split(':');823 if (dependencyArr.length > 1) {824 if (!this[dependencyArr[0]] ||825 String(this[dependencyArr[0]]) !== String(dependencyArr[1])826 ) {827 dependancyHits++;828 delete this[name];829 }830 } else if (!this[routeConfig.dependency]) {831 dependancyHits++;832 delete this[name];833 }834 }835 // Clean out empty values...836 if (!this[name] || this[name] === '') {837 delete this[name];838 }839 }840 }841 if (dependancyHits > 0) {842 this.cleanRoute();843 }844};845RouteStateRoute.prototype.toObject = function () {846 var routeObj = {};847 for (var name in this) {848 if (!RouteState.isFunction(this[name])) {849 routeObj[name] = this[name];850 }851 }852 return routeObj;853};854// ===============END SERIALIZERS=============855RouteStateRoute.prototype.toElementClass = function (element, prefix) {856 var bodyClass = element[0].classList.value;857 if (bodyClass) {858 var bodyClassList = bodyClass.split(/\s+/);859 bodyClassList.forEach(function(index, item) {860 if (index.indexOf(prefix) === 0) {861 element[0].classList.remove(index);862 }863 }, this);864 }865 var serializedClasses = this.serializedToBodyClasses(prefix);866 var serializedClassList = serializedClasses.split(/\s+/);867 serializedClassList.forEach(function(item, index) {868 element[0].classList.add(item);869 }, this);870};871RouteStateRoute.prototype.clone = function (overrides, replaceArrays) {872 var routeState = RouteState.factory(this);873 if (!replaceArrays) {874 replaceArrays = false;875 }876 if (overrides) {877 for (var i in overrides) {878 if (!RouteState.isFunction(overrides[i])) {879 if (RouteState.isArray(overrides[i])) {880 if (replaceArrays) {881 routeState[i] = [].concat(overrides[i]);882 } else {883 if (!routeState[i]) {884 routeState[i] = [];885 }886 if (!RouteState.isArray(routeState[i])) {887 routeState[i] = [].concat(routeState[i]);888 }889 var override;890 for (var p = 0; p < overrides[i].length; p++) {891 override = String(overrides[i][p]);892 if (override.indexOf('-') === 0) {893 override = override.replace('-', '');894 var index = routeState[i].indexOf(override);895 if (index > -1) {896 routeState[i].splice(index, 1);897 }898 } else if (routeState[i].indexOf(override) === -1) {899 routeState[i].push(override);900 }901 }902 }903 } else {904 routeState[i] = overrides[i];905 }906 }907 }908 }909 return routeState;...
taskbarElement.js
Source:taskbarElement.js
1/*2Copyright (c) 2012 Tony Germaneri3Permission is hereby granted,4free of charge, to any person obtaining a copy of this software 5and associated documentation files (the "Software"), to deal in 6the Software without restriction, including without limitation the7rights to use, copy, modify, merge, publish, distribute, 8sublicense, and/or sell copies of the Software, and to permit 9persons to whom the Software is furnished to do so, subject to the10following conditions:11The above copyright notice and this 12permission notice shall be included in all copies or substantial 13portions of the Software.14THE SOFTWARE IS PROVIDED "AS IS", 15WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 16NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 17PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 19OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20OTHERWISE, AR21SING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE22OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.23*/24/**25* Style of the task bar element.26* @constructor27* @name Rendition.UI.TaskBarElementStyle28*/29Rendition.UI.TaskBarElementStyle = function() {30 var instance = {}31 /**32 * The unique id of this instance.33 * @name TaskBarElementStyle.id34 * @memberOf Rendition.UI.TaskBarElementStyle.prototype35 * @type Native.String36 * @public37 * @property38 */39 instance.id = 'uid_' + Rendition.UI.createId();40 /**41 * The type of widget. Returns taskBarElementStyle.42 * @name TaskBarElementStyle.type43 * @memberOf Rendition.UI.TaskBarElementStyle.prototype44 * @type Native.String45 * @public46 * @property47 */48 instance.type = 'taskBarElementStyle';49 /**50 * When estimating text length, how many PX per characters should be used.51 * @name TaskBarElementStyle.charToPx52 * @memberOf Rendition.UI.TaskBarElementStyle.prototype53 * @type Native.Integer54 * @public55 * @property56 */57 instance.charToPx = 7;58 /**59 * The maximum width in PX that the element can be.60 * @name TaskBarElementStyle.maxWidth61 * @memberOf Rendition.UI.TaskBarElementStyle.prototype62 * @type Native.Integer63 * @public64 * @property65 */66 instance.maxWidth = 250;67 /**68 * The maximum number of visible characters in the element. This value is calculated: maxWidth / charToPx.69 * @name TaskBarElementStyle.maxChars70 * @memberOf Rendition.UI.TaskBarElementStyle.prototype71 * @type Native.Integer72 * @private73 * @property74 */75 instance.maxChars = instance.maxWidth / instance.charToPx;76 /**77 * This rect represents the text height, the offset left and offset top and the width to add.78 * This object looks like { x: 13, y: 0, h: 20, w: 0 }.79 * @name TaskBarElementStyle.textRect80 * @memberOf Rendition.UI.TaskBarElementStyle.prototype81 * @type Native.Object82 * @public83 * @property84 */85 instance.textRect = { x: 13, y: 0, h: 20, w: 0 }86 /**87 * This rect represents the height of the element.88 * This object looks like { x: 0, y: 0, h: 20, w: 0 }.89 * @name TaskBarElementStyle.centerRect90 * @memberOf Rendition.UI.TaskBarElementStyle.prototype91 * @type Native.Object92 * @public93 * @property94 */95 instance.centerRect = { x: 0, y: 0, h: 20, w: 0 }96 /**97 * This rect represents the height and width of the left side element.98 * This object looks like { x: 0, y: 0, h: 20, w: 5 }.99 * @name TaskBarElementStyle.leftRect100 * @memberOf Rendition.UI.TaskBarElementStyle.prototype101 * @type Native.Object102 * @public103 * @property104 */105 instance.leftRect = { x: 0, y: 0, h: 20, w: 5 }106 /**107 * This rect represents the height and width of the right side element.108 * This object looks like { x: 0, y: 0, h: 20, w: 5 }.109 * @name TaskBarElementStyle.rightRect110 * @memberOf Rendition.UI.TaskBarElementStyle.prototype111 * @type Native.Object112 * @public113 * @property114 */115 instance.rightRect = { x: 0, y: 0, h: 20, w: 5 }116 /**117 * The CSS background property of the center element.118 * @name TaskBarElementStyle.centerBackground119 * @memberOf Rendition.UI.TaskBarElementStyle.prototype120 * @type Native.String121 * @public122 * @property123 */124 instance.centerBackground = '#F00';125 /**126 * The CSS background property of the left element.127 * @name TaskBarElementStyle.leftBackground128 * @memberOf Rendition.UI.TaskBarElementStyle.prototype129 * @type Native.String130 * @public131 * @property132 */133 instance.leftBackground = '#700';134 /**135 * The CSS background property of the right element.136 * @name TaskBarElementStyle.rightBackground137 * @memberOf Rendition.UI.TaskBarElementStyle.prototype138 * @type Native.String139 * @public140 * @property141 */142 instance.rightBackground = '#FF9';143 /**144 * The CSS background property of the center element when the mouse hovers over it.145 * @name TaskBarElementStyle.centerHoverBackground146 * @memberOf Rendition.UI.TaskBarElementStyle.prototype147 * @type Native.String148 * @public149 * @property150 */151 instance.centerHoverBackground = '#070';152 /**153 * The CSS background property of the left element when the mouse hovers over it.154 * @name TaskBarElementStyle.leftHoverBackground155 * @memberOf Rendition.UI.TaskBarElementStyle.prototype156 * @type Native.String157 * @public158 * @property159 */160 instance.leftHoverBackground = '#00F';161 /**162 * The CSS background property of the right element when the mouse hovers over it.163 * @name TaskBarElementStyle.rightHoverBackground164 * @memberOf Rendition.UI.TaskBarElementStyle.prototype165 * @type Native.String166 * @public167 * @property168 */169 instance.rightHoverBackground = '#007';170 /**171 * The CSS font property of the element.172 * @name TaskBarElementStyle.font173 * @memberOf Rendition.UI.TaskBarElementStyle.prototype174 * @type Native.String175 * @public176 * @property177 */178 instance.font = 'normal 12px \'Trebuchet MS\',\'Arial\',\'Helvetica\',\'Sans-serif\'';179 /**180 * The CSS text-align property of the element.181 * @name TaskBarElementStyle.textAlignment182 * @memberOf Rendition.UI.TaskBarElementStyle.prototype183 * @type Native.String184 * @public185 * @property186 */187 instance.textAlignment = 'left';188 /**189 * The CSS color property of the element text.190 * @name TaskBarElementStyle.textColor191 * @memberOf Rendition.UI.TaskBarElementStyle.prototype192 * @type Native.String193 * @public194 * @property195 */196 instance.textColor = '#000';197 return instance;198}199/* WIDGIT: TASKBARELEMENT */200/**201* Creates a task bar element for the task bar. Elements are automatically added by202* <link xlink:href="Rendition.UI.Desktop"/> when a <link xlink:href="Rendition.UI.Dialog"/>203* is instantiated.204* @param {Native.Object} dialogWindow The <link xlink:href="Rendition.UI.Dialog"/> that represents this instance. 205* @param {Native.Object} objTaskBar The <link xlink:href="Rendition.UI.TaskBar"/> this instance attaches to. 206* @param {Native.Object} objTaskBar The <link xlink:href="Rendition.elementStyle"/> to use. 207* @constructor208* @name Rendition.UI.TaskBarElement209*/210Rendition.UI.TaskBarElement = function(dialogWindow, objTaskBar, elementStyle) {211 var instance = {}212 /**213 * The unique id of this instance.214 * @name TaskBarElement.id215 * @memberOf Rendition.UI.TaskBarElement.prototype216 * @type Native.String217 * @public218 * @property219 */220 instance.id = 'uid_' + Rendition.UI.createId();221 /**222 * The type of widget. Returns RenditionTaskBarElement.223 * @name TaskBarElement.type224 * @memberOf Rendition.UI.TaskBarElement.prototype225 * @type Native.String226 * @public227 * @property228 */229 instance.type = 'RenditionTaskBarElement';230 instance.text = document.createTextNode(dialogWindow.titleValue);231 instance.width = dialogWindow.titleValue.length * elementStyle.charToPx;232 /**233 * updates the title, clipping and redrawing the text.234 * @function235 * @name TaskBarElement.updatetitle236 * @memberOf Rendition.UI.TaskBarElement.prototype237 * @public238 * @returns undefined.239 */240 instance.updatetitle = function() {241 if (instance.width > elementStyle.maxWidth) {242 instance.width = elementStyle.maxWidth;243 }244 if (instance.width > objTaskBar.maxWindowWidth) {245 instance.width = objTaskBar.maxWindowWidth;246 }247 var maxChars = instance.width / elementStyle.charToPx;248 if (maxChars < dialogWindow.titleValue.length) {249 instance.text.data = dialogWindow.titleValue.substring(0, maxChars) + '...';250 } else {251 instance.text.data = dialogWindow.titleValue;252 }253 }254 instance.updatetitle();255 /**256 * Activates the element, bringing its <link xlink:href="Rendition.UI.Dialog"/> to the front.257 * @function258 * @name TaskBarElement.onclick259 * @memberOf Rendition.UI.TaskBarElement.prototype260 * @public261 * @returns undefined.262 */263 instance.onclick = function() {264 if (dialogWindow.windowState == 2) {265 dialogWindow.restore();266 } else {267 if (dialogWindow.isTopmostWindow()) {268 dialogWindow.minimize();269 } else {270 dialogWindow.activate();271 }272 }273 return false;274 }275 instance.dialog = dialogWindow;276 /**277 * The left DHTML div element.278 * @name TaskBarElement.elementLeft279 * @memberOf Rendition.UI.TaskBarElement.prototype280 * @type Native.DHTMLElement281 * @private282 * @property283 */284 instance.elementLeft = document.createElement('div');285 instance.elementLeft.style.position = 'absolute';286 instance.elementLeft.style.top = elementStyle.leftRect.y + 'px';287 instance.elementLeft.style.left = elementStyle.leftRect.x + objTaskBar.leftOffset + 'px';288 instance.elementLeft.style.width = elementStyle.leftRect.w + 'px';289 instance.elementLeft.style.height = elementStyle.leftRect.h + 'px';290 instance.elementLeft.style.background = elementStyle.leftBackground;291 objTaskBar.content.appendChild(instance.elementLeft);292 Rendition.UI.appendEvent('mousedown', instance.elementLeft, instance.onclick, false);293 /**294 * The right DHTML div element.295 * @name TaskBarElement.elementRight296 * @memberOf Rendition.UI.TaskBarElement.prototype297 * @type Native.DHTMLElement298 * @private299 * @property300 */301 instance.elementRight = document.createElement('div');302 instance.elementRight.style.position = 'absolute';303 instance.elementRight.style.top = elementStyle.rightRect.y + 'px';304 instance.elementRight.style.left = elementStyle.leftRect.x + objTaskBar.leftOffset + elementStyle.centerRect.w + elementStyle.leftRect.w + instance.width + 'px';305 instance.elementRight.style.width = elementStyle.rightRect.w + 'px';306 instance.elementRight.style.height = elementStyle.rightRect.h + 'px';307 instance.elementRight.style.background = elementStyle.rightBackground;308 objTaskBar.content.appendChild(instance.elementRight);309 Rendition.UI.appendEvent('mousedown', instance.elementRight, instance.onclick, false);310 /**311 * The center DHTML div element.312 * @name TaskBarElement.elementCenter313 * @memberOf Rendition.UI.TaskBarElement.prototype314 * @type Native.DHTMLElement315 * @private316 * @property317 */318 instance.elementCenter = document.createElement('div');319 instance.elementCenter.style.position = 'absolute';320 instance.elementCenter.style.top = elementStyle.centerRect.y + 'px';321 instance.elementCenter.style.left = elementStyle.centerRect.x + objTaskBar.leftOffset + elementStyle.leftRect.x + elementStyle.leftRect.w + 'px';322 instance.elementCenter.style.width = elementStyle.centerRect.w + instance.width + 'px';323 instance.elementCenter.style.height = elementStyle.centerRect.h + 'px';324 instance.elementCenter.style.background = elementStyle.centerBackground;325 objTaskBar.content.appendChild(instance.elementCenter);326 Rendition.UI.appendEvent('mousedown', instance.elementCenter, instance.onclick, false);327 /**328 * The text holder DHTML div element.329 * @name TaskBarElement.elementText330 * @memberOf Rendition.UI.TaskBarElement.prototype331 * @type Native.DHTMLElement332 * @private333 * @property334 */335 instance.elementText = document.createElement('div');336 instance.elementText.style.position = 'absolute';337 instance.elementText.style.overflow = 'hidden';338 instance.elementText.style.cursor = 'default';339 instance.elementText.style.top = elementStyle.textRect.y + 'px';340 instance.elementText.style.left = elementStyle.textRect.x + objTaskBar.leftOffset + 'px';341 instance.elementText.style.width = elementStyle.textRect.w + instance.width + 'px';342 instance.elementText.style.height = elementStyle.textRect.h + 'px';343 instance.elementText.style.font = elementStyle.font;344 instance.elementText.style.textAlign = elementStyle.textAlignment;345 objTaskBar.content.appendChild(instance.elementText);346 instance.elementText.appendChild(instance.text);347 Rendition.UI.appendEvent('mousedown', instance.elementText, instance.onclick, false);348 objTaskBar.leftOffset += instance.width + objTaskBar.style.horizontalSpacing + elementStyle.leftRect.w + elementStyle.leftRect.w;349 return instance;...
content.js
Source:content.js
...29// chrome.runtime.sendMessage("contentMounted");30document.addEventListener(31 "click",32 function (e) {33 if (isTopMostWindow()) {34 // topmost window35 sendClickToBackground({36 clientX: e.clientX,37 clientY: e.clientY,38 });39 } else {40 // embedded window41 try {42 sendMessageToParentWindow(e.target.ownerDocument.defaultView.parent, {43 clientX: e.clientX,44 clientY: e.clientY,45 });46 } catch (error) {47 console.error(error);48 }49 }50 },51 true52);53window.addEventListener("message", function (messageEvent) {54 // TODO: check all frames to find which one sent message55 console.log(messageEvent);56 try {57 const { type, payload } = JSON.parse(messageEvent.data);58 if (typeof type === "string" && type === iframeClickAction) {59 const frameOffset = {60 x: 0,61 y: 0,62 };63 // Find message source iframe64 const currentWindowIframes = document.getElementsByTagName("IFRAME");65 for (let i = 0; i < currentWindowIframes.length; i++) {66 const iframe = currentWindowIframes[i];67 // Cross-browser way to get iframe's window object68 const frameWindow =69 iframe.contentWindow || iframe.contentDocument.defaultView;70 // Comparison71 if (messageEvent.source === frameWindow) {72 // get relative offset73 const iframeRect = iframe.getBoundingClientRect();74 frameOffset.x = Math.max(0, iframeRect.x);75 frameOffset.y = Math.max(0, iframeRect.y);76 }77 }78 // calculate iframe sender offset79 const { event } = payload;80 const nextEvent = {81 clientX: Number(event.clientX) + frameOffset.x,82 clientY: Number(event.clientY) + frameOffset.y,83 };84 if (isTopMostWindow()) {85 sendClickToBackground(nextEvent);86 } else {87 sendMessageToParentWindow(window.parent, nextEvent);88 }89 }90 } catch (error) {91 console.error(error);92 }...
top-same-origin-window.js
Source:top-same-origin-window.js
...21 return false;22 }23 return true;24 }25 function isTopMostWindow(w) {26 return w === w.parent;27 }28 while (!isTopMostWindow(parentOf) && satisfiesSameOrigin(parentOf.parent)) {29 parentOf = parentOf.parent;30 }31 return parentOf;32 };...
Using AI Code Generation
1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.contains('type').click()4 cy.url().should('include', '/commands/actions')5 cy.isTopMostWindow().then((isTopMostWindow) => {6 expect(isTopMostWindow).to.be.true7 })8 cy.window().then((window) => {9 })10 cy.isTopMostWindow().then((isTopMostWindow) => {11 expect(isTopMostWindow).to.be.false12 })13 })14})
Using AI Code Generation
1cy.isTopMostWindow().then((isTopMostWindow) => {2 if (isTopMostWindow) {3 cy.log('This is the top most window');4 } else {5 cy.log('This is not the top most window');6 }7});8cy.isTopMostWindow().then((isTopMostWindow) => {9 if (isTopMostWindow) {10 cy.log('This is the top most window');11 } else {12 cy.log('This is not the top most window');13 }14});15cy.isTopMostWindow().then((isTopMostWindow) => {16 if (isTopMostWindow) {17 cy.log('This is the top most window');18 } else {19 cy.log('This is not the top most window');20 }21});22cy.isTopMostWindow().then((isTopMostWindow) => {23 if (isTopMostWindow) {24 cy.log('This is the top most window');25 } else {26 cy.log('This is not the top most window');27 }28});29cy.isTopMostWindow().then((isTopMostWindow) => {30 if (isTopMostWindow) {31 cy.log('This is the top most window');32 } else {33 cy.log('This is not the top most window');34 }35});36cy.isTopMostWindow().then((isTopMostWindow) => {37 if (isTopMostWindow) {38 cy.log('This is the top most window');39 } else {40 cy.log('This is not the top most window');41 }42});43cy.isTopMostWindow().then((isTopMostWindow) => {44 if (isTopMostWindow) {45 cy.log('This is the top most window');46 } else {47 cy.log('This is not the top most window');48 }49});50cy.isTopMostWindow().then((isTopMostWindow) => {51 if (isTopMostWindow) {52 cy.log('This is the top most window');53 }
Using AI Code Generation
1describe('Test', () => {2 it('Test', () => {3 cy.visit('www.google.com');4 cy.isTopMostWindow().then((isTopMostWindow) => {5 if (isTopMostWindow) {6 cy.get('input[type="text"]').type('Cypress');7 }8 });9 });10});
Using AI Code Generation
1cy.isTopMostWindow().then((isTopMostWindow) => {2 if (isTopMostWindow) {3 }4});5Cypress.Commands.add('isTopMostWindow', () => {6 return cy.window().then((win) => {7 const winParent = win.parent;8 if (winParent === win) {9 return true;10 }11 if (winParent === null) {12 return true;13 }14 if (winParent === undefined) {15 return true;16 }17 return false;18 });19});20Cypress.Commands.add('isTopMostWindow', () => {21 return cy.window().then((win) => {22 const winParent = win.parent;23 if (winParent === win) {24 return true;25 }26 if (winParent === null) {27 return true;28 }29 if (winParent === undefined) {30 return true;31 }32 return false;33 });34});35Cypress.Commands.add('isTopMostWindow', () => {36 return cy.window().then((win) => {37 const winParent = win.parent;38 if (winParent === win) {39 return true;40 }41 if (winParent === null) {42 return true;43 }44 if (winParent === undefined) {45 return true;46 }47 return false;48 });49});50Cypress.Commands.add('isTopMostWindow', () => {51 return cy.window().then((win) => {52 const winParent = win.parent;53 if (winParent === win) {54 return true;55 }56 if (winParent === null) {
Using AI Code Generation
1describe('Cypress Demo', function () {2 it('Cypress Demo', function () {3 cy.get('input[name="q"]').type('cypress')4 cy.get('input[name="btnK"]').click()5 cy.get('[class="LC20lb"]').should('be.visible')6 cy.get('[class="LC20lb"]').click()7 cy.window().then((win) => {8 expect(win.isTopMostWindow()).to.be.true9 })10 cy.get('[class="docs-hero-title"]').should('be.visible')11 })12})
Using AI Code Generation
1cy.window().then(win => {2 cy.log('is top most window', win.isTopMostWindow())3})4cy.window().then(win => {5 cy.log('is top most window', win.isTopMostWindow())6})7MIT © [Vivek Kumar](
Using AI Code Generation
1it('is the top most window', () => {2 cy.isTopMostWindow()3})4it('is the window focused', () => {5 cy.isWindowFocused()6})7it('is the window maximized', () => {8 cy.isWindowMaximized()9})10it('is the window minimized', () => {11 cy.isWindowMinimized()12})13it('is the window normal', () => {14 cy.isWindowNormal()15})
Using AI Code Generation
1cy.isTopMostWindow().should('be.true');2cy.isNotTopMostWindow().should('be.false');3cy.isTopMostWindowByTitle('Cypress - Google Search').should('be.true');4cy.isNotTopMostWindowByTitle('Cypress - Google Search').should('be.false');5cy.get('a')6 .contains('Open New Window')7 .click();8cy.switchToWindowByIndex(1);
Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.
You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.
Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.
Get 100 minutes of automation test minutes FREE!!