Skip to content

Commit 0d77ccd

Browse files
committed
Add advanced setting to force popup panel orientation
Related discussion: uBlockOrigin/uBlock-issues#2419 (reply in thread) Name: `popupPanelOrientation` Supported values: - `unset` (default): uBO decides whichever mode is best - `landscape`: force popup panel to landscape mode - `portrait`: force popup panel to portrait mode
1 parent 46ea551 commit 0d77ccd

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

src/js/background.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ const hiddenSettingsDefault = {
8080
modifyWebextFlavor: 'unset',
8181
popupFontSize: 'unset',
8282
popupPanelDisabledSections: 0,
83-
popupPanelLockedSections: 0,
8483
popupPanelHeightMode: 0,
84+
popupPanelLockedSections: 0,
85+
popupPanelOrientation: 'unset',
8586
requestJournalProcessPeriod: 1000,
8687
requestStatsDisabled: false,
8788
selfieDelayInSeconds: 53,

src/js/messaging.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ const popupDataFromTabId = function(tabId, tabTitle) {
378378
popupPanelDisabledSections: µbhs.popupPanelDisabledSections,
379379
popupPanelLockedSections: µbhs.popupPanelLockedSections,
380380
popupPanelHeightMode: µbhs.popupPanelHeightMode,
381+
popupPanelOrientation: µbhs.popupPanelOrientation,
381382
tabId,
382383
tabTitle,
383384
tooltipsDisabled: µbus.tooltipsDisabled,

src/js/popup-fenix.js

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ let renderOnce = function() {
802802
dom.attr('#firewall [title][data-src]', 'title', null);
803803
}
804804

805-
// This must be done the firewall is populated
805+
// This must be done when the firewall is populated
806806
if ( popupData.popupPanelHeightMode === 1 ) {
807807
dom.cl.add(dom.body, 'vMin');
808808
}
@@ -1462,6 +1462,31 @@ const getPopupData = async function(tabId, first = false) {
14621462
}
14631463
};
14641464

1465+
const setOrientation = async ( ) => {
1466+
if ( dom.cl.has(dom.root, 'mobile') ) {
1467+
dom.cl.remove(dom.root, 'desktop');
1468+
dom.cl.add(dom.root, 'portrait');
1469+
return;
1470+
}
1471+
if ( selfURL.searchParams.get('portrait') !== null ) {
1472+
dom.cl.add(dom.root, 'portrait');
1473+
return;
1474+
}
1475+
if ( popupData.popupPanelOrientation === 'landscape' ) { return; }
1476+
if ( popupData.popupPanelOrientation === 'portrait' ) {
1477+
dom.cl.add(dom.root, 'portrait');
1478+
return;
1479+
}
1480+
if ( dom.cl.has(dom.root, 'desktop') === false ) { return; }
1481+
await nextFrames(8);
1482+
const main = qs$('#main');
1483+
const firewall = qs$('#firewall');
1484+
const minWidth = (main.offsetWidth + firewall.offsetWidth) / 1.1;
1485+
if ( window.innerWidth < minWidth ) {
1486+
dom.cl.add(dom.root, 'portrait');
1487+
}
1488+
};
1489+
14651490
// The purpose of the following code is to reset to a vertical layout
14661491
// should the viewport not be enough wide to accommodate the horizontal
14671492
// layout.
@@ -1474,24 +1499,7 @@ const getPopupData = async function(tabId, first = false) {
14741499
// Use a tolerance proportional to the sum of the width of the panes
14751500
// when testing against viewport width.
14761501
const checkViewport = async function() {
1477-
if (
1478-
dom.cl.has(dom.root, 'mobile') ||
1479-
selfURL.searchParams.get('portrait')
1480-
) {
1481-
dom.cl.add(dom.root, 'portrait');
1482-
dom.cl.remove(dom.root, 'desktop');
1483-
} else if ( dom.cl.has(dom.root, 'desktop') ) {
1484-
await nextFrames(8);
1485-
const main = qs$('#main');
1486-
const firewall = qs$('#firewall');
1487-
const minWidth = (main.offsetWidth + firewall.offsetWidth) / 1.1;
1488-
if (
1489-
selfURL.searchParams.get('portrait') ||
1490-
window.innerWidth < minWidth
1491-
) {
1492-
dom.cl.add(dom.root, 'portrait');
1493-
}
1494-
}
1502+
await setOrientation();
14951503
if ( dom.cl.has(dom.root, 'portrait') ) {
14961504
const panes = qs$('#panes');
14971505
const sticky = qs$('#sticky');

0 commit comments

Comments
 (0)