From 1a55ecfbcd1b0c4e1870b2305b96616c6cb7ca11 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 18 Feb 2015 16:54:05 -0700 Subject: [PATCH] Safari: off/disabled version of toolbar icon Toolbar icon now dims when on a whitelisted website --- platform/safari/vapi-background.js | 54 ++++++++++--------------- src/img/browsericons/icon16-off.png | Bin 0 -> 195 bytes src/img/browsericons/icon16-off@2x.png | Bin 0 -> 344 bytes 3 files changed, 22 insertions(+), 32 deletions(-) create mode 100644 src/img/browsericons/icon16-off.png create mode 100644 src/img/browsericons/icon16-off@2x.png diff --git a/platform/safari/vapi-background.js b/platform/safari/vapi-background.js index 1a417a4c7..756c26f55 100644 --- a/platform/safari/vapi-background.js +++ b/platform/safari/vapi-background.js @@ -377,7 +377,7 @@ i = wins.length, j; - while(i--) { + while(i --) { j = wins[i].tabs.length; while(j--) { @@ -426,13 +426,13 @@ return; } - // update the badge, when tab is selected - vAPI.setIcon(); + // update the badge + vAPI.setIcon(vAPI.tabs.getTabId(e.target)); }, true); /******************************************************************************/ - // reload the popup when that is opened + // reload the popup when it's opened safari.application.addEventListener('popover', function(e) { var w = e.target.contentWindow, body = w.document.body, child; while(child = body.firstChild) { @@ -442,42 +442,32 @@ }, true); /******************************************************************************/ + function TabIcon() {} + TabIcon.prototype.badge = 0; + TabIcon.prototype.img = ""; vAPI.tabIcons = { /*tabId: {badge: 0, img: suffix}*/ }; vAPI.setIcon = function(tabId, iconStatus, badge) { - var curTabId = vAPI.tabs.getTabId( - safari.application.activeBrowserWindow.activeTab - ); - - // from 'activate' event - if(tabId === undefined) { - tabId = curTabId; - } else { - if(badge && /\D/.test(badge)) { - badge = 999; - } - - vAPI.tabIcons[tabId] = { - badge: badge || 0, - img: iconStatus === 'on' ? '' : '-off' - }; + var icon = vAPI.tabIcons[tabId]; + if(typeof icon === "undefined") { + icon = vAPI.tabIcons[tabId] = new TabIcon(); } - if(tabId !== curTabId) { - return; + // If we've been passed a badge/iconStatus: + if(typeof badge !== "undefined") { + icon.badge = badge; + icon.img = (iconStatus === "on" ? "" : "-off"); } - // if the selected tab has the same ID, then update the badge too, - // or always update it when changing tabs ('activate' event) - var items = safari.extension.toolbarItems; - var i = items.length; + var items = safari.extension.toolbarItems, + i = items.length; - while(i--) { - if(items[i].browserWindow === safari.application.activeBrowserWindow) { - var icon = vAPI.tabIcons[tabId]; - items[i].badge = icon && icon.badge || 0; - // TODO: a disabled icon for Safari - // items[i].img = vAPI.getURL(icon.img); + 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; } } diff --git a/src/img/browsericons/icon16-off.png b/src/img/browsericons/icon16-off.png new file mode 100644 index 0000000000000000000000000000000000000000..5658e96ca473c8560c346a8f822f405eac863694 GIT binary patch literal 195 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`k|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*D5XQaxQ9Ln>}1r8qE~nwqjXXf-fe-?(t;QW0ZhgJAcwzYaPL zha31E-gM+}D09x*D0RqVQ5ui4#K{XiNgTo^2RyExVYn)M;E02wgegPP0k(`O1``B( pr8WFLLOf4}ob-8;mfpa?%)l>fx@Uz&qaV;h22WQ%mvv4FO#lifKK1|r literal 0 HcmV?d00001 diff --git a/src/img/browsericons/icon16-off@2x.png b/src/img/browsericons/icon16-off@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..a7130c8a3cfdf0bdd17ff7ecc1091f1426225b4a GIT binary patch literal 344 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz$r9IylHmNblJdl&R0hYC{G?O` z&)mfH)S%SFl*+=BsWw1GzdT(WLn>}1B}gP3@aS1IYu2nfg;a+{H^rl(qPR567%qJJ z>7do`9+r6f3?DNQPhkBP0UtcrVO1zk*2;!izA0bYK9mM%dA<^FxRn!9#B%SR;JtZ* oqB4#fvdtdMz0AnYz{tk%bV9y;s9;npFccU(UHx3vIVCg!0DJL%yZ`_I literal 0 HcmV?d00001