Stop using detail summary as applies to expander

This commit is contained in:
Rob Garrison 2019-01-27 18:36:38 -06:00
parent f9ccd3eeee
commit 7d7e7e9f72
4 changed files with 33 additions and 29 deletions

View File

@ -29,7 +29,7 @@
--> -->
<template data-id="style"> <template data-id="style">
<div class="entry"> <div class="entry hide-extra">
<div class="entry-col entry-filter"> <div class="entry-col entry-filter">
<label class="checkmate" tabindex="0"> <label class="checkmate" tabindex="0">
<input class="entry-filter-toggle" type="checkbox"> <input class="entry-filter-toggle" type="checkbox">
@ -163,9 +163,7 @@
</template> </template>
<template data-id="extraAppliesTo"> <template data-id="extraAppliesTo">
<details class="applies-to-extra hidden"> <a href="#" class="applies-to-extra-expander" tabindex="0">...</a>
<summary class="applies-to-extra-expander">&nbsp;</summary>
</details>
</template> </template>
<script src="js/polyfill.js"></script> <script src="js/polyfill.js"></script>

View File

@ -144,6 +144,7 @@ Object.assign(handleEvent, {
'.header-filter': 'toggleBulkActions', '.header-filter': 'toggleBulkActions',
'.sortable': 'updateSort', '.sortable': 'updateSort',
'#applies-to-config': 'appliesConfig', '#applies-to-config': 'appliesConfig',
'.applies-to-extra-expander': 'toggleExtraAppliesTo'
}, },
entryClicked(event) { entryClicked(event) {
@ -209,6 +210,15 @@ Object.assign(handleEvent, {
$('.header-filter').classList.toggle('active', !tools.classList.contains('hidden')); $('.header-filter').classList.toggle('active', !tools.classList.contains('hidden'));
}, },
toggleExtraAppliesTo(event, entry) {
event.preventDefault();
entry.classList.toggle('hide-extra');
if (event.shiftKey) {
const state = entry.classList.contains('hide-extra');
$$('.entry').forEach(entry => entry.classList.toggle('hide-extra', state));
}
},
check(event, entry) { check(event, entry) {
event.preventDefault(); event.preventDefault();
checkUpdate(entry, {single: true}); checkUpdate(entry, {single: true});
@ -433,20 +443,8 @@ function switchUI({styleOnly} = {}) {
const missingFavicons = UI.favicons && !$('.entry-applies-to img[src]'); const missingFavicons = UI.favicons && !$('.entry-applies-to img[src]');
if (changed.targets) { if (changed.targets) {
for (const targets of $$('.entry .targets')) { for (const targets of $$('.entry .targets')) {
const items = $$('.target', targets); $$('.target', targets).forEach((el, indx) => {
const extra = $('.applies-to-extra', targets); el.classList.toggle('extra', indx >= UI.targets);
items.splice(0, UI.targets).forEach(el => {
if (!el.parentElement.classList.contains('targets')) {
targets.insertBefore(el, extra);
}
});
extra.classList.toggle('hidden', items.length < 1);
items.some(el => {
if (!el.parentElement.classList.contains('applies-to-extra')) {
extra.prepend(el);
return false;
}
return true;
}); });
} }
return; return;

View File

@ -199,6 +199,7 @@ const UI = {
const targets = parts.targets.cloneNode(true); const targets = parts.targets.cloneNode(true);
let container = targets; let container = targets;
let numTargets = 0; let numTargets = 0;
let extraClass = '';
const displayed = new Set(); const displayed = new Set();
for (const type of UI.TARGET_TYPES) { for (const type of UI.TARGET_TYPES) {
for (const section of style.sections) { for (const section of style.sections) {
@ -209,8 +210,7 @@ const UI = {
displayed.add(targetValue); displayed.add(targetValue);
const element = template.appliesToTarget.cloneNode(true); const element = template.appliesToTarget.cloneNode(true);
if (numTargets === UI.targets) { if (numTargets === UI.targets) {
container = container.appendChild(template.extraAppliesTo.cloneNode(true)); extraClass = ' extra';
container.classList.remove('hidden');
} }
element.dataset.type = type; element.dataset.type = type;
element.dataset.index = numTargets; element.dataset.index = numTargets;
@ -218,14 +218,16 @@ const UI = {
(parts.decorations[type + 'Before'] || '') + (parts.decorations[type + 'Before'] || '') +
targetValue + targetValue +
(parts.decorations[type + 'After'] || ''); (parts.decorations[type + 'After'] || '');
element.className += extraClass;
container.appendChild(element); container.appendChild(element);
numTargets++; numTargets++;
} }
} }
} }
if (numTargets <= UI.targets) {
// Include hidden expander in case user changes UI.targets // Include hidden expander in case user changes UI.targets
container.appendChild(template.extraAppliesTo.cloneNode(true)); container.appendChild(template.extraAppliesTo.cloneNode(true));
if (numTargets <= UI.targets) {
$('.applies-to-extra-expander', container).classList.add('hidden');
} }
if (numTargets) { if (numTargets) {
entryTargets.parentElement.replaceChild(targets, entryTargets); entryTargets.parentElement.replaceChild(targets, entryTargets);

View File

@ -341,13 +341,19 @@ body.all-styles-hidden-by-filters #installed:after {
.targets .target { .targets .target {
display: inline-block; display: inline-block;
padding: 0 2px; padding: 2px;
line-height: var(--favicon-size);
} }
.targets .applies-to-extra .target { .targets .applies-to-extra .target {
padding: 2px; padding: 2px;
} }
.applies-to-extra-expander {
text-decoration: none;
font-size: 1.5em;
}
.targets .target img, .targets .target img,
.targets .target svg { .targets .target svg {
max-width: var(--favicon-size); max-width: var(--favicon-size);
@ -568,17 +574,17 @@ a svg, .svg-icon.sort {
filter: grayscale(0); filter: grayscale(0);
} }
.targets details.applies-to-extra { .targets .applies-to-extra {
margin-left: 4px; margin-left: 4px;
margin-top: 5px; margin-top: 5px;
cursor: pointer; cursor: pointer;
} }
details.applies-to-extra[open] { .entry.hide-extra .target.extra {
position: absolute; display: none;
background: #eee; }
z-index: 90; .entry:not(.hide-extra) {
padding: 10px; height: auto !important;
} }
#faviconsHelp { #faviconsHelp {