contentpanels.js
来自「php绿色服务器,让大家试用greenamp」· JavaScript 代码 · 共 474 行 · 第 1/2 页
JS
474 行
/*
* Ext JS Library 1.0.1
* Copyright(c) 2006-2007, Ext JS, LLC.
* licensing@extjs.com
*
* http://www.extjs.com/license
*/
/**
* @class Ext.ContentPanel
* @extends Ext.util.Observable
* A basic ContentPanel element.
* @cfg {Boolean} fitToFrame True for this panel to adjust its size to fit when the region resizes (defaults to false)
* @cfg {Boolean} fitContainer When using fitToFrame and resizeEl, you can also fit the parent container (defaults to false)
* @cfg {Boolean/Object} autoCreate True to auto generate the DOM element for this panel, or a DomHelper config of the element to create
* @cfg {Boolean} closable True if the panel can be closed/removed
* @cfg {Boolean} background True if the panel should not be activated when it is added (defaults to false)
* @cfg {String/HTMLElement/Element} resizeEl An element to resize if fitToFrame is true (instead of this panel's element)
* @cfg {Toolbar} toolbar A toolbar for this panel
* @cfg {Boolean} autoScroll True to scroll overflow in this panel (use with fitToFrame)
* @cfg {String} title The title for this panel
* @cfg {Array} adjustments Values to <b>add</b> to the width/height when doing a fitToFrame (default is [0, 0])
* @cfg {String} url Calls setUrl() with this value
* @cfg {String/Object} params When used with "url", calls setUrl() with this value
* @cfg {Boolean} loadOnce Calls When used with "url", calls setUrl() with this value
* @constructor
* Create a new ContentPanel.
* @param {String/HTMLElement/Element} el The container element for this panel
* @param {String/Object} config A string to set only the title or a config object
* @param {String} content (optional) Set the HTML content for this panel
*/
Ext.ContentPanel = function(el, config, content){
Ext.ContentPanel.superclass.constructor.call(this);
if(el.autoCreate){
config = el;
el = Ext.id();
}
this.el = Ext.get(el);
if(!this.el && config && config.autoCreate){
if(typeof config.autoCreate == "object"){
if(!config.autoCreate.id){
config.autoCreate.id = config.id||el;
}
this.el = Ext.DomHelper.append(document.body,
config.autoCreate, true);
}else{
this.el = Ext.DomHelper.append(document.body,
{tag: "div", cls: "x-layout-inactive-content", id: config.id||el}, true);
}
}
this.closable = false;
this.loaded = false;
this.active = false;
if(typeof config == "string"){
this.title = config;
}else{
Ext.apply(this, config);
}
if(this.resizeEl){
this.resizeEl = Ext.get(this.resizeEl, true);
}else{
this.resizeEl = this.el;
}
this.addEvents({
/**
* @event activate
* Fires when this panel is activated.
* @param {Ext.ContentPanel} this
*/
"activate" : true,
/**
* @event deactivate
* Fires when this panel is activated.
* @param {Ext.ContentPanel} this
*/
"deactivate" : true,
/**
* @event resize
* Fires when this panel is resized if fitToFrame is true.
* @param {Ext.ContentPanel} this
* @param {Number} width The width after any component adjustments
* @param {Number} height The height after any component adjustments
*/
"resize" : true
});
if(this.autoScroll){
this.resizeEl.setStyle("overflow", "auto");
}
content = content || this.content;
if(content){
this.setContent(content);
}
if(config && config.url){
this.setUrl(this.url, this.params, this.loadOnce);
}
};
Ext.extend(Ext.ContentPanel, Ext.util.Observable, {
tabTip:'',
setRegion : function(region){
this.region = region;
if(region){
this.el.replaceClass("x-layout-inactive-content", "x-layout-active-content");
}else{
this.el.replaceClass("x-layout-active-content", "x-layout-inactive-content");
}
},
/**
* Returns the toolbar for this Panel if one was configured.
* @return {Ext.Toolbar}
*/
getToolbar : function(){
return this.toolbar;
},
setActiveState : function(active){
this.active = active;
if(!active){
this.fireEvent("deactivate", this);
}else{
this.fireEvent("activate", this);
}
},
/**
* Updates this panel's element
* @param {String} content The new content
* @param {Boolean} loadScripts (optional) true to look for and process scripts
*/
setContent : function(content, loadScripts){
this.el.update(content, loadScripts);
},
ignoreResize : function(w, h){
if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
return true;
}else{
this.lastSize = {width: w, height: h};
return false;
}
},
/**
* Get the {@link Ext.UpdateManager} for this panel. Enables you to perform Ajax updates.
* @return {Ext.UpdateManager} The UpdateManager
*/
getUpdateManager : function(){
return this.el.getUpdateManager();
},
/**
* Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use setUrl.
* @param {Object/String/Function} url The url for this request or a function to call to get the url or a config object containing any of the following options:
<pre><code>
panel.load({<br/>
url: "your-url.php",<br/>
params: {param1: "foo", param2: "bar"}, // or a URL encoded string<br/>
callback: yourFunction,<br/>
scope: yourObject, //(optional scope) <br/>
discardUrl: false, <br/>
nocache: false,<br/>
text: "Loading...",<br/>
timeout: 30,<br/>
scripts: false<br/>
});
</code></pre>
* The only required property is url. The optional properties nocache, text and scripts
* are shorthand for disableCaching, indicatorText and loadScripts and are used to set their associated property on this panel UpdateManager instance.
* @param {String/Object} params (optional) The parameters to pass as either a url encoded string "param1=1&param2=2" or an object {param1: 1, param2: 2}
* @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess, oResponse)
* @param {Boolean} discardUrl (optional) By default when you execute an update the defaultUrl is changed to the last used url. If true, it will not store the url.
* @return {Ext.ContentPanel} this
*/
load : function(){
var um = this.el.getUpdateManager();
um.update.apply(um, arguments);
return this;
},
/**
* Set a URL to be used to load the content for this panel. When this panel is activated, the content will be loaded from that URL.
* @param {String/Function} url The url to load the content from or a function to call to get the url
* @param {String/Object} params (optional) The string params for the update call or an object of the params. See {@link Ext.UpdateManager#update} for more details. (Defaults to null)
* @param {Boolean} loadOnce (optional) Whether to only load the content once. If this is false it makes the Ajax call every time this panel is activated. (Defaults to false)
* @return {Ext.UpdateManager} The UpdateManager
*/
setUrl : function(url, params, loadOnce){
if(this.refreshDelegate){
this.removeListener("activate", this.refreshDelegate);
}
this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
this.on("activate", this._handleRefresh.createDelegate(this, [url, params, loadOnce]));
return this.el.getUpdateManager();
},
_handleRefresh : function(url, params, loadOnce){
if(!loadOnce || !this.loaded){
var updater = this.el.getUpdateManager();
updater.update(url, params, this._setLoaded.createDelegate(this));
}
},
_setLoaded : function(){
this.loaded = true;
},
/**
* Returns this panel's id
* @return {String}
*/
getId : function(){
return this.el.id;
},
/**
* Returns this panel's element
* @return {Ext.Element}
*/
getEl : function(){
return this.el;
},
adjustForComponents : function(width, height){
if(this.resizeEl != this.el){
width -= this.el.getFrameWidth('lr');
height -= this.el.getFrameWidth('tb');
}
if(this.toolbar){
var te = this.toolbar.getEl();
height -= te.getHeight();
te.setWidth(width);
}
if(this.adjustments){
width += this.adjustments[0];
height += this.adjustments[1];
}
return {"width": width, "height": height};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?