开发者

Safari Extension, toggle toolbar

开发者 https://www.devze.com 2023-02-17 09:33 出处:网络
Does anyone k开发者_如何学Cnow how to toggle toolbar visibility when clicking on a Toolbar Item.

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

精彩评论

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

关注公众号