?? messagebox.js
字號:
/*
* Ext JS Library 1.1 RC 1
* Copyright(c) 2006-2007, Ext JS, LLC.
* licensing@extjs.com
*
* http://www.extjs.com/license
*/
/**
* @class Ext.MessageBox
* Utility class for generating different styles of message boxes. The alias Ext.Msg can also be used.
* Example usage:
*<pre><code>
// Basic alert:
Ext.Msg.alert('Status', 'Changes saved successfully.');
// Prompt for user data:
Ext.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
if (btn == 'ok'){
// process text value...
}
});
// Show a dialog using config options:
Ext.Msg.show({
title:'Save Changes?',
msg: 'Your are closing a tab that has unsaved changes. Would you like to save your changes?',
buttons: Ext.Msg.YESNOCANCEL,
fn: processResult,
animEl: 'elId'
});
</code></pre>
* @singleton
*/
Ext.MessageBox = function(){
var dlg, opt, mask, waitTimer;
var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp;
var buttons, activeTextEl, bwidth;
// private
var handleButton = function(button){
dlg.hide();
Ext.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value], 1);
};
// private
var handleHide = function(){
if(opt && opt.cls){
dlg.el.removeClass(opt.cls);
}
if(waitTimer){
Ext.TaskMgr.stop(waitTimer);
waitTimer = null;
}
};
// private
var updateButtons = function(b){
var width = 0;
if(!b){
buttons["ok"].hide();
buttons["cancel"].hide();
buttons["yes"].hide();
buttons["no"].hide();
dlg.footer.dom.style.display = 'none';
return width;
}
dlg.footer.dom.style.display = '';
for(var k in buttons){
if(typeof buttons[k] != "function"){
if(b[k]){
buttons[k].show();
buttons[k].setText(typeof b[k] == "string" ? b[k] : Ext.MessageBox.buttonText[k]);
width += buttons[k].el.getWidth()+15;
}else{
buttons[k].hide();
}
}
}
return width;
};
// private
var handleEsc = function(d, k, e){
if(opt && opt.closable !== false){
dlg.hide();
}
if(e){
e.stopEvent();
}
};
return {
/**
* Returns a reference to the underlying {@link Ext.BasicDialog} element
* @return {Ext.BasicDialog} The BasicDialog element
*/
getDialog : function(){
if(!dlg){
dlg = new Ext.BasicDialog("x-msg-box", {
autoCreate : true,
shadow: true,
draggable: true,
resizable:false,
constraintoviewport:false,
fixedcenter:true,
collapsible : false,
shim:true,
modal: true,
width:400, height:100,
buttonAlign:"center",
closeClick : function(){
if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
handleButton("no");
}else{
handleButton("cancel");
}
}
});
dlg.on("hide", handleHide);
mask = dlg.mask;
dlg.addKeyListener(27, handleEsc);
buttons = {};
var bt = this.buttonText;
buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok"));
buttons["yes"] = dlg.addButton(bt["yes"], handleButton.createCallback("yes"));
buttons["no"] = dlg.addButton(bt["no"], handleButton.createCallback("no"));
buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel"));
bodyEl = dlg.body.createChild({
html:'<span class="ext-mb-text"></span><br /><input type="text" class="ext-mb-input" /><textarea class="ext-mb-textarea"></textarea><div class="ext-mb-progress-wrap"><div class="ext-mb-progress"><div class="ext-mb-progress-bar"> </div></div></div>'
});
msgEl = bodyEl.dom.firstChild;
textboxEl = Ext.get(bodyEl.dom.childNodes[2]);
textboxEl.enableDisplayMode();
textboxEl.addKeyListener([10,13], function(){
if(dlg.isVisible() && opt && opt.buttons){
if(opt.buttons.ok){
handleButton("ok");
}else if(opt.buttons.yes){
handleButton("yes");
}
}
});
textareaEl = Ext.get(bodyEl.dom.childNodes[3]);
textareaEl.enableDisplayMode();
progressEl = Ext.get(bodyEl.dom.childNodes[4]);
progressEl.enableDisplayMode();
var pf = progressEl.dom.firstChild;
pp = Ext.get(pf.firstChild);
pp.setHeight(pf.offsetHeight);
}
return dlg;
},
/**
* Updates the message box body text
* @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
* the XHTML-compliant non-breaking space character '&#160;')
* @return {Ext.MessageBox} This message box
*/
updateText : function(text){
if(!dlg.isVisible() && !opt.width){
dlg.resizeTo(this.maxWidth, 100); // resize first so content is never clipped from previous shows
}
msgEl.innerHTML = text || ' ';
var w = Math.max(Math.min(opt.width || msgEl.offsetWidth, this.maxWidth),
Math.max(opt.minWidth || this.minWidth, bwidth));
if(opt.prompt){
activeTextEl.setWidth(w);
}
if(dlg.isVisible()){
dlg.fixedcenter = false;
}
dlg.setContentSize(w, bodyEl.getHeight());
if(dlg.isVisible()){
dlg.fixedcenter = true;
}
return this;
},
/**
* Updates a progress-style message box's text and progress bar. Only relevant on message boxes
* initiated via {@link Ext.MessageBox#progress} or by calling {@link Ext.MessageBox#show} with progress: true.
* @param {Number} value Any number between 0 and 1 (e.g., .5)
* @param {String} text (optional) If defined, the message box's body text is replaced with the specified string (defaults to undefined)
* @return {Ext.MessageBox} This message box
*/
updateProgress : function(value, text){
if(text){
this.updateText(text);
}
pp.setWidth(Math.floor(value*progressEl.dom.firstChild.offsetWidth));
return this;
},
/**
* Returns true if the message box is currently displayed
* @return {Boolean} True if the message box is visible, else false
*/
isVisible : function(){
return dlg && dlg.isVisible();
},
/**
* Hides the message box if it is displayed
*/
hide : function(){
if(this.isVisible()){
dlg.hide();
}
},
/**
* Displays a new message box, or reinitializes an existing message box, based on the config options
* passed in. All functions (e.g. prompt, alert, etc) on MessageBox call this function internally.
* The following config object properties are supported:
* <pre>
Property Type Description
---------- --------------- ----------------------------------------------------------------------
title String The title text
closable Boolean False to hide the top-right close box (defaults to true)
prompt Boolean True to prompt the user to enter single-line text (defaults to false)
multiline Boolean True to prompt the user to enter multi-line text (defaults to false)
progress Boolean True to display a progress bar (defaults to false)
value String The string value to set into the active textbox element if displayed
buttons Object/Boolean A button config object (e.g., Ext.MessageBox.OKCANCEL or {ok:'Foo',
cancel:'Bar'}), or false to not show any buttons (defaults to false)
msg String A string that will replace the existing message box body text (defaults
to the XHTML-compliant non-breaking space character  )
cls String A custom CSS class to apply to the message box element
proxyDrag Boolean True to display a lightweight proxy while dragging (defaults to false)
modal Boolean False to allow user interaction with the page while the message box is
displayed (defaults to true)
</pre>
*
* Example usage:
* <pre><code>
Ext.Msg.show({
title: 'Address',
msg: 'Please enter your address:',
width: 300,
buttons: Ext.MessageBox.OKCANCEL,
multiline: true,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -