3

创建 Firefox 附加组件时ActionButton disabled,例如,

var button = new ActionButton({
  id: 'my-link',
  label: 'My label',
  icon: {
    '16': './icon-16.png',
    '32': './icon-32.png',
    '64': './icon-64.png'
  },
  onClick: handleClick,
  disabled: true
});

该按钮确实不可点击并且不会产生任何事件,但该图标并未像文档中所宣传的那样显示为灰色。

关于为什么会这样的任何想法?

4

1 回答 1

1

试试这个,我的按钮的 id 是toggle-button--helloname-my-button1helloname的插件的名称,my-button1是我设置的 id。因此,toggle-button--helloname-my-button1您应该将 dom id 更新为toggle-button--YOUR_ADDON_NAME-my-link

// globals
Cu.import('resource://gre/modules/Services.jsm');
var sss = Cc['@mozilla.org/content/style-sheet-service;1'].getService(Ci.nsIStyleSheetService);

var cssUri;
var svgFilterUrl;
// end globals

if (Services.vc.compare(Services.appinfo.version, 34) < 0) {
    // for less then firefox v34
    if (!svgFilterUrl) {
        Cu.importGlobalProperties(['URL']);
        var oFileBody = '<svg xmlns="http://www.w3.org/2000/svg"><filter id="grayscale"><feColorMatrix type="saturate" values="0"/></filter></svg>';
        var {Blob} = Cu.import("resource://gre/modules/Services.jsm", {});
        var oBlob = Blob([oFileBody], {
            type: "text/xml"
        });
        svgFilterUrl = URL.createObjectURL(oBlob);
        console.log(url)
    }
    var css = '#toggle-button--helloname-my-button1[disabled] { filter: url(' + url + '#grayscale); }';
} else {
    // for less then firefox >= v34
    var css = '#toggle-button--helloname-my-button1[disabled] { filter:grayscale(1) }';
}
var newURIParam = {
    aURL: 'data:text/css,' + encodeURIComponent(css),
    aOriginCharset: null,
    aBaseURI: null
};
var cssUri = Services.io.newURI(newURIParam.aURL, newURIParam.aOriginCharset, newURIParam.aBaseURI);
sss.loadAndRegisterSheet(cssUri, sss.AUTHOR_SHEET);

当你想卸载/禁用你的插件时sss.unregisterSheet(cssUri, sss.AUTHOR_SHEET);

于 2015-05-21T22:33:58.513 回答