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();
}
精彩评论