PDA

View Full Version : Ext.get("link").on('click', function() { ##need help



koko2589
4 Nov 2011, 2:17 PM
when i click more 1 time its open win more and more
iwant it to open just 1 time
tankou

Ext.onReady(function() {
Ext.get("link").on('click', function() {
var win = new Ext.Window({
width:200,y:'20', x:'70', border:false,
height: 450,closeAction: 'hide'

}); win.show();
});



});

skirtle
4 Nov 2011, 5:06 PM
When you say open one time...

Do you mean that you want the window to open only when the user clicks the element the first time?

Or do you mean that you only want the window to show if it isn't already showing?

koko2589
5 Nov 2011, 12:58 AM
if i click on the link 5 time ,to close it i need 5 time to click on close its open 5 window
i want just 1 window to show
tankyou

ycuk
5 Nov 2011, 1:11 AM
Ext.onReady(function() { Ext.get("link").on('click', function() { var win = new Ext.Window({ width:200,y:'20', x:'720', border:false, height: 450,closeAction: 'hide',

listeners: {
hide: function() {
Ext.get("link").un('click');
}
}

}); win.show(); });

Approximately so

koko2589
5 Nov 2011, 1:29 AM
Ext.onReady(function() { Ext.get("link").on('click', function() { var win = new Ext.Window({ width:200,y:'20', x:'720', border:false, height: 450,closeAction: 'hide',

listeners: {
hide: function() {
Ext.get("link").un('click');
}
}

}); win.show(); });

Approximately so

no good
i want if i clik on link 10 time to show 1 time not 10 time

koko2589
5 Nov 2011, 1:38 AM
i want like this
i i click 10 times its open 1 win not 10 window
tankyou


Ext.onReady(function(){

var win;
var button = Ext.get('show-btn');
button.on('click', function(){
// create the window on the first click and reuse on subsequent clicks
if(!win){

win = new Ext.Window({

layout : 'fit',
width : 500,
height : 300,
closeAction :'hide',
plain : true

});}

win.show( button);
});

});

mitchellsimoens
5 Nov 2011, 6:29 AM
First, let's clean your original code up so we can all easily read it:


Ext.onReady(function() {
Ext.get('link').on('click', function() {
var win = new Ext.Window({
width : 200,
y : 20,
x : 70,
border : false,
height : 450,
closeAction : 'hide'
});
win.show();
});
});

Now, if you want a listener to fire only once and remove itself, you can use the single listener config (changes in red):


Ext.onReady(function() {
Ext.get("link").on('click', function() {
var win = new Ext.Window({
width : 200,
y : 20,
x : 70,
border : false,
height : 450,
closeAction : 'hide'
});
win.show();
}, null, { single : true });
});

Problem is, when a Window is closed, that link is no longer going to fire the click event. The way to get around that is not to use the single config and since you are using closeAction as 'hide', just need to see if there is already a Window:


Ext.onReady(function() {
var win;
Ext.get('link').on('click', function() {
if (!win) {
//if there is no Window, create one!
win = new Ext.Window({
width : 200,
y : 20,
x : 70,
border : false,
height : 450,
closeAction : 'hide'
});
}

win.show();
});
});