[Edit: Animal offered a very nice riff on the same theme further down in this thread.]
Ever notice how, by default, new Ext Windows are created in the center of their containing element? I thought it'd be nice to have the first window start at the top left, and each subsequent window start down and to the right a bit, like in most OSes. Hence this plugin.
To call a window that will cascade:
PHP Code:
win = new Ext.Window({
layout:'fit',
width:500,
height:300,
closeAction:'hide',
plain: true,
plugins: [ new Ext.ux.plugins.CascadeWindows() ],
offSetX: 15,
offSetY: -15,
items: [{title: 'Hello World', html: 'lorem ipsum'}],
});
win.show();
The offSetX and offSetY options set how far down and over each window is created. If you don't specify them, the defaults are 15px. Oh, and I should note that cascading is relative to the window's windowgroup, defaulting to the global Ext.WindowMgr if one hasn't been specified.
And here's the plugin code:
PHP Code:
Ext.namespace('Ext.ux.plugins');
Ext.ux.plugins.CascadeWindows = function(config) {
Ext.apply(this, config);
};
Ext.extend(Ext.ux.plugins.CascadeWindows, Ext.util.Observable, {
init:function(win) {
Ext.apply(win, {
onRender:win.onRender.createSequence(function(ct, position) {
var mgr = (this.manager)?this.manager:Ext.WindowMgr;
var ctr = this.container;
var size = { width: this.width,
height: this.height };
var ctSize = this.getEl().getAlignToXY(ctr.id, "tl-br");
var offSetX = (this.offSetX)?this.offSetX:15;
var offSetY = (this.offsetY)?this.offsetY:-15;
if (mgr.cascaded) {
mgr.cascaded += 1;
} else {
mgr.cascaded = 1;
}
if (mgr.cascaded == 1) {
mgr.lastXY = this.getEl().getAlignToXY(ctr.id, "tl-tl?", [offSetX,offSetY]);
} else {
mgr.lastXY[0] += 40;
mgr.lastXY[1] += 25;
var testBR = {bottom: (size.height + mgr.lastXY[1]),
right: (size.width + mgr.lastXY[0]) };
if (testBR.bottom > ctSize[1]) {
mgr.lastXY[1] = 0;
}
if (testBR.right > ctSize[0]) {
mgr.lastXY[0] = 15;
}
}
this.cascaded = true;
this.origPos = [];
this.origPos[0] = mgr.lastXY[0];
this.origPos[1] = mgr.lastXY[1];
this.setPosition(mgr.lastXY[0], mgr.lastXY[1]);
}),
cascade: function(e) {
this.setPosition(this.origPos[0], this.origPos[1]);
}
});
} // end of function init
}); // end of extend