2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
10 * @class Ext.WindowGroup
\r
11 * An object that represents a group of {@link Ext.Window} instances and provides z-order management
\r
12 * and window activation behavior.
\r
15 Ext.WindowGroup = function(){
\r
17 var accessList = [];
\r
21 var sortWindows = function(d1, d2){
\r
22 return (!d1._lastAccess || d1._lastAccess < d2._lastAccess) ? -1 : 1;
\r
26 var orderWindows = function(){
\r
27 var a = accessList, len = a.length;
\r
29 a.sort(sortWindows);
\r
30 var seed = a[0].manager.zseed;
\r
31 for(var i = 0; i < len; i++){
\r
33 if(win && !win.hidden){
\r
34 win.setZIndex(seed + (i*10));
\r
42 var setActiveWin = function(win){
\r
45 front.setActive(false);
\r
49 win.setActive(true);
\r
55 var activateLast = function(){
\r
56 for(var i = accessList.length-1; i >=0; --i) {
\r
57 if(!accessList[i].hidden){
\r
58 setActiveWin(accessList[i]);
\r
68 * The starting z-index for windows (defaults to 9000)
\r
69 * @type Number The z-index value
\r
74 register : function(win){
\r
76 accessList.push(win);
\r
77 win.on('hide', activateLast);
\r
81 unregister : function(win){
\r
82 delete list[win.id];
\r
83 win.un('hide', activateLast);
\r
84 accessList.remove(win);
\r
88 * Gets a registered window by id.
\r
89 * @param {String/Object} id The id of the window or a {@link Ext.Window} instance
\r
90 * @return {Ext.Window}
\r
93 return typeof id == "object" ? id : list[id];
\r
97 * Brings the specified window to the front of any other active windows.
\r
98 * @param {String/Object} win The id of the window or a {@link Ext.Window} instance
\r
99 * @return {Boolean} True if the dialog was brought to the front, else false
\r
100 * if it was already in front
\r
102 bringToFront : function(win){
\r
103 win = this.get(win);
\r
105 win._lastAccess = new Date().getTime();
\r
113 * Sends the specified window to the back of other active windows.
\r
114 * @param {String/Object} win The id of the window or a {@link Ext.Window} instance
\r
115 * @return {Ext.Window} The window
\r
117 sendToBack : function(win){
\r
118 win = this.get(win);
\r
119 win._lastAccess = -(new Date().getTime());
\r
125 * Hides all windows in the group.
\r
127 hideAll : function(){
\r
128 for(var id in list){
\r
129 if(list[id] && typeof list[id] != "function" && list[id].isVisible()){
\r
136 * Gets the currently-active window in the group.
\r
137 * @return {Ext.Window} The active window
\r
139 getActive : function(){
\r
144 * Returns zero or more windows in the group using the custom search function passed to this method.
\r
145 * The function should accept a single {@link Ext.Window} reference as its only argument and should
\r
146 * return true if the window matches the search criteria, otherwise it should return false.
\r
147 * @param {Function} fn The search function
\r
148 * @param {Object} scope (optional) The scope in which to execute the function (defaults to the window
\r
149 * that gets passed to the function if not specified)
\r
150 * @return {Array} An array of zero or more matching windows
\r
152 getBy : function(fn, scope){
\r
154 for(var i = accessList.length-1; i >=0; --i) {
\r
155 var win = accessList[i];
\r
156 if(fn.call(scope||win, win) !== false){
\r
164 * Executes the specified function once for every window in the group, passing each
\r
165 * window as the only parameter. Returning false from the function will stop the iteration.
\r
166 * @param {Function} fn The function to execute for each item
\r
167 * @param {Object} scope (optional) The scope in which to execute the function
\r
169 each : function(fn, scope){
\r
170 for(var id in list){
\r
171 if(list[id] && typeof list[id] != "function"){
\r
172 if(fn.call(scope || list[id], list[id]) === false){
\r
183 * @class Ext.WindowMgr
\r
184 * @extends Ext.WindowGroup
\r
185 * The default global window group that is available automatically. To have more than one group of windows
\r
186 * with separate z-order stacks, create additional instances of {@link Ext.WindowGroup} as needed.
\r
189 Ext.WindowMgr = new Ext.WindowGroup();