【问题标题】:Disabled Firefox Add-on ActionButton not grayed out已禁用的 Firefox 附加操作按钮未灰显
【发布时间】:2015-05-10 22:19:20
【问题描述】:

创建 Firefox 插件时ActionButtondisabled,例如,

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
});

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

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

【问题讨论】:

  • 不错的收获。这应该报告为一个错误,因为它显示禁用图标的不透明度为 50%。
  • 谢谢@Nico :) 在他们修复之前,您可以使用我在下面发布的样式注册

标签: javascript firefox-addon firefox-addon-sdk jpm


【解决方案1】:

试试这个,我的按钮的 id 是 toggle-button--helloname-my-button1 其中helloname 是我的插件的名称,my-button1 是我设置的 id。所以 dom id 是 toggle-button--helloname-my-button1 你应该把它更新为 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);

【讨论】:

    猜你喜欢
    • 2020-08-17
    • 1970-01-01
    • 2021-07-09
    • 1970-01-01
    • 2018-02-18
    • 1970-01-01
    • 1970-01-01
    • 2012-07-25
    • 1970-01-01
    相关资源
    最近更新 更多