From b301ac031e0c2e9a99cb6f8953319d44e22f33d2 Mon Sep 17 00:00:00 2001 From: Deathamns Date: Thu, 25 Dec 2014 14:53:30 +0100 Subject: [PATCH] Popup related changes --- platform/chromium/vapi-common.js | 16 +++++---- platform/firefox/vapi-background.js | 49 +++++++++++++++++---------- platform/firefox/vapi-common.js | 8 +++++ platform/safari/vapi-background.js | 13 -------- platform/safari/vapi-common.js | 17 ++++++++++ src/css/common.css | 20 ++++------- src/css/popup.css | 15 +++++++-- src/js/element-picker.js | 3 -- src/js/popup.js | 52 ++++++++--------------------- src/popup.html | 4 +-- 10 files changed, 103 insertions(+), 94 deletions(-) diff --git a/platform/chromium/vapi-common.js b/platform/chromium/vapi-common.js index 7797452d3..9fcffc852 100644 --- a/platform/chromium/vapi-common.js +++ b/platform/chromium/vapi-common.js @@ -73,18 +73,22 @@ vAPI.download = function(details) { /******************************************************************************/ -vAPI.getURL = function(path) { - return chrome.runtime.getURL(path); -}; +vAPI.getURL = chrome.runtime.getURL; -vAPI.i18n = function(s) { - return chrome.i18n.getMessage(s); -}; +/******************************************************************************/ + +vAPI.i18n = chrome.i18n.getMessage; setScriptDirection(vAPI.i18n('@@ui_locale')); /******************************************************************************/ +vAPI.closePopup = function() { + window.open('','_self').close(); +}; + +/******************************************************************************/ + })(); /******************************************************************************/ diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index 6f4b33468..01ee3a18a 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -432,14 +432,14 @@ vAPI.tabs.get = function(tabId, callback) { /******************************************************************************/ vAPI.tabs.getAll = function(window) { - var tabs = []; + var win, tab, tabs = []; - for (var win of this.getWindows()) { + for (win of this.getWindows()) { if (window && window !== win) { continue; } - for (var tab of win.gBrowser.tabs) { + for (tab of win.gBrowser.tabs) { tabs.push(tab); } } @@ -643,8 +643,23 @@ vAPI.toolbarButton.init = function() { } }); + this.closePopup = function({target}) { + CustomizableUI.hidePanelForNode( + target.ownerDocument.getElementById(vAPI.toolbarButton.panelId) + ); + }; + + vAPI.messaging.globalMessageManager.addMessageListener( + location.host + ':closePopup', + this.closePopup + ); + vAPI.unload.push(function() { CustomizableUI.destroyWidget(vAPI.toolbarButton.widgetId); + vAPI.messaging.globalMessageManager.addMessageListener( + location.host + ':closePopup', + vAPI.toolbarButton.closePopup + ); }); }; @@ -763,19 +778,19 @@ vAPI.messaging.listen = function(listenerName, callback) { /******************************************************************************/ -vAPI.messaging.onMessage = function(request) { - var messageManager = request.target.messageManager; +vAPI.messaging.onMessage = function({target, data}) { + var messageManager = target.messageManager; if (!messageManager) { // Message came from a popup, and its message manager is not usable. // So instead we broadcast to the parent window. - messageManager = request.target + messageManager = target .webNavigation.QueryInterface(Ci.nsIDocShell) .chromeEventHandler.ownerDocument.defaultView.messageManager; } - var listenerId = request.data.portName.split('|'); - var requestId = request.data.requestId; + var listenerId = data.portName.split('|'); + var requestId = data.requestId; var portName = listenerId[1]; listenerId = listenerId[0]; @@ -799,7 +814,7 @@ vAPI.messaging.onMessage = function(request) { var sender = { tab: { - id: vAPI.tabs.getTabId(request.target) + id: vAPI.tabs.getTabId(target) } }; @@ -807,19 +822,19 @@ vAPI.messaging.onMessage = function(request) { var r = vAPI.messaging.UNHANDLED; var listener = vAPI.messaging.listeners[portName]; if ( typeof listener === 'function' ) { - r = listener(request.data.msg, sender, callback); + r = listener(data.msg, sender, callback); } if ( r !== vAPI.messaging.UNHANDLED ) { return; } // Default handler - r = vAPI.messaging.defaultHandler(request.data.msg, sender, callback); + r = vAPI.messaging.defaultHandler(data.msg, sender, callback); if ( r !== vAPI.messaging.UNHANDLED ) { return; } - console.error('µBlock> messaging > unknown request: %o', request.data); + console.error('µBlock> messaging > unknown request: %o', data); // Unhandled: // Need to callback anyways in case caller expected an answer, or @@ -883,11 +898,11 @@ var httpObserver = { parentFrameId: null }, observe: function(httpChannel, topic) { + // if this check is performed, it doesn't need to be QueryInterfaced? if (!(httpChannel instanceof Ci.nsIHttpChannel)) { return; } - httpChannel = httpChannel.QueryInterface(Ci.nsIHttpChannel); var URI = httpChannel.URI, tabId, result; // the first distinct character @@ -912,10 +927,10 @@ var httpObserver = { return; } - var header = 'Content-Security-Policy'; + var CSPHeader = 'Content-Security-Policy'; try { - result = httpChannel.getResponseHeader(header); + result = httpChannel.getResponseHeader(CSPHeader); } catch (ex) { result = null; } @@ -924,12 +939,12 @@ var httpObserver = { url: URI.spec, tabId: tabId, parentFrameId: -1, - responseHeaders: result ? [{name: header, value: result}] : [] + responseHeaders: result ? [{name: CSPHeader, value: result}] : [] }); if (result) { httpChannel.setResponseHeader( - header, + CSPHeader, result.responseHeaders[0].value, true ); diff --git a/platform/firefox/vapi-common.js b/platform/firefox/vapi-common.js index cbe6dc75f..949b7e909 100644 --- a/platform/firefox/vapi-common.js +++ b/platform/firefox/vapi-common.js @@ -19,6 +19,8 @@ Home: https://github.com/gorhill/uBlock */ +/* global sendAsyncMessage */ + // For background page or non-background pages /******************************************************************************/ @@ -92,6 +94,12 @@ setScriptDirection(navigator.language); /******************************************************************************/ +vAPI.closePopup = function() { + sendAsyncMessage(location.host + ':closePopup'); +}; + +/******************************************************************************/ + })(); /******************************************************************************/ diff --git a/platform/safari/vapi-background.js b/platform/safari/vapi-background.js index f027bd5dc..678fbe558 100644 --- a/platform/safari/vapi-background.js +++ b/platform/safari/vapi-background.js @@ -408,19 +408,6 @@ safari.application.addEventListener('close', function(e) { // update badge when tab is activated safari.application.addEventListener('activate', function(e) { - // hide popover, since in some cases won't close by itself - var items = safari.extension.toolbarItems; - - for (var i = 0; i < items.length; ++i) { - if (items[i].browserWindow === safari.application.activeBrowserWindow) { - if (items[i].popover) { - items[i].popover.hide(); - } - - break; - } - } - // ignore windows if (!(e.target instanceof SafariBrowserTab)) { return; diff --git a/platform/safari/vapi-common.js b/platform/safari/vapi-common.js index 820a168ca..85e6f77d2 100644 --- a/platform/safari/vapi-common.js +++ b/platform/safari/vapi-common.js @@ -106,6 +106,23 @@ vAPI.i18n = function(s) { /******************************************************************************/ +vAPI.closePopup = function() { + var safr = safari.extension.globalPage.contentWindow.safari; + var items = safr.extension.toolbarItems; + + for (var i = 0; i < items.length; i++) { + if (items[i].browserWindow !== safr.application.activeBrowserWindow) { + continue; + } + + if (items[i].popover && items[i].popover.visible) { + items[i].popover.hide(); + } + } +}; + +/******************************************************************************/ + })(); /******************************************************************************/ diff --git a/src/css/common.css b/src/css/common.css index 043555a81..a8fa93c4c 100644 --- a/src/css/common.css +++ b/src/css/common.css @@ -35,8 +35,13 @@ body:not(.advancedUser) [data-tip]:hover:after { top: 110%; white-space: pre-line; z-index: 20; - animation: tooltip 0.8s; - -webkit-animation: tooltip 0.8s; + pointer-events: none; + opacity: 0; + } +[data-tip]:hover::after { + opacity: 1; + -webkit-transition: opacity 0.2s 0.2s; + transition: opacity 0.2s 0.2s; } body[dir=rtl] [data-tip]:hover:after { text-align: right; @@ -55,17 +60,6 @@ body[dir=rtl] [data-tip][data-tip-anchor="top"]:hover:after { right: -500%; } -@keyframes tooltip { - 0% { opacity: 0; } - 85% { opacity: 0; } - 100% { opacity: 1; } - } -@-webkit-keyframes tooltip { - 0% { opacity: 0; } - 85% { opacity: 0; } - 100% { opacity: 1; } - } - .hiddenFileInput { visibility: hidden; width: 0; diff --git a/src/css/popup.css b/src/css/popup.css index 2d6956d96..0303ced42 100644 --- a/src/css/popup.css +++ b/src/css/popup.css @@ -20,9 +20,20 @@ a { color: inherit; text-decoration: none; } -*:focus { +:focus { outline: 0; } +#gotoPrefs { + display: block; + margin: 0; + border: 0; + padding: 4px; + color: white; + font-weight: bold; + background-color: #444; + text-align: center; + cursor: pointer; + } #version { font-size: 11px; font-weight: normal; @@ -202,7 +213,7 @@ body.dirty #refresh:hover { border-left: 1px solid white; color: #444; cursor: pointer; - text-align: center; + text-align: center; width: 15%; } #dynamicFilteringContainer > div.isDomain > span:nth-of-type(1) { diff --git a/src/js/element-picker.js b/src/js/element-picker.js index 16cb52526..ff67dc2b1 100644 --- a/src/js/element-picker.js +++ b/src/js/element-picker.js @@ -986,9 +986,6 @@ var startPicker = function(details) { localMessager.send({ what: 'elementPickerArguments' }, startPicker); -// This triggers the hiding of the popover in Safari -window.focus(); - /******************************************************************************/ // https://www.youtube.com/watch?v=sociXdKnyr8 diff --git a/src/js/popup.js b/src/js/popup.js index 7143a0631..b0ae6eefc 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -64,7 +64,7 @@ var cachePopupData = function(data) { if ( typeof data !== 'object' ) { return popupData; - } + } popupData = data; scopeToSrcHostnameMap['.'] = popupData.pageHostname || ''; var hostnameDict = popupData.hostnameDict; @@ -163,8 +163,8 @@ var addDynamicFilterRow = function(des) { // Hacky? I couldn't figure a CSS recipe for this problem. // I do not want the left pane -- optional and hidden by defaut -- to - // dictate the height of the popup. The right pane dictates the height - // of the popup, and the left pane will have a scrollbar if ever its + // dictate the height of the popup. The right pane dictates the height + // of the popup, and the left pane will have a scrollbar if ever its // height is larger than what is available. if ( popupHeight === undefined ) { popupHeight = uDom('#panes > div:nth-of-type(1)').nodeAt(0).offsetHeight; @@ -310,6 +310,7 @@ var renderPopup = function() { // Conditions for request log: // - `http` or `https` scheme uDom('#gotoLog').toggleClass('enabled', isHTTP); + uDom('#gotoLog').attr('href', 'devtools.html?tabId=' + popupData.tabId); // Conditions for element picker: // - `http` or `https` scheme @@ -381,44 +382,19 @@ var toggleNetFilteringSwitch = function(ev) { /******************************************************************************/ -var gotoDashboard = function() { - messager.send({ - what: 'gotoURL', - details: { - url: 'dashboard.html', - select: true, - index: -1 - } - }); -}; - -/******************************************************************************/ - -var gotoDevTools = function() { - messager.send({ - what: 'gotoURL', - details: { - url: 'devtools.html?tabId=' + popupData.tabId, - select: true, - index: -1 - } - }); -}; - -/******************************************************************************/ - var gotoPick = function() { messager.send({ what: 'gotoPick', tabId: popupData.tabId }); - window.open('','_self').close(); + + vAPI.closePopup(); }; /******************************************************************************/ -var gotoLink = function(ev) { - if (!ev.target.href) { +var gotoURL = function(ev) { + if (!this.hasAttribute('href')) { return; } @@ -427,11 +403,13 @@ var gotoLink = function(ev) { messager.send({ what: 'gotoURL', details: { - url: ev.target.href, + url: this.getAttribute('href'), select: true, index: -1 } }); + + vAPI.closePopup(); }; /******************************************************************************/ @@ -546,14 +524,14 @@ var reloadTab = function() { // from the main extension process to a specific auxiliary extension process: // // - broadcasting() is not an option given there could be a lot of tabs opened, -// and maybe even many frames within these tabs, i.e. unacceptable overhead +// and maybe even many frames within these tabs, i.e. unacceptable overhead // regardless of whether the popup is opened or not. // // - Modifying the messaging API is not an option, as this would require // revisiting all platform-specific code to support targeted broadcasting, // which who knows could be not so trivial for some platforms. // -// A well done polling is a better anyways IMO, I prefer that data is pulled +// A well done polling is a better anyways IMO, I prefer that data is pulled // on demand rather than forcing the main process to assume a client may need // it and thus having to push it all the time unconditionally. @@ -608,11 +586,9 @@ var getPopupData = function() { uDom.onLoad(function() { getPopupData(); - uDom('h1,h2,h3,h4').on('click', gotoDashboard); uDom('#switch').on('click', toggleNetFilteringSwitch); - uDom('#gotoLog').on('click', gotoDevTools); uDom('#gotoPick').on('click', gotoPick); - uDom('a[href^=http]').on('click', gotoLink); + uDom('a[href]').on('click', gotoURL); uDom('#dfToggler').on('click', toggleDynamicFiltering); uDom('#refresh').on('click', reloadTab); }); diff --git a/src/popup.html b/src/popup.html index 7beae721b..568aff9db 100644 --- a/src/popup.html +++ b/src/popup.html @@ -9,7 +9,7 @@ -

+

@@ -18,7 +18,7 @@

  - +

?