1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-07 03:12:33 +01:00
This commit is contained in:
Raymond Hill 2018-05-04 08:44:54 -04:00
parent 8be1aed04d
commit 14709d18cf
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
4 changed files with 107 additions and 106 deletions

View File

@ -701,7 +701,7 @@ vAPI.setIcon = (function() {
chrome.browserAction.onClicked.addListener(function(tab) { chrome.browserAction.onClicked.addListener(function(tab) {
vAPI.tabs.open({ vAPI.tabs.open({
select: true, select: true,
url: 'popup.html?tabId=' + tab.id + '&mobile=1' url: 'popup.html?tabId=' + tab.id + '&responsive=1'
}); });
}); });

View File

@ -1,25 +1,15 @@
body { body {
background-color: white; background-color: white;
border: 0; border: 0;
float: left; display: flex;
flex-direction: column;
margin: 0; margin: 0;
opacity: 1; opacity: 1;
overflow: hidden; overflow: hidden;
padding: 0; padding: 0;
white-space: nowrap; white-space: nowrap;
} width: fit-content;
body.fullsize { width: -moz-fit-content;
overflow: auto;
}
body.mobile {
overflow-y: auto;
}
/**
https://github.com/gorhill/uBlock/issues/83
.portrait = portrait mode = width is constrained = optimize layout accordingly.
*/
body.portrait {
width: 100%;
} }
h2 { h2 {
@ -50,30 +40,22 @@ a {
padding: calc(0.1em + 1px) 0; padding: calc(0.1em + 1px) 0;
position: relative; position: relative;
text-align: center; text-align: center;
width: 100%;
} }
#version { #version {
font-size: 90%; font-size: 90%;
font-weight: normal; font-weight: normal;
} }
body[dir="ltr"] #panes {
direction: rtl;
}
body[dir="rtl"] #panes {
direction: ltr;
}
body, #panes {
text-align: right; /* this helps the popup render better at "intermediate" widths */
}
#panes {
display: flex;
flex-direction: row-reverse;
}
#panes > div { #panes > div {
display: inline-block; display: inline-block;
position: relative; position: relative;
vertical-align: top; vertical-align: top;
} }
body.portrait #panes > div {
display: block;
width: 100%;
}
body[dir="ltr"] #panes > div { body[dir="ltr"] #panes > div {
direction: ltr; direction: ltr;
} }
@ -81,6 +63,7 @@ body[dir="rtl"] #panes > div {
direction: rtl; direction: rtl;
} }
#panes > div:nth-of-type(2) { #panes > div:nth-of-type(2) {
flex-shrink: 0;
font-family: "Noto Sans", sans-serif; font-family: "Noto Sans", sans-serif;
overflow-y: auto; overflow-y: auto;
overflow-x: hidden; overflow-x: hidden;
@ -93,14 +76,7 @@ body[dir="ltr"] #panes > div:nth-of-type(2) {
direction: rtl; direction: rtl;
margin-right: 1px; margin-right: 1px;
} }
/** body[dir="rtl"] #panes > div:nth-of-type(2) {
Scroll bar to the right.
Firefox bug: when popup is rendered inside hamburger menu panel, Firefox is
unable to render the scroll bar to the left.
Maybe <https://bugzilla.mozilla.org/show_bug.cgi?id=1139306>?
*/
body[dir="rtl"] #panes > div:nth-of-type(2),
body.portrait[dir="ltr"] #panes > div:nth-of-type(2) {
direction: ltr; direction: ltr;
margin-left: 1px; margin-left: 1px;
} }
@ -543,3 +519,21 @@ body.advancedUser #firewallContainer > div > span.noopRule.ownRule {
#firewallContainer.dirty ~ #rulesetTools > span:hover { #firewallContainer.dirty ~ #rulesetTools > span:hover {
color: black; color: black;
} }
body.responsive {
overflow-y: auto;
width: auto;
}
body.responsive #panes {
flex-wrap: wrap;
}
body.responsive #panes > div:nth-of-type(1) {
flex-shrink: 0;
flex-grow: 1;
}
body.responsive #panes > div:nth-of-type(2) {
flex-grow: 8;
flex-shrink: 1;
width: auto;
}

View File

