📄 basicdialog.js
字号:
this.resizeTo(w, h);
return this;
},
/**
* Adds a key listener for when this dialog is displayed. This allows you to hook in a function that will be
* executed in response to a particular key being pressed while the dialog is active.
* @param {Number/Array/Object} key Either the numeric key code, array of key codes or an object with the following options:
* {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
* @param {Function} fn The function to call
* @param {Object} scope (optional) The scope of the function
* @return {Ext.BasicDialog} this
*/
addKeyListener : function(key, fn, scope){
var keyCode, shift, ctrl, alt;
if(typeof key == "object" && !Ext.isArray(key)){
keyCode = key["key"];
shift = key["shift"];
ctrl = key["ctrl"];
alt = key["alt"];
}else{
keyCode = key;
}
var handler = function(dlg, e){
if((!shift || e.shiftKey) && (!ctrl || e.ctrlKey) && (!alt || e.altKey)){
var k = e.getKey();
if(Ext.isArray(keyCode)){
for(var i = 0, len = keyCode.length; i < len; i++){
if(keyCode[i] == k){
fn.call(scope || window, dlg, k, e);
return;
}
}
}else{
if(k == keyCode){
fn.call(scope || window, dlg, k, e);
}
}
}
};
this.on("keydown", handler);
return this;
},
/**
* Returns the TabPanel component (creates it if it doesn't exist).
* Note: If you wish to simply check for the existence of tabs without creating them,
* check for a null 'tabs' property.
* @return {Ext.TabPanel} The tabs component
*/
getTabs : function(){
if(!this.tabs){
this.el.addClass("x-dlg-auto-tabs");
this.body.addClass(this.tabPosition == "bottom" ? "x-tabs-bottom" : "x-tabs-top");
this.tabs = new Ext.TabPanel(this.body.dom, this.tabPosition == "bottom");
}
return this.tabs;
},
/**
* Adds a button to the footer section of the dialog.
* @param {String/Object} config A string becomes the button text, an object can either be a Button config
* object or a valid Ext.DomHelper element config
* @param {Function} handler The function called when the button is clicked
* @param {Object} scope (optional) The scope of the handler function
* @return {Ext.Button} The new button
*/
addButton : function(config, handler, scope){
var dh = Ext.DomHelper;
if(!this.footer){
this.footer = dh.append(this.bwrap, {tag: "div", cls:"x-dlg-ft"}, true);
}
if(!this.btnContainer){
var tb = this.footer.createChild({
cls:"x-dlg-btns x-dlg-btns-"+this.buttonAlign,
html:'<table cellspacing="0"><tbody><tr></tr></tbody></table><div class="x-clear"></div>'
}, null, true);
this.btnContainer = tb.firstChild.firstChild.firstChild;
}
var bconfig = {
handler: handler,
scope: scope,
minWidth: this.minButtonWidth,
hideParent:true
};
if(typeof config == "string"){
bconfig.text = config;
}else{
if(config.tag){
bconfig.dhconfig = config;
}else{
Ext.apply(bconfig, config);
}
}
var btn = new Ext.Button(
bconfig
);
btn.render(this.btnContainer.appendChild(document.createElement("td")));
this.syncBodyHeight();
if(!this.buttons){
/**
* Array of all the buttons that have been added to this dialog via addButton
* @type Array
*/
this.buttons = [];
}
this.buttons.push(btn);
return btn;
},
/**
* Sets the default button to be focused when the dialog is displayed.
* @param {Ext.BasicDialog.Button} btn The button object returned by {@link #addButton}
* @return {Ext.BasicDialog} this
*/
setDefaultButton : function(btn){
this.defaultButton = btn;
return this;
},
// private
getHeaderFooterHeight : function(safe){
var height = 0;
if(this.header){
height += this.header.getHeight();
}
if(this.footer){
var fm = this.footer.getMargins();
height += (this.footer.getHeight()+fm.top+fm.bottom);
}
height += this.bwrap.getPadding("tb")+this.bwrap.getBorderWidth("tb");
height += this.centerBg.getPadding("tb");
return height;
},
// private
syncBodyHeight : function(){
var bd = this.body, cb = this.centerBg, bw = this.bwrap;
var height = this.size.height - this.getHeaderFooterHeight(false);
bd.setHeight(height-bd.getMargins("tb"));
var hh = this.header.getHeight();
var h = this.size.height-hh;
cb.setHeight(h);
bw.setLeftTop(cb.getPadding("l"), hh+cb.getPadding("t"));
bw.setHeight(h-cb.getPadding("tb"));
bw.setWidth(this.el.getWidth(true)-cb.getPadding("lr"));
bd.setWidth(bw.getWidth(true));
if(this.tabs){
this.tabs.syncHeight();
if(Ext.isIE){
this.tabs.el.repaint();
}
}
},
/**
* Restores the previous state of the dialog if Ext.state is configured.
* @return {Ext.BasicDialog} this
*/
restoreState : function(){
var box = Ext.state.Manager.get(this.stateId || (this.el.id + "-state"));
if(box && box.width){
this.xy = [box.x, box.y];
this.resizeTo(box.width, box.height);
}
return this;
},
// private
beforeShow : function(){
this.expand();
if(this.fixedcenter){
this.xy = this.el.getCenterXY(true);
}
if(this.modal){
Ext.getBody().addClass("x-body-masked");
this.mask.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true));
this.mask.show();
}
this.constrainXY();
},
// private
animShow : function(){
var b = Ext.get(this.animateTarget, true).getBox();
this.proxy.setSize(b.width, b.height);
this.proxy.setLocation(b.x, b.y);
this.proxy.show();
this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height,
true, .35, this.showEl.createDelegate(this));
},
/**
* Shows the dialog.
* @param {Mixed} animateTarget (optional) Reset the animation target
* @return {Ext.BasicDialog} this
*/
show : function(animateTarget){
if (this.fireEvent("beforeshow", this) === false){
return;
}
if(this.syncHeightBeforeShow){
this.syncBodyHeight();
}else if(this.firstShow){
this.firstShow = false;
this.syncBodyHeight(); // sync the height on the first show instead of in the constructor
}
this.animateTarget = animateTarget || this.animateTarget;
if(!this.el.isVisible()){
this.beforeShow();
if(this.animateTarget){
this.animShow();
}else{
this.showEl();
}
}
return this;
},
// private
showEl : function(){
this.proxy.hide();
this.el.setXY(this.xy);
this.el.show();
this.adjustAssets(true);
this.toFront();
this.focus();
// IE peekaboo bug - fix found by Dave Fenwick
if(Ext.isIE){
this.el.repaint();
}
this.fireEvent("show", this);
},
/**
* Focuses the dialog. If a defaultButton is set, it will receive focus, otherwise the
* dialog itself will receive focus.
*/
focus : function(){
if(this.defaultButton){
this.defaultButton.focus();
}else{
this.focusEl.focus();
}
},
// private
constrainXY : function(){
if(this.constraintoviewport !== false){
if(!this.viewSize){
if(this.container){
var s = this.container.getSize();
this.viewSize = [s.width, s.height];
}else{
this.viewSize = [Ext.lib.Dom.getViewWidth(),Ext.lib.Dom.getViewHeight()];
}
}
var s = Ext.get(this.container||document).getScroll();
var x = this.xy[0], y = this.xy[1];
var w = this.size.width, h = this.size.height;
var vw = this.viewSize[0], vh = this.viewSize[1];
// only move it if it needs it
var moved = false;
// first validate right/bottom
if(x + w > vw+s.left){
x = vw - w;
moved = true;
}
if(y + h > vh+s.top){
y = vh - h;
moved = true;
}
// then make sure top/left isn't negative
if(x < s.left){
x = s.left;
moved = true;
}
if(y < s.top){
y = s.top;
moved = true;
}
if(moved){
// cache xy
this.xy = [x, y];
if(this.isVisible()){
this.el.setLocation(x, y);
this.adjustAssets();
}
}
}
},
// private
onDrag : function(){
if(!this.proxyDrag){
this.xy = this.el.getXY();
this.adjustAssets();
}
},
// private
adjustAssets : function(doShow){
var x = this.xy[0], y = this.xy[1];
var w = this.size.width, h = this.size.height;
if(doShow === true){
if(this.shadow){
this.shadow.show(this.el);
}
if(this.shim){
this.shim.show();
}
}
if(this.shadow && this.shadow.isVisible()){
this.shadow.show(this.el);
}
if(this.shim && this.shim.isVisible()){
this.shim.setBounds(x, y, w, h);
}
},
// private
adjustViewport : function(w, h){
if(!w || !h){
w = Ext.lib.Dom.getViewWidth();
h = Ext.lib.Dom.getViewHeight();
}
// cache the size
this.viewSize = [w, h];
if(this.modal && this.mask.isVisible()){
this.mask.setSize(w, h); // first make sure the mask isn't causing overflow
this.mask.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true));
}
if(this.isVisible()){
this.constrainXY();
}
},
/**
* Destroys this dialog and all its supporting elements (including any tabs, shim,
* shadow, proxy, mask, etc.) Also removes all event listeners.
* @param {Boolean} removeEl (optional) true to remove the element from the DOM
*/
destroy : function(removeEl){
if(this.isVisible()){
this.animateTarget = null;
this.hide();
}
Ext.EventManager.removeResizeListener(this.adjustViewport, this);
if(this.tabs){
this.tabs.destroy(removeEl);
}
Ext.destroy(
this.shim,
this.proxy,
this.resizer,
this.close,
this.mask
);
if(this.dd){
this.dd.unreg();
}
if(this.buttons){
for(var i = 0, len = this.buttons.length; i < len; i++){
this.buttons[i].destroy();
}
}
this.el.removeAllListeners();
if(removeEl === true){
this.el.update("");
this.el.remove();
}
Ext.DialogManager.unregister(this);
},
// private
startMove : function(){
if(this.proxyDrag){
this.proxy.show();
}
if(this.constraintoviewport !== false){
this.dd.constrainTo(document.body, {right: this.shadowOffset, bottom: this.shadowOffset});
}
},
// private
endMove : function(){
if(!this.proxyDrag){
Ext.dd.DD.prototype.endDrag.apply(this.dd, arguments);
}else{
Ext.dd.DDProxy.prototype.endDrag.apply(this.dd, arguments);
this.proxy.hide();
}
this.refreshSize();
this.adjustAssets();
this.focus();
this.fireEvent("move", this, this.xy[0], this.xy[1]);
},
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -