PDA

View Full Version : ux.plugins.ContainerMask



hendricd
9 Mar 2008, 6:16 AM
The following Container plugin, provides a flexible masking agent for any Ext.Container (Viewport, Panel, TreePanel, Toolbar, etc) .


Ext.namespace('Ext.ux.plugins');
Ext.ux.plugins.ContainerMask = function(opt) {
var options = opt||{};

return {
init: function(c) {
Ext.applyIf(c,{
showMask : function(msg, msgClass, maskClass){
var el;
if(this.rendered && (el = this[options.el] || Ext.get(options.el) || this.getEl?this.getEl():null)){
el.mask.call(el,msg || options.msg, msgClass || options.msgClass, maskClass || options.maskClass);
}
},
hideMask : function(){
var el;
if(this.rendered && (el = this[options.el] || Ext.get(options.el) || this.getEl?this.getEl():null)){
el.unmask.call(el);
}
}
});
if(options.masked){
c.on('render', c.showMask.createDelegate(c,[null]) ,c, {delay:10, single:true}) ;
}
}
};
};Optional Plugin config options:
msg: the default mask message to be displayed when shown.
msgClass: CSS className applied to the message
maskClass: CSS className applied to the mask
masked: if true, the mask is shown during initial Container rendering
el: element to use as the masking element. Can be a property name (ie: 'bwrap'), or even a specific element elsewhere on the page. Defaults to main container element.Usage:

Ext.onReady(function(){
var tabs = new Ext.TabPanel({ //any container tho
title: 'Test',
plugins: [new Ext.ux.plugins.ContainerMask ({msg:'Don\'t Touch!', masked:true })],
renderTo: document.body
});
tabs.hideMask(); //you must control on/off
tabs.showMask('Hold on...');
});

garraS
9 Mar 2008, 7:51 PM
Nice plugin!

Thanks a lot!

garraS

Choleriker
12 Mar 2008, 2:42 AM
Hello,

i am using a similar implementation. With my implementation you can show/hide a mask for any Ext.Element:

[code]
// Let's add a couple new convenience methods to Ext.LoadMask
Ext.apply(Ext.LoadMask.prototype,{
visible:false,
onBeforeLoad : function(){
if(!this.disabled && !this.visible){
this.el.mask(this.msg, this.msgCls);
this.visible = true;
}
},
onLoad : function(){
this.el.unmask(this.removeMask);
this.visible = false;
},

show:function(msg, append){
if(!this.disabled){
if(msg){
this.msg= append?this.msg + '<br/>'+ msg:msg;
}
this.onBeforeLoad();
}
},
showDefer:function(msg,fn,config){
config || (config={});
this.show(msg, config.append||false);
if(fn){
config = Ext.apply({scope:this,millis:100,"arguments":[],appendArguments:false},config);
fn.defer(config.millis,config.scope,[].concat(config.arguments),config.appendArguments);
}
},
hide:function(){ this.onLoad(); }
});



/**
F

jsakalos
15 Mar 2008, 7:01 AM
What your extension adds to, let's say, Ext.getBody().mask('Mask message')?

hendricd
15 Mar 2008, 7:59 AM
What your extension adds to, let's say, Ext.getBody().mask('Mask message')Not sure who that was directed at but, the override Choleriker previously posted came from this (http://extjs.com/forum/showthread.php?t=11304)thread I created back in the 1.1+ days.

This ux provides a simpler approach for the novice who wants to add loadMask support to other 2.0+ Containers besides gridPanel, etc...

One benefit: It's real easy to wire masking up to (optionally, a specific element within) the Container:


items: [{
xtype:'panel',
//mask the toolBars too: ('bwrap')
plugins: [new Ext.ux.plugins.ContainerMask ({msg:'Don\'t Touch!', masked:true, el:'bwrap' })],
.....
}],

Done, loadMask added (doubt you need it though ;) ).

jsakalos
15 Mar 2008, 8:31 AM
Yeah, I see. Inline config could come handy sometimes...

I've been using panel.body.mask(....) or panel.getEl().mask(...) so far...

jay@moduscreate.com
15 Mar 2008, 7:12 PM
Yeah, I see. Inline config could come handy sometimes...

I've been using panel.body.mask(....) or panel.getEl().mask(...) so far...

to me the element method is where the magic is.

Shaguar
19 Apr 2008, 8:21 AM
How can i change the position of the loading message? i tried it with a custom msgClass but it didnt work.

wm003
19 Apr 2008, 12:07 PM
Very useful! Thanks for sharing:)

hendricd
9 May 2008, 6:31 AM
To handle lighter-weight Components (like Ext.DataView). (See Post #1)

moegal
7 Mar 2009, 7:05 AM
Doug,

Nice plugin. This is very handy. How would I change the message on a mask that is already applied? Would I just give it an id and then reference by id.msd = 'newtexthere' or similar.

Initialising...

Please Wait...

Loading...

Etc.

Thanks, Marty

mjlecomte
7 Mar 2009, 7:31 AM
Did you try just calling showMask () again? Arguably you should just work with Element.mask() anyway.

moegal
7 Mar 2009, 7:50 AM
calling showMask() again seems to work as long as the mask was set from the function and not in the config. Thanks.

I am not sure how to use Element.mask(). I will do some research on it now, thanks.

Marty

mjlecomte
7 Mar 2009, 7:54 AM
If you look at the code in the first post it's there. Doug's plugin code just makes a convenience wrapper for it.

Next place to look would be to go to the source file for Element and look at what it is doing.

moegal
7 Mar 2009, 7:56 AM
that is just what I was doing, thanks!

moegal
8 Jul 2009, 6:15 AM
How can I show the spinning gif with this? I tried to set iconCls but to no avail. Do I need to create a custom class?

Marty

hendricd
8 Jul 2009, 8:16 AM
How can I show the spinning gif with this? I tried to set iconCls but to no avail. Do I need to create a custom class?

Marty

Your best bet, is simply specify your custom mask and mask-msg classes:




plugins: [
new Ext.ux.plugins.ContainerMask ({
msg:'Don\'t Touch!',
masked:true ,
maskClass : 'custom-mask',
msgClass : 'custom-msg'
}
)],


Study the ext-el-mask and ext-el-mask-msg CSS rules for a general guide.

moegal
8 Jul 2009, 9:16 AM
Doug,
Thanks

Marty