I can add an handle with:
Code: Select all
dojo.query( '.card' ).connect( 'onclick', this, 'onPlayCard' );
Code: Select all
dojo.query( '.card' ).connect( 'onclick', this, 'onPlayCard' );
Code: Select all
this.click_handler = dojo.query( '.card' ).connect( 'onclick', this, 'onPlayCard' );
...
dojo.disconnect( this.click_handler );
Code: Select all
var card = evt.target.closest( '.card' );
if ( card != null ) {
this.onPlayCard( evt );
}
This is, IMO, one of the best method (and even to the whole game board, so you can later move / duplicate the buttons / elements as you wish)
Code: Select all
cards.forEach( card => {
dojo.connect("card_" + card.id, "onclick", () => this.onPlayCard(card) );
});
Code: Select all
cards.forEach( card => {
this.connect(card, "onclick", () => this.onPlayCard(card) );
});
...
cards.forEach( card => {
this.disconnect(card, "onclick");
});
Code: Select all
dojo.forEach(this.clickHandlesCombat, function(handle) {
dojo.disconnect(handle, "onclick");
})
Well you definitively needs to post more code as this behaviour is clearly not caused by these lines of code.Hornir91 wrote: ↑01 March 2021, 00:11 I got into similar problem. I have several cards connected to 'onclick' event. After clicking one of them, I want the rest to be disconnected. So i store all handlers in global array and after the click I disconnect them with this code:
And there is a problem, because all cards are disappearing (all card divs and only holders are left). Does somebody know what causes the problem?Code: Select all
dojo.forEach(this.clickHandlesCombat, function(handle) { dojo.disconnect(handle, "onclick"); })
Thanks in advance.
Cheers.
Code: Select all
addActiveSlotQuery: function(query, handler) {
if (typeof handler == 'string')
handler = this[handler];
var superhandler = (event) => {
if (handler(event)) {
dojo.query(query).forEach((node) => {
this.disconnect(node, 'click');
});
}
};
dojo.query(query).forEach((node) => {
this.connect(node, 'click', superhandler);
});
},
I think dojo.forEach is a polyfill for back when [].forEach was not supported by most browsers.Victoria_La wrote: ↑01 March 2021, 14:44 dojo.disconnect jave only one parameter -handle,
Why you are using dojo.forEach, its the this.clickHandlesCombat query results? Or what is that?
This is my code in sharecode project that does similar thingAnd you call it with queryCode: Select all
addActiveSlotQuery: function(query, handler) { if (typeof handler == 'string') handler = this[handler]; var superhandler = (event) => { if (handler(event)) { dojo.query(query).forEach((node) => { this.disconnect(node, 'click'); }); } }; dojo.query(query).forEach((node) => { this.connect(node, 'click', superhandler); }); },
this.addActiveSlotQuery(".something > .foo", (even)=>{...; return true;});
I skipped some code that also add classes to these (one class to make active highlight and class to mark it as temp node to clean up
in case user did not click on anything)
Code: Select all
constructor: function(){
// Here, you can init the global variables of your user interface
// Example:
// this.myGlobalValue = 0;
this.clickHandlesCombat = [];
},
Code: Select all
for (i = 1; i <= 4; i ++) {
this.clickHandlesCombat.push(dojo.query("#combat_card_" + i).connect("onclick", dojo.hitch(this, "onClickCombatCard")));
dojo.addClass("combat_card_" + i, "can_play");
}
Code: Select all
showSpiedCard: function(card_nbr) {
this.setClientState('client_PlayerSpyCard', {
"descriptionmyturn": "",
});
var card = dojo.query('#combat_card_' + card_nbr);
dojo.addClass(card[0], "combat_card_flip_1");
dojo.forEach(this.clickHandlesCombat, function(handle) {
dojo.disconnect(handle, "onclick");
})
},