show + and - on all applies-to items in standard editor
This commit is contained in:
parent
0ed701a9d9
commit
6a4b3c9cf9
|
@ -405,13 +405,6 @@ body[data-match-highlight="selection"] .CodeMirror-selection-highlight-scrollbar
|
||||||
.applies-to li:not(.applies-to-everything) > * {
|
.applies-to li:not(.applies-to-everything) > * {
|
||||||
margin: 0 .2rem .5rem 0;
|
margin: 0 .2rem .5rem 0;
|
||||||
}
|
}
|
||||||
html:not(.usercss) .applies-to li .add-applies-to {
|
|
||||||
visibility: hidden;
|
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
html:not(.usercss) .applies-to li:last-child .add-applies-to {
|
|
||||||
visibility: visible
|
|
||||||
}
|
|
||||||
.applies-to li .add-applies-to:first-child {
|
.applies-to li .add-applies-to:first-child {
|
||||||
margin-left: 1rem;
|
margin-left: 1rem;
|
||||||
}
|
}
|
||||||
|
@ -905,4 +898,4 @@ html:not(.usercss) .usercss-only,
|
||||||
#help-popup.big {
|
#help-popup.big {
|
||||||
left: 3rem;
|
left: 3rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,29 +150,44 @@ function addSection(event, section) {
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addAppliesTo(list, name, value) {
|
// may be invoked as a DOM listener
|
||||||
const showingEverything = $('.applies-to-everything', list) !== null;
|
function addAppliesTo(list, type, value) {
|
||||||
|
let clickedItem;
|
||||||
|
if (this instanceof Node) {
|
||||||
|
clickedItem = this.closest('.applies-to-item');
|
||||||
|
list = this.closest('.applies-to-list');
|
||||||
|
}
|
||||||
|
const showingEverything = $('.applies-to-everything', list);
|
||||||
// blow away 'Everything' if it's there
|
// blow away 'Everything' if it's there
|
||||||
if (showingEverything) {
|
if (showingEverything) {
|
||||||
list.removeChild(list.firstChild);
|
list.removeChild(list.firstChild);
|
||||||
}
|
}
|
||||||
let e;
|
let item, toFocus;
|
||||||
if (name) {
|
|
||||||
e = template.appliesTo.cloneNode(true);
|
// a section is added with known applies-to
|
||||||
$('[name=applies-type]', e).value = name;
|
if (type) {
|
||||||
$('[name=applies-value]', e).value = value;
|
item = template.appliesTo.cloneNode(true);
|
||||||
$('.remove-applies-to', e).addEventListener('click', removeAppliesTo, false);
|
$('[name=applies-type]', item).value = type;
|
||||||
} else if (showingEverything || list.hasChildNodes()) {
|
$('[name=applies-value]', item).value = value;
|
||||||
e = template.appliesTo.cloneNode(true);
|
$('.remove-applies-to', item).addEventListener('click', removeAppliesTo);
|
||||||
if (list.hasChildNodes()) {
|
|
||||||
$('[name=applies-type]', e).value = $('li:last-child [name="applies-type"]', list).value;
|
// a "+" button was clicked
|
||||||
|
} else if (showingEverything || clickedItem) {
|
||||||
|
item = template.appliesTo.cloneNode(true);
|
||||||
|
toFocus = $('[name=applies-type]', item);
|
||||||
|
if (clickedItem) {
|
||||||
|
$('[name=applies-type]', item).value = $('[name="applies-type"]', clickedItem).value;
|
||||||
}
|
}
|
||||||
$('.remove-applies-to', e).addEventListener('click', removeAppliesTo, false);
|
$('.remove-applies-to', item).addEventListener('click', removeAppliesTo);
|
||||||
|
|
||||||
|
// a global section is added
|
||||||
} else {
|
} else {
|
||||||
e = template.appliesToEverything.cloneNode(true);
|
item = template.appliesToEverything.cloneNode(true);
|
||||||
}
|
}
|
||||||
$('.add-applies-to', e).addEventListener('click', () => addAppliesTo(list));
|
|
||||||
list.appendChild(e);
|
$('.add-applies-to', item).addEventListener('click', addAppliesTo);
|
||||||
|
list.insertBefore(item, clickedItem && clickedItem.nextElementSibling);
|
||||||
|
if (toFocus) toFocus.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupCodeMirror(sectionDiv, code, index) {
|
function setupCodeMirror(sectionDiv, code, index) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user