3 * A simple utility class for generically masking elements while loading data. If the {@link #store}
4 * config option is specified, the masking will be automatically synchronized with the store's loading
5 * process and the mask element will be cached for reuse.
6 * <p>Example usage:</p>
9 var myMask = new Ext.LoadMask(Ext.getBody(), {msg:"Please wait..."});
14 * Create a new LoadMask
15 * @param {Mixed} el The element, element ID, or DOM node you wish to mask. Also, may be a Component who's element you wish to mask.
16 * @param {Object} config The config object
19 Ext.define('Ext.LoadMask', {
21 /* Begin Definitions */
24 observable: 'Ext.util.Observable'
27 requires: ['Ext.data.StoreManager'],
32 * @cfg {Ext.data.Store} store
33 * Optional Store to which the mask is bound. The mask is displayed when a load request is issued, and
34 * hidden on either load success, or load fail.
39 * The text to display in a centered loading message box (defaults to 'Loading...')
43 * @cfg {String} msgCls
44 * The CSS class to apply to the loading message element (defaults to "x-mask-loading")
46 msgCls : Ext.baseCSSPrefix + 'mask-loading',
49 * @cfg {Boolean} useMsg
50 * Whether or not to use a loading message class or simply mask the bound element.
55 * Read-only. True if the mask is currently disabled so that it will not be displayed (defaults to false)
60 constructor : function(el, config) {
68 Ext.apply(me, config);
70 me.addEvents('beforeshow', 'show', 'hide');
72 me.bindStore(me.store, true);
74 me.mixins.observable.constructor.call(me, config);
77 bindComponent: function(comp) {
80 resize: me.onComponentResize,
85 me.onComponentRender(comp);
88 fn: me.onComponentRender,
93 me.mon(comp, listeners);
98 * Called if we were configured with a Component, and that Component was not yet rendered. Collects the element to mask.
100 onComponentRender: function(comp) {
101 this.el = comp.getContentTarget();
106 * Called when this LoadMask's Component is resized. The isMasked method also re-centers any displayed message.
108 onComponentResize: function(comp, w, h) {
113 * Changes the data store bound to this LoadMask.
114 * @param {Store} store The store to bind to this LoadMask
116 bindStore : function(store, initial) {
119 if (!initial && me.store) {
122 beforeload: me.onBeforeLoad,
131 store = Ext.data.StoreManager.lookup(store);
134 beforeload: me.onBeforeLoad,
141 if (store && store.isLoading()) {
147 * Disables the mask to prevent it from being displayed
149 disable : function() {
159 * Enables the mask so that it can be displayed
161 enable : function() {
162 this.disabled = false;
166 * Method to determine whether this LoadMask is currently disabled.
167 * @return {Boolean} the disabled state of this LoadMask.
169 isDisabled : function() {
170 return this.disabled;
174 onLoad : function() {
179 me.fireEvent('hide', me, me.el, me.store);
183 onBeforeLoad : function() {
186 if (!me.disabled && !me.loading && me.fireEvent('beforeshow', me, me.el, me.store) !== false) {
188 me.el.mask(me.msg, me.msgCls, false);
193 me.fireEvent('show', me, me.el, me.store);
199 * Show this LoadMask over the configured Element.
206 * Hide this LoadMask.
213 destroy : function() {
215 this.clearListeners();