"validate" ,
var popupBackground = {
initialised : false,
activeTab : null,
numberOfTabs : null,
_init : function() {
var that = this;
localStorage.clear();
localStorage["popupOpened"] = false;
safari.application.addEventListener("command", function(event){
that.handleCommand(event);
}, false);
safari.application.addEventListener("validate",function(event){
that.validateCommand(event);
}, false);
safari.application.addEventListener("message", function(event){
that.handleMessage(event);
}, false);
},
_getActiveTab : function(){
return safari.application.activeBrowserWindow.activeTab;
},
validateCommand : function(aEvent) {
var that = this;
if (aEvent.command === "togglePopup") {
if (!aEvent.target.browserWindow.activeTab.url) {
aEvent.target.disabled = true;
} else {
aEvent.target.disabled = false;
}
}
if(this.activeTab !== null){
if(this.activeTab !== this._getActiveTab()){
$.each(safari.application.browserWindows, function(aIndex, aWindow) {
$.each(aWindow.tabs, function(aIndex, aTab) {
if(typeof aTab.page !== "undefined"){
if (aTab !== that._getActiveTab()) {
aTab.page.dispatchMessage("tabUnfocused");
localStorage["popupOpened"] = false;
}else{
aTab.page.dispatchMessage("tabFocused");
}
}
});
});
}
}
this.activeTab = this._getActiveTab();
}
}