开发者

Safari Extension, toggle toolbar

Does anyone k开发者_如何学Cnow how to toggle toolbar visibility when clicking on a Toolbar Item.

I'm building a Safari Extension and I have created a button on the main toolbar. When I click this button I can open my custom toolbar with the following:

function performCommand(event)
{
    if (event.command === "theBar") {

        const bars = safari.extension.bars;
        const activeBrowserWindow = safari.application.activeBrowserWindow;
        for (var i = 0; i < bars.length; ++i) {
            var bar = bars[i];
            if (bar.browserWindow === activeBrowserWindow && bar.identifier === "openBar")
               {
               bar.show();
            }   
        }       
    }
}

I would like to be able to click the button a second time to hide the custom toolbar.


Add this in place of bar.show();

        if(bar.visible) {
            bar.hide();
        } else {
            bar.show();
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