How can I tell if someone has entered or exited customise mode

Add-ons for Pale Moon and other applications
General discussion, compatibility, contributed extensions, themes, plugins, and more.

Moderators: FranklinDM, Lootyhoof

thosrtanner
Lunatic
Lunatic
Posts: 395
Joined: 2014-05-10, 18:19
Location: UK

How can I tell if someone has entered or exited customise mode

Unread post by thosrtanner » 2023-08-02, 20:48

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.

User avatar
Kris_88
Keeps coming back
Keeps coming back
Posts: 940
Joined: 2021-01-26, 11:18

Re: How can I tell if someone has entered or exited customise mode

Unread post by Kris_88 » 2023-08-02, 21:13

I once faced this problem.
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);
    };


User avatar
Kris_88
Keeps coming back
Keeps coming back
Posts: 940
Joined: 2021-01-26, 11:18

Re: How can I tell if someone has entered or exited customise mode

Unread post by Kris_88 » 2023-08-02, 21:32

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.

thosrtanner
Lunatic
Lunatic
Posts: 395
Joined: 2014-05-10, 18:19
Location: UK

Re: How can I tell if someone has entered or exited customise mode

Unread post by thosrtanner » 2023-08-03, 06:06

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...