@ -40,9 +40,13 @@ if ( typeof popupFontSize === 'string' && popupFontSize !== 'unset' ) {
var dfPaneVisibleStored = vAPI.localStorage.getItem('popupFirewallPane') === 'true'; var dfPaneVisibleStored = vAPI.localStorage.getItem('popupFirewallPane') === 'true';
// No restriction on vertical size? // Popup panel can be in one of two modes:
if ( /[\?&]fullsize=1/.test(window.location.search) ) { // - not responsive: viewport is expected to adjust to popup panel size
document.body.classList.add('fullsize'); // - responsive: popup panel must adjust to viewport size -- this happens when
// the viewport is not resized by the browser to perfectly fits uBO's popup
// panel.
if ( /[\?&]responsive=1/.test(window.location.search) ) {
document.body.classList.add('responsive');
} }
// Mobile device? // Mobile device?
@ -50,29 +54,10 @@ if ( /[\?&]fullsize=1/.test(window.location.search) ) {
// - If at least one of the window's viewport dimension is larger than the // - If at least one of the window's viewport dimension is larger than the
// corresponding device's screen dimension, assume uBO's popup panel sits in // corresponding device's screen dimension, assume uBO's popup panel sits in
// its own tab. // its own tab.
if ( if ( vAPI.webextFlavor.soup.has('mobile') ) {
/[\?&]mobile=1/.test(window.location.search) || document.body.classList.add('responsive');
window.innerWidth >= window.screen.availWidth ||
window.innerHeight >= window.screen.availHeight
) {
document.body.classList.add('mobile');
} }
// The padlock/eraser must be manually positioned:
// - Its vertical position depends on the height of the popup title bar
// - Its horizontal position depends on whether there is a vertical scrollbar.
var positionRulesetTools = function() {
var vpos = document.getElementById('appinfo')
.getBoundingClientRect()
.bottom + window.scrollY + 3;
var hpos = document.getElementById('firewallContainer')
.getBoundingClientRect()
.left + window.scrollX + 3;
var style = document.getElementById('rulesetTools').style;
style.setProperty('top', (vpos >>> 0) + 'px');
style.setProperty('left', (hpos >>> 0) + 'px');
};
// https://github.com/chrisaljoudi/uBlock/issues/996 // https://github.com/chrisaljoudi/uBlock/issues/996
// Experimental: mitigate glitchy popup UI: immediately set the firewall pane // Experimental: mitigate glitchy popup UI: immediately set the firewall pane
// visibility to its last known state. By default the pane is hidden. // visibility to its last known state. By default the pane is hidden.
@ -115,6 +100,24 @@ var reCyrillicAmbiguous = /[\u042c\u0430\u0433\u0435\u043e\u043f\u0440\u0441\u04
/******************************************************************************/ /******************************************************************************/
// The padlock/eraser must be manually positioned:
// - Its vertical position depends on the height of the popup title bar
// - Its horizontal position depends on whether there is a vertical scrollbar.
var positionRulesetTools = function() {
var vpos = document.getElementById('appinfo')
.getBoundingClientRect()
.bottom + window.scrollY + 3;
var hpos = document.getElementById('firewallContainer')
.getBoundingClientRect()
.left + window.scrollX + 3;
var style = document.getElementById('rulesetTools').style;
style.setProperty('top', (vpos >>> 0) + 'px');
style.setProperty('left', (hpos >>> 0) + 'px');
};
/******************************************************************************/
var cachePopupData = function(data) { var cachePopupData = function(data) {
popupData = {}; popupData = {};
scopeToSrcHostnameMap['.'] = ''; scopeToSrcHostnameMap['.'] = '';
@ -584,43 +587,47 @@ var renderOnce = function() {
uDom('#firewallContainer [data-i18n-tip][data-src]').removeAttr('data-tip'); uDom('#firewallContainer [data-i18n-tip][data-src]').removeAttr('data-tip');
} }
// https://github.com/gorhill/uBlock/issues/2274
// Make use of the whole viewport when in responsive mode.
if ( document.body.classList.contains('responsive') ) { return; }
// For large displays: we do not want the left pane -- optional and // For large displays: we do not want the left pane -- optional and
// hidden by defaut -- to dictate the height of the popup. The right pane // 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 // dictates the height of the popup, and the left pane will have a
// scrollbar if ever its height is more than what is available. // scrollbar if ever its height is more than what is available.
// For small displays: we use the whole viewport. // For small displays: we use the whole viewport.
var panes = uDom.nodeFromId('panes'), let rpane = uDom.nodeFromSelector('#panes > div:first-of-type'),
rpane = uDom.nodeFromSelector('#panes > div:first-of-type'),
lpane = uDom.nodeFromSelector('#panes > div:last-of-type'); lpane = uDom.nodeFromSelector('#panes > div:last-of-type');
var fillViewport = function() { lpane.style.setProperty('height', rpane.offsetHeight + 'px');
var newHeight = Math.max(
window.innerHeight - uDom.nodeFromSelector('#appinfo').offsetHeight, // Be prepared to fall into responsive mode if ever it is found the
rpane.offsetHeight // viewport is not a perfect match for the popup panel.
);
if ( newHeight !== lpane.offsetHeight ) { let resizeTimer;
lpane.style.setProperty('height', newHeight + 'px'); let resize = function() {
} resizeTimer = undefined;
// https://github.com/gorhill/uBlock/issues/3038 // Do not use equality, fractional pixel dimension occurs and must
// - Resize the firewall pane while minding the space between the panes. // be ignored.
var newWidth = window.innerWidth - panes.offsetWidth + lpane.offsetWidth; if (
if ( newWidth !== lpane.offsetWidth ) { Math.abs(document.body.offsetWidth - window.innerWidth) < 2 &&
lpane.style.setProperty('width', newWidth + 'px'); Math.abs(document.body.offsetHeight - window.innerHeight) < 2
) {
return;
} }
document.body.classList.add('responsive');
lpane.style.removeProperty('height');
window.removeEventListener('resize', resizeAsync);
}; };
let resizeAsync = function() {
// https://github.com/gorhill/uBlock/issues/2274 if ( resizeTimer !== undefined ) {
// Make use of the whole viewport on mobile devices. clearTimeout(resizeTimer);
if ( document.body.classList.contains('mobile') ) { }
fillViewport(); resizeTimer = vAPI.setTimeout(resize, 67);
window.addEventListener('resize', fillViewport); };
return; window.addEventListener('resize', resizeAsync);
} resizeAsync();
if ( document.body.classList.contains('fullsize') === false ) {
lpane.style.setProperty('height', rpane.offsetHeight + 'px');
}
}; };
/******************************************************************************/ /******************************************************************************/
@ -864,7 +871,7 @@ var toggleMinimize = function(ev) {
{ {
what: 'gotoURL', what: 'gotoURL',
details: { details: {
url: 'popup.html?tabId=' + popupData.tabId + '&fullsize=1', url: 'popup.html?tabId=' + popupData.tabId + '&responsive=1',
select: true, select: true,
index: -1 index: -1
} }
@ -1066,31 +1073,31 @@ var onHideTooltip = function() {
(function() { (function() {
// If there's no tab id specified in the query string, // If there's no tab id specified in the query string,
// it will default to current tab. // it will default to current tab.
var tabId = null; let tabId = null;
// Extract the tab id of the page this popup is for // Extract the tab id of the page this popup is for
var matches = window.location.search.match(/[\?&]tabId=([^&]+)/); let matches = window.location.search.match(/[\?&]tabId=([^&]+)/);
if ( matches && matches.length === 2 ) { if ( matches && matches.length === 2 ) {
tabId = parseInt(matches[1], 10) || 0; tabId = parseInt(matches[1], 10) || 0;
} }
getPopupData(tabId); getPopupData(tabId);
uDom('#switch').on('click', toggleNetFilteringSwitch);
uDom('#gotoZap').on('click', gotoZap);
uDom('#gotoPick').on('click', gotoPick);
uDom('h2').on('click', toggleFirewallPane);
uDom('#refresh').on('click', reloadTab);
uDom('.hnSwitch').on('click', toggleHostnameSwitch);
uDom('#saveRules').on('click', saveFirewallRules);
uDom('#revertRules').on('click', revertFirewallRules);
uDom('[data-i18n="popupAnyRulePrompt"]').on('click', toggleMinimize);
uDom('body').on('mouseenter', '[data-tip]', onShowTooltip)
.on('mouseleave', '[data-tip]', onHideTooltip);
uDom('a[href]').on('click', gotoURL);
})(); })();
uDom('#switch').on('click', toggleNetFilteringSwitch);
uDom('#gotoZap').on('click', gotoZap);
uDom('#gotoPick').on('click', gotoPick);
uDom('h2').on('click', toggleFirewallPane);
uDom('#refresh').on('click', reloadTab);
uDom('.hnSwitch').on('click', toggleHostnameSwitch);
uDom('#saveRules').on('click', saveFirewallRules);
uDom('#revertRules').on('click', revertFirewallRules);
uDom('[data-i18n="popupAnyRulePrompt"]').on('click', toggleMinimize);
uDom('body').on('mouseenter', '[data-tip]', onShowTooltip)
.on('mouseleave', '[data-tip]', onHideTooltip);
uDom('a[href]').on('click', gotoURL);
/******************************************************************************/ /******************************************************************************/
})(); })();

View File

@ -2,8 +2,8 @@
<html id="uBO-popup-panel"> <html id="uBO-popup-panel">
<head> <head>
<meta name="viewport" content="width=470"><!-- When showing as a tab in fennec, scale to full size (150px + 320px) -->
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/common.css" type="text/css"> <link rel="stylesheet" href="css/common.css" type="text/css">
<link rel="stylesheet" href="css/popup.css" type="text/css"> <link rel="stylesheet" href="css/popup.css" type="text/css">
<link rel="stylesheet" href="css/vapi-popup.css" type="text/css"><!-- Optional platform-specific CSS rules --> <link rel="stylesheet" href="css/vapi-popup.css" type="text/css"><!-- Optional platform-specific CSS rules -->