How to change Panel Size in mozilla like chrome extension

混江龙づ霸主 提交于 2019-12-24 16:30:08

问题


Panel Size is fixed in SDK-based Add-on

I want to change the size of panel automatically like chrome dictionary extension here

If you will search in panel it will show big and small data like content requirement. In Mozilla panel we can fix only 1 type of size like width:400px and height:400px etc. but i want that panel size should based on data size means like chrome extensions.


回答1:


You can implement this in the Add-on SDK with a little extra code.

In main.js:

var panel = require("panel").Panel({
  contentURL: "https://bugzilla.mozilla.org/enter_bug.cgi?product=Add-on%20SDK",
  onShow: function() {
        let worker = tabs.activeTab.attach({
            contentScriptFile: [
                data.url('windowsize.js')
            ]
        });

        worker.port.on('winsize', function(data) {
            panel.resize((data.width-120), (data.height-120));
        });
        worker.port.emit('fetchwinsize');
  }
});

In the content script:

self.port.on('fetchwinsize', function() {
    self.port.emit("winsize", {height: window.innerHeight, width: window.innerWidth});
});

Here's a working example of this:

https://builder.addons.mozilla.org/package/150225/latest/



来源:https://stackoverflow.com/questions/14123936/how-to-change-panel-size-in-mozilla-like-chrome-extension

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