diff options
author | gorhill <rhill@raymondhill.net> | 2015-03-18 13:00:07 -0400 |
---|---|---|
committer | gorhill <rhill@raymondhill.net> | 2015-03-18 13:00:07 -0400 |
commit | 74981341e817bce117af2695aaa55da907200daa (patch) | |
tree | 8ebca67efd073150b0e64d957ff2d706bbfb61d5 /src/js | |
parent | 51532fc74e1a6c2a3914b0e4adfa1235dbe3cee6 (diff) | |
download | uBlock-74981341e817bce117af2695aaa55da907200daa.zip uBlock-74981341e817bce117af2695aaa55da907200daa.tar.gz uBlock-74981341e817bce117af2695aaa55da907200daa.tar.bz2 |
attempt at addressing #514, #518
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/devtools.js | 61 | ||||
-rw-r--r-- | src/js/messaging.js | 4 |
2 files changed, 65 insertions, 0 deletions
diff --git a/src/js/devtools.js b/src/js/devtools.js index da8ed55..17a783a 100644 --- a/src/js/devtools.js +++ b/src/js/devtools.js @@ -78,6 +78,7 @@ var selectPage = function() { return; } inspector.attr('src', targetSrc); + uDom('#popup').attr('src', tabId ? 'popup.html?tabId=' + tabId : ''); // This is useful for when the user force-refresh the page: this will // prevent a reset to the original request log. @@ -93,6 +94,63 @@ var selectPage = function() { /******************************************************************************/ +var togglePopup = function() { + var tabId = uDom('#pageSelector').val() || ''; + var body = uDom('body'); + body.toggleClass('popupEnabled'); + if ( body.hasClass('popupEnabled') === false ) { + tabId = ''; + } + uDom('#popup').attr('src', tabId ? 'popup.html?tabId=' + tabId : ''); +}; + +/******************************************************************************/ + +var resizePopup = function() { + var popup = document.getElementById('popup'); + popup.style.width = popup.contentWindow.document.body.clientWidth + 'px'; + popup.style.height = popup.contentWindow.document.body.clientHeight + 'px'; +}; + +/******************************************************************************/ + +var onPopupLoaded = function() { + resizePopup(); + + if ( popupObserver !== null ) { + popupObserver.disconnect(); + } + + var popup = document.getElementById('popup'); + if ( popup.contentDocument === null ) { + return; + } + var popupBody = popup.contentDocument.body; + if ( popupBody === null ) { + return; + } + var popupPanes = popup.contentDocument.getElementById('panes'); + if ( popupPanes === null ) { + return; + } + + if ( popupObserver === null ) { + popupObserver = new MutationObserver(resizePopup); + } + + var details = { + childList: false, + attributes: true, + attributeFilter: ['class'] + }; + popupObserver.observe(popupBody, details); + popupObserver.observe(popupPanes, details); +}; + +var popupObserver = null; + +/******************************************************************************/ + uDom.onLoad(function() { var tabId; @@ -102,6 +160,9 @@ uDom.onLoad(function() { tabId = matches[1]; } + uDom('#popupToggler').on('click', togglePopup); + uDom('#popup').on('load', onPopupLoaded); + renderPageSelector(tabId); uDom('#pageSelector').on('change', pageSelectorChanged); diff --git a/src/js/messaging.js b/src/js/messaging.js index eea5110..f11de5e 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -281,6 +281,10 @@ var onMessage = function(request, sender, callback) { // Async switch ( request.what ) { case 'getPopupData': + if ( request.tabId === vAPI.noTabId ) { + callback(getStats(vAPI.noTabId, '')); + return; + } vAPI.tabs.get(request.tabId, function(tab) { // https://github.com/gorhill/uBlock/issues/1012 callback(getStats(getTargetTabId(tab), tab ? tab.title : '')); |