Activate / deactivate an ActionButton on a certain page

1

I'm developing an extension for Firefox browsers, so the need arose to control the action button so that it is inactive until the user enters a certain page.

For example, I'll use the link page as an example. Well, I would like the button to be active only when it is with the active tab and with that page open.

Here is my code:

var data = require("sdk/self").data;

// o painel que será exibido
var panel = require("sdk/panel").Panel({
    contentURL: data.url("painel.html")
});


// as configurações do botão de ação
var actionBtn = require("sdk/ui/button/action").ActionButton({
    id: "ID do botão",
    label: "Descrição do botão",
    icon: {
        "16": "./logo-16.png",
        "36": "./logo-36.png"
    },
    onClick : openPanel
});

// função que exibe o painel quando o botão de ação é clicado.
function openPanel(){
    panel.show();
}

So far I have the normal code, only to open the panel when the user clicks on it. How can I make this control on / off?

    
asked by anonymous 13.09.2014 / 19:16

1 answer

1

Check the value of the URL, tabs.activeTab.url , and if that's what you want, you can disable the button by setting the disabled property to true;

var tabs = require("sdk/tabs");

function onOpen(tab) {
  console.log(tab.url + " is open");
  tab.on("pageshow", logShow);
  tab.on("activate", logActivate);    // Voce pode acessar a aba atual nesta funcao
  tab.on("deactivate", logDeactivate);
  tab.on("close", logClose);
}

function logShow(tab) {
  console.log(tab.url + " is loaded");
}

function logActivate(tab) {
  if(tab.url=="http://www.google.com"){
      actionBtn.disabled = true;
  } else {
      actionBtn.disabled = false;
  }
  console.log(tab.url + " is activated");
}

function logDeactivate(tab) {
  console.log(tab.url + " is deactivated");
}

function logClose(tab) {
  console.log(tab.url + " is closed");
}

tabs.on('open', onOpen);

References:

  • link
  • link
  • 16.09.2014 / 12:05