Auto width widget

孤者浪人 提交于 2019-12-25 16:54:30

问题


I'm writing a small add-on to Firefofx, in which I use widgets. I wonder how to set auto-width which adapts to content. For example I want my widget to display numbers, which will have a different length. I can set my widget width but how do I know how much my number takes pixels. Is there a way to get the width, choosing automatically? Here is some of my code: My widget (my add-on uses other widgets),

//ROBOTS META
var robots_meta = widgets.Widget({
 id: "robots_meta",
 label: "Displays information about robots meta",
 content: "Meta-robots n/a",
 width: 100
});

Here is function that update content of my widget:

function meta_robots_checker(tab) {
  var meta_robots_w = robots_meta.getView(tab.window);
  meta_robots_w.content = 'Meta-robots n/a';
  worker = tab.attach({
    contentScriptFile: data.url("js/meta-checker.js")
   });
worker.port.emit("check_noindex");
worker.port.on('content', function(message) {    
        message = message.toLowerCase();
        message = message.replace('nofollow', '<span style="color:red">nofollow</span>');
        message = message.replace('noindex', '<span style="color:red">noindex</span>');
        meta_robots_w.content = message;
       //HERE MY WIDGET WIDTH SHOULD BE CHANGED
    });
}

回答1:


you have to dynamically control the width, the widget is a panel. not a dynamically change width element like a label.

to get the widget panel element use "Element Selector" addon with "Dom Inspector".

See this topic here: Avoid panel to autoHide in Firefox extension



来源:https://stackoverflow.com/questions/21825454/auto-width-widget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!