3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
8 * @class Ext.WindowGroup
9 * An object that represents a group of {@link Ext.Window} instances and provides z-order management
10 * and window activation behavior.
13 Ext.WindowGroup = function(){
19 var sortWindows = function(d1, d2){
20 return (!d1._lastAccess || d1._lastAccess < d2._lastAccess) ? -1 : 1;
24 var orderWindows = function(){
25 var a = accessList, len = a.length;
28 var seed = a[0].manager.zseed;
29 for(var i = 0; i < len; i++){
31 if(win && !win.hidden){
32 win.setZIndex(seed + (i*10));
40 var setActiveWin = function(win){
43 front.setActive(false);
53 var activateLast = function(){
54 for(var i = accessList.length-1; i >=0; --i) {
55 if(!accessList[i].hidden){
56 setActiveWin(accessList[i]);
66 * The starting z-index for windows (defaults to 9000)
67 * @type Number The z-index value
72 register : function(win){
75 win.on('hide', activateLast);
79 unregister : function(win){
81 win.un('hide', activateLast);
82 accessList.remove(win);
86 * Gets a registered window by id.
87 * @param {String/Object} id The id of the window or a {@link Ext.Window} instance
88 * @return {Ext.Window}
91 return typeof id == "object" ? id : list[id];
95 * Brings the specified window to the front of any other active windows.
96 * @param {String/Object} win The id of the window or a {@link Ext.Window} instance
97 * @return {Boolean} True if the dialog was brought to the front, else false
98 * if it was already in front
100 bringToFront : function(win){
103 win._lastAccess = new Date().getTime();
111 * Sends the specified window to the back of other active windows.
112 * @param {String/Object} win The id of the window or a {@link Ext.Window} instance
113 * @return {Ext.Window} The window
115 sendToBack : function(win){
117 win._lastAccess = -(new Date().getTime());
123 * Hides all windows in the group.
125 hideAll : function(){
127 if(list[id] && typeof list[id] != "function" && list[id].isVisible()){
134 * Gets the currently-active window in the group.
135 * @return {Ext.Window} The active window
137 getActive : function(){
142 * Returns zero or more windows in the group using the custom search function passed to this method.
143 * The function should accept a single {@link Ext.Window} reference as its only argument and should
144 * return true if the window matches the search criteria, otherwise it should return false.
145 * @param {Function} fn The search function
146 * @param {Object} scope (optional) The scope in which to execute the function (defaults to the window
147 * that gets passed to the function if not specified)
148 * @return {Array} An array of zero or more matching windows
150 getBy : function(fn, scope){
152 for(var i = accessList.length-1; i >=0; --i) {
153 var win = accessList[i];
154 if(fn.call(scope||win, win) !== false){
162 * Executes the specified function once for every window in the group, passing each
163 * window as the only parameter. Returning false from the function will stop the iteration.
164 * @param {Function} fn The function to execute for each item
165 * @param {Object} scope (optional) The scope in which to execute the function
167 each : function(fn, scope){
169 if(list[id] && typeof list[id] != "function"){
170 if(fn.call(scope || list[id], list[id]) === false){
181 * @class Ext.WindowMgr
182 * @extends Ext.WindowGroup
183 * The default global window group that is available automatically. To have more than one group of windows
184 * with separate z-order stacks, create additional instances of {@link Ext.WindowGroup} as needed.
187 Ext.WindowMgr = new Ext.WindowGroup();