Ensure state of more/less in panel reflect locked/disabled sections

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1059
This commit is contained in:
Raymond Hill 2022-11-20 13:02:09 -05:00
parent 9ab8de41cf
commit eb709335f8
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
3 changed files with 28 additions and 20 deletions

View File

@ -252,11 +252,8 @@ body.mobile.no-tooltips .toolRibbon .tool {
border-inline-start: 1px solid var(--surface-1); border-inline-start: 1px solid var(--surface-1);
text-align: end; text-align: end;
} }
body[data-more="a b c d e f"] #moreButton { #moreButton.disabled,
pointer-events: none; #lessButton.disabled {
visibility: hidden;
}
body[data-more=""] #lessButton {
pointer-events: none; pointer-events: none;
visibility: hidden; visibility: hidden;
} }
@ -596,27 +593,27 @@ body.godMode #actionSelector > #dynaAllow {
:root body[data-ui~="+logger"] [href="logger-ui.html#_"] { :root body[data-ui~="+logger"] [href="logger-ui.html#_"] {
display: flex; display: flex;
} }
body:not([data-more~="a"]) [data-more="a"], body:not([data-more*="a"]) [data-more="a"],
body:not([data-more~="b"]) [data-more="b"], body:not([data-more*="b"]) [data-more="b"],
body:not([data-more~="c"]) [data-more="c"], body:not([data-more*="c"]) [data-more="c"],
body:not([data-more~="d"]) [data-more="d"], body:not([data-more*="d"]) [data-more="d"],
body:not([data-more~="f"]) [data-more="f"] { body:not([data-more*="f"]) [data-more="f"] {
height: 0; height: 0;
margin-bottom: 0 !important; margin-bottom: 0 !important;
margin-top: 0 !important; margin-top: 0 !important;
overflow-y: hidden; overflow-y: hidden;
visibility: hidden; visibility: hidden;
} }
body[data-more~="d"] hr[data-more="a"] { body[data-more*="d"] hr[data-more="a"] {
display: none; display: none;
} }
body[data-more~="c"] hr[data-more="f"] { body[data-more*="c"] hr[data-more="f"] {
display: none; display: none;
} }
body[data-more~="c"]:not([data-more~="f"]) hr[data-more="g"] { body[data-more*="c"]:not([data-more*="f"]) hr[data-more="g"] {
display: none; display: none;
} }
body:not([data-more~="e"]) [data-more="e"] { body:not([data-more*="e"]) [data-more="e"] {
display: none; display: none;
} }

View File

@ -39,7 +39,7 @@ vAPI.localStorage.getItemAsync('popupFontSize').then(value => {
// pane visibility to its last known state. By default the pane is hidden. // pane visibility to its last known state. By default the pane is hidden.
vAPI.localStorage.getItemAsync('popupPanelSections').then(bits => { vAPI.localStorage.getItemAsync('popupPanelSections').then(bits => {
if ( typeof bits !== 'number' ) { return; } if ( typeof bits !== 'number' ) { return; }
sectionBitsToAttribute(bits); setSections(bits);
}); });
/******************************************************************************/ /******************************************************************************/
@ -700,7 +700,7 @@ let renderOnce = function() {
dom.text('#version', popupData.appVersion); dom.text('#version', popupData.appVersion);
sectionBitsToAttribute(computedSections()); setSections(computedSections());
if ( popupData.uiPopupConfig !== undefined ) { if ( popupData.uiPopupConfig !== undefined ) {
dom.attr(dom.body, 'data-ui', popupData.uiPopupConfig); dom.attr(dom.body, 'data-ui', popupData.uiPopupConfig);
@ -910,7 +910,7 @@ const sectionBitsFromAttribute = function() {
const attr = document.body.dataset.more; const attr = document.body.dataset.more;
if ( attr === '' ) { return 0; } if ( attr === '' ) { return 0; }
let bits = 0; let bits = 0;
for ( const c of attr.split(' ') ) { for ( const c of attr ) {
bits |= 1 << (c.charCodeAt(0) - 97); bits |= 1 << (c.charCodeAt(0) - 97);
} }
return bits; return bits;
@ -923,7 +923,18 @@ const sectionBitsToAttribute = function(bits) {
if ( (bits & bit) === 0 ) { continue; } if ( (bits & bit) === 0 ) { continue; }
attr.push(String.fromCharCode(97 + i)); attr.push(String.fromCharCode(97 + i));
} }
document.body.dataset.more = attr.join(' '); return attr.join('');
};
const setSections = function(bits) {
const value = sectionBitsToAttribute(bits);
const min = sectionBitsToAttribute(popupData.popupPanelLockedSections);
const max = sectionBitsToAttribute(
(1 << maxNumberOfSections) - 1 & ~popupData.popupPanelDisabledSections
);
document.body.dataset.more = value;
dom.cl.toggle('#lessButton', 'disabled', value === min);
dom.cl.toggle('#moreButton', 'disabled', value === max);
}; };
const toggleSections = function(more) { const toggleSections = function(more) {
@ -943,7 +954,7 @@ const toggleSections = function(more) {
} }
if ( newBits === currentBits ) { return; } if ( newBits === currentBits ) { return; }
sectionBitsToAttribute(newBits); setSections(newBits);
popupData.popupPanelSections = newBits; popupData.popupPanelSections = newBits;
messaging.send('popupPanel', { messaging.send('popupPanel', {

View File

@ -12,7 +12,7 @@
<title data-i18n="extName"></title> <title data-i18n="extName"></title>
</head> </head>
<body class="loading" data-more="a b c d"> <body class="loading" data-more="abcd">
<div id="panes"> <div id="panes">
<div id="main"> <div id="main">
<div id="sticky"> <div id="sticky">