How can I tell if someone has entered or exited customise mode
Moderators: FranklinDM, Lootyhoof
-
- Lunatic
- Posts: 395
- Joined: 2014-05-10, 18:19
- Location: UK
How can I tell if someone has entered or exited customise mode
for reasons i don't understand, if someone enters and exits customise mode, and my extension is running in the status bar, it loses the ability to update its status bar icon. So is there any way I can tell when this has happened - among other reasons, it'd be extremely useful in finding out what has changed. I suspect the code is holding onto something it shouldn't that gets recreated, but it ain't obvious what right now.
-
- Keeps coming back
- Posts: 940
- Joined: 2021-01-26, 11:18
Re: How can I tell if someone has entered or exited customise mode
I once faced this problem.
Then I did this:
Then I did this:
Code: Select all
val label = null;
label = FindElm(label, 'MyElementID');
document.addEventListener("aftercustomization", function() {
label = FindElm(label, 'MyElementID');
if(label) UpdateValue(label);
});
if(label) UpdateValue(label);
...
function FindElm(elm, id) {
if(elm) try {
// remove events listeners here
elm.removeEventListener("click", onClick);
} catch(e) {};
elm = null;
elm = document.getElementById(id);
if(elm) {
// apply events listeners here
elm.addEventListener("click", onClick);
};
return(elm);
};
-
- Keeps coming back
- Posts: 940
- Joined: 2021-01-26, 11:18
Re: How can I tell if someone has entered or exited customise mode
In short, after customization, you need to find your element again and assign additional event handlers if they are needed. In my case, it was not a button, but a simple label with text, but I wanted to respond to a click on it. Keep in mind that your element may not be found if the user moved it to the palette during customization.
-
- Lunatic
- Posts: 395
- Joined: 2014-05-10, 18:19
- Location: UK
Re: How can I tell if someone has entered or exited customise mode
Thanks. I'll have a dig round there. Oddly, clicking on the button is working fine. It's just that updates to the contents don't work...