dmid
dmid

Reputation: 493

Safari Extension, toggle toolbar

Does anyone know 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.

Upvotes: 0

Views: 1354

Answers (1)

Paul Kehrer
Paul Kehrer

Reputation: 14089

Add this in place of bar.show();

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

Upvotes: 1

Related Questions