How to add a proper-looking text input field to Firefox toolbar?

后端 未结 2 410
小蘑菇
小蘑菇 2021-01-15 06:11

I want to have a text input field in toolbar that looks like search input and is controlled by a FF extension.

I am using sdk/widget:

in main js file I have<

相关标签:
2条回答
  • 2021-01-15 06:50

    The widget api has been deprecated and you should not use it. If you look at the browser console, you'll see messages from the SDK warning about this deprecation.

    Instead, you should be using the newer UI elements introduced with Firefox 29 like the toolbar api:

    https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/ui#Toolbar

    0 讨论(0)
  • 2021-01-15 06:51

    I would insert a textfield with CustomizableUI.jsm type custom and build the thing.

    This is how to make custom type customizazbleui.jsm stuff: https://gist.github.com/Noitidart/10902477

    I tried to find how the searchbar was created, i would have though it was also done via customizableui.jsm but i couldnt find it on mxr.

    edit:

    this is how:

    const {Cu} = require("chrome");
    Cu.import('resource:///modules/CustomizableUI.jsm');
    CustomizableUI.createWidget({
        id: 'myCUITextbox',
        type: 'custom',
        removable: true,
        defaultArea: CustomizableUI.AREA_NAVBAR,
        onBuild: function(aDocument) {
            var node = aDocument.createElement('toolbaritem');
            node.setAttribute('id', this.id);
    
            var props = {
              title: 'Search',
              align: 'center',
              class: 'chromeclass-toolbar-additional panel-wide-item',
              flex: 100
            };
            for (var p in props) {
              node.setAttribute(p, props[p])
            }
    
            var textbox = aDocument.createElement('textbox');
            node.appendChild(textbox);
    
            //node.style.listStyleImage = "url(" + (aProvider.icon32URL || aProvider.iconURL) + ")";
            return node;
        }
    });
    

    And when you want to remove do:

    CustomizableUI.destroyWidget('myCUITextbox');
    
    0 讨论(0)
提交回复
热议问题