3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
17 * A simple utility class for generically masking elements while loading data. If the {@link #store}
18 * config option is specified, the masking will be automatically synchronized with the store's loading
19 * process and the mask element will be cached for reuse.
20 * <p>Example usage:</p>
23 var myMask = new Ext.LoadMask(Ext.getBody(), {msg:"Please wait..."});
29 Ext.define('Ext.LoadMask', {
31 /* Begin Definitions */
34 observable: 'Ext.util.Observable'
37 requires: ['Ext.data.StoreManager'],
42 * @cfg {Ext.data.Store} store
43 * Optional Store to which the mask is bound. The mask is displayed when a load request is issued, and
44 * hidden on either load success, or load fail.
49 * The text to display in a centered loading message box (defaults to 'Loading...')
53 * @cfg {String} msgCls
54 * The CSS class to apply to the loading message element (defaults to "x-mask-loading")
56 msgCls : Ext.baseCSSPrefix + 'mask-loading',
59 * @cfg {Boolean} useMsg
60 * Whether or not to use a loading message class or simply mask the bound element.
65 * Read-only. True if the mask is currently disabled so that it will not be displayed (defaults to false)
71 * Creates new LoadMask.
72 * @param {Mixed} el The element, element ID, or DOM node you wish to mask.
73 * Also, may be a Component who's element you wish to mask.
74 * @param {Object} config (optional) The config object
76 constructor : function(el, config) {
84 Ext.apply(me, config);
86 me.addEvents('beforeshow', 'show', 'hide');
88 me.bindStore(me.store, true);
90 me.mixins.observable.constructor.call(me, config);
93 bindComponent: function(comp) {
96 resize: me.onComponentResize,
101 me.onComponentRender(comp);
104 fn: me.onComponentRender,
109 me.mon(comp, listeners);
114 * Called if we were configured with a Component, and that Component was not yet rendered. Collects the element to mask.
116 onComponentRender: function(comp) {
117 this.el = comp.getContentTarget();
122 * Called when this LoadMask's Component is resized. The isMasked method also re-centers any displayed message.
124 onComponentResize: function(comp, w, h) {
129 * Changes the data store bound to this LoadMask.
130 * @param {Store} store The store to bind to this LoadMask
132 bindStore : function(store, initial) {
135 if (!initial && me.store) {
138 beforeload: me.onBeforeLoad,
147 store = Ext.data.StoreManager.lookup(store);
150 beforeload: me.onBeforeLoad,
157 if (store && store.isLoading()) {
163 * Disables the mask to prevent it from being displayed
165 disable : function() {
175 * Enables the mask so that it can be displayed
177 enable : function() {
178 this.disabled = false;
182 * Method to determine whether this LoadMask is currently disabled.
183 * @return {Boolean} the disabled state of this LoadMask.
185 isDisabled : function() {
186 return this.disabled;
190 onLoad : function() {
195 me.fireEvent('hide', me, me.el, me.store);
199 onBeforeLoad : function() {
202 if (!me.disabled && !me.loading && me.fireEvent('beforeshow', me, me.el, me.store) !== false) {
204 me.el.mask(me.msg, me.msgCls, false);
209 me.fireEvent('show', me, me.el, me.store);
215 * Show this LoadMask over the configured Element.
222 * Hide this LoadMask.
229 destroy : function() {
231 this.clearListeners();