Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:gorhill/uBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Feb 20, 2015
2 parents da63253 + 7e77a0c commit e9ee6ab
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Install from [Firefox Add-ons homepage](https://addons.mozilla.org/en-US/firefox

##### 8.0 or newer only

You can get and install the latest µBlock for Safari [right here](https://chrismatic.io/ublock).
You can get and install the latest µBlock for Safari **[right here](https://chrismatic.io/ublock/)**.

µBlock is also available on the [Safari Extension Gallery](https://extensions.apple.com/details/?id=net.gorhill.uBlock-96G4BAKDQ9), although that's not guaranteed to be the latest version.

Expand Down
69 changes: 33 additions & 36 deletions platform/safari/vapi-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

(function() {

'use strict';
"use strict";

var vAPI = self.vAPI = self.vAPI || {};

Expand Down Expand Up @@ -412,65 +412,62 @@
vAPI.tabs.onClosed(tabId);
}

delete vAPI.tabIcons[tabId];
delete vAPI.tabIconState[tabId];
delete vAPI.tabs.stack[tabId];
}
}, true);

/******************************************************************************/

// update badge when tab is activated
safari.application.addEventListener('activate', function(e) {
// ignore windows
if(!(e.target instanceof SafariBrowserTab)) {
vAPI.toolbarItem = false;
safari.application.addEventListener("validate", function(event) {
if(vAPI.toolbarItem === event.target) {
return;
}

// update the badge
vAPI.setIcon(vAPI.tabs.getTabId(e.target));
vAPI.toolbarItem = event.target;
}, true);
safari.application.addEventListener("activate", function(event) {
if(!(event.target instanceof SafariBrowserTab)) {
return;
}
vAPI.updateIcon(vAPI.toolbarItem);
}, true);

/******************************************************************************/

// reload the popup when it's opened
safari.application.addEventListener('popover', function(e) {
var w = e.target.contentWindow, body = w.document.body, child;
safari.application.addEventListener("popover", function(event) {
var w = event.target.contentWindow, body = w.document.body, child;
while(child = body.firstChild) {
body.removeChild(child);
}
w.location.reload();
}, true);

/******************************************************************************/
function TabIcon() {}
TabIcon.prototype.badge = 0;
TabIcon.prototype.img = "";

vAPI.tabIcons = { /*tabId: {badge: 0, img: suffix}*/ };
vAPI.setIcon = function(tabId, iconStatus, badge) {
var icon = vAPI.tabIcons[tabId];
if(typeof icon === "undefined") {
icon = vAPI.tabIcons[tabId] = new TabIcon();
}
function TabIconState() {}
TabIconState.prototype.badge = 0;
TabIconState.prototype.img = "";

// If we've been passed a badge/iconStatus:
if(typeof badge !== "undefined") {
icon.badge = badge;
icon.img = (iconStatus === "on" ? "" : "-off");
vAPI.tabIconState = { /*tabId: {badge: 0, img: suffix}*/ };
vAPI.updateIcon = function(icon) {
var tabId = vAPI.tabs.getTabId(icon.browserWindow.activeTab),
state = vAPI.tabIconState[tabId];
if(typeof state === "undefined") {
state = vAPI.tabIconState[tabId] = new TabIconState();
}

var items = safari.extension.toolbarItems,
i = items.length;

var curWindow = safari.application.activeBrowserWindow;
while(i --) {
if(items[i].browserWindow === curWindow) {
items[i].badge = icon.badge;
items[i].image = vAPI.getURL("img/browsericons/icon16" +
icon.img + ".png");
return;
}
icon.badge = state.badge;
icon.image = vAPI.getURL("img/browsericons/icon16" + state.img + ".png");
};
vAPI.setIcon = function(tabId, iconStatus, badge) {
var state = vAPI.tabIconState[tabId];
if(typeof state === "undefined") {
state = vAPI.tabIconState[tabId] = new TabIconState();
}
state.badge = badge || 0;
state.img = (iconStatus === "on" ? "" : "-off");
vAPI.updateIcon(vAPI.toolbarItem);
};

/******************************************************************************/
Expand Down

0 comments on commit e9ee6ab

Please sign in to comment.