Update all assets
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/*global SelectBox, gettext, interpolate, quickElement, SelectFilter*/
|
||||
/*global SelectBox, gettext, ngettext, interpolate, quickElement, SelectFilter*/
|
||||
/*
|
||||
SelectFilter2 - Turns a multiple-select box into a filter interface.
|
||||
|
||||
@@ -15,6 +15,7 @@ Requires core.js and SelectBox.js.
|
||||
const from_box = document.getElementById(field_id);
|
||||
from_box.id += '_from'; // change its ID
|
||||
from_box.className = 'filtered';
|
||||
from_box.setAttribute('aria-labelledby', field_id + '_from_title');
|
||||
|
||||
for (const p of from_box.parentNode.getElementsByTagName('p')) {
|
||||
if (p.classList.contains("info")) {
|
||||
@@ -30,23 +31,23 @@ Requires core.js and SelectBox.js.
|
||||
|
||||
// <div class="selector"> or <div class="selector stacked">
|
||||
const selector_div = quickElement('div', from_box.parentNode);
|
||||
// Make sure the selector div is at the beginning so that the
|
||||
// add link would be displayed to the right of the widget.
|
||||
from_box.parentNode.prepend(selector_div);
|
||||
selector_div.className = is_stacked ? 'selector stacked' : 'selector';
|
||||
|
||||
// <div class="selector-available">
|
||||
const selector_available = quickElement('div', selector_div);
|
||||
selector_available.className = 'selector-available';
|
||||
const title_available = quickElement('h2', selector_available, interpolate(gettext('Available %s') + ' ', [field_name]));
|
||||
const selector_available_title = quickElement('div', selector_available);
|
||||
selector_available_title.id = field_id + '_from_title';
|
||||
selector_available_title.className = 'selector-available-title';
|
||||
quickElement('label', selector_available_title, interpolate(gettext('Available %s') + ' ', [field_name]), 'for', field_id + '_from');
|
||||
quickElement(
|
||||
'span', title_available, '',
|
||||
'class', 'help help-tooltip help-icon',
|
||||
'title', interpolate(
|
||||
gettext(
|
||||
'This is the list of available %s. You may choose some by ' +
|
||||
'selecting them in the box below and then clicking the ' +
|
||||
'"Choose" arrow between the two boxes.'
|
||||
),
|
||||
[field_name]
|
||||
)
|
||||
'p',
|
||||
selector_available_title,
|
||||
interpolate(gettext('Choose %s by selecting them and then select the "Choose" arrow button.'), [field_name]),
|
||||
'class', 'helptext'
|
||||
);
|
||||
|
||||
const filter_p = quickElement('p', selector_available, '', 'id', field_id + '_filter');
|
||||
@@ -57,7 +58,7 @@ Requires core.js and SelectBox.js.
|
||||
quickElement(
|
||||
'span', search_filter_label, '',
|
||||
'class', 'help-tooltip search-label-icon',
|
||||
'title', interpolate(gettext("Type into this box to filter down the list of available %s."), [field_name])
|
||||
'aria-label', interpolate(gettext("Type into this box to filter down the list of available %s."), [field_name])
|
||||
);
|
||||
|
||||
filter_p.appendChild(document.createTextNode(' '));
|
||||
@@ -66,32 +67,47 @@ Requires core.js and SelectBox.js.
|
||||
filter_input.id = field_id + '_input';
|
||||
|
||||
selector_available.appendChild(from_box);
|
||||
const choose_all = quickElement('a', selector_available, gettext('Choose all'), 'title', interpolate(gettext('Click to choose all %s at once.'), [field_name]), 'href', '#', 'id', field_id + '_add_all_link');
|
||||
choose_all.className = 'selector-chooseall';
|
||||
const choose_all = quickElement(
|
||||
'button',
|
||||
selector_available,
|
||||
interpolate(gettext('Choose all %s'), [field_name]),
|
||||
'id', field_id + '_add_all',
|
||||
'class', 'selector-chooseall',
|
||||
'type', 'button'
|
||||
);
|
||||
|
||||
// <ul class="selector-chooser">
|
||||
const selector_chooser = quickElement('ul', selector_div);
|
||||
selector_chooser.className = 'selector-chooser';
|
||||
const add_link = quickElement('a', quickElement('li', selector_chooser), gettext('Choose'), 'title', gettext('Choose'), 'href', '#', 'id', field_id + '_add_link');
|
||||
add_link.className = 'selector-add';
|
||||
const remove_link = quickElement('a', quickElement('li', selector_chooser), gettext('Remove'), 'title', gettext('Remove'), 'href', '#', 'id', field_id + '_remove_link');
|
||||
remove_link.className = 'selector-remove';
|
||||
const add_button = quickElement(
|
||||
'button',
|
||||
quickElement('li', selector_chooser),
|
||||
interpolate(gettext('Choose selected %s'), [field_name]),
|
||||
'id', field_id + '_add',
|
||||
'class', 'selector-add',
|
||||
'type', 'button'
|
||||
);
|
||||
const remove_button = quickElement(
|
||||
'button',
|
||||
quickElement('li', selector_chooser),
|
||||
interpolate(gettext('Remove selected %s'), [field_name]),
|
||||
'id', field_id + '_remove',
|
||||
'class', 'selector-remove',
|
||||
'type', 'button'
|
||||
);
|
||||
|
||||
// <div class="selector-chosen">
|
||||
const selector_chosen = quickElement('div', selector_div, '', 'id', field_id + '_selector_chosen');
|
||||
selector_chosen.className = 'selector-chosen';
|
||||
const title_chosen = quickElement('h2', selector_chosen, interpolate(gettext('Chosen %s') + ' ', [field_name]));
|
||||
const selector_chosen_title = quickElement('div', selector_chosen);
|
||||
selector_chosen_title.className = 'selector-chosen-title';
|
||||
selector_chosen_title.id = field_id + '_to_title';
|
||||
quickElement('label', selector_chosen_title, interpolate(gettext('Chosen %s') + ' ', [field_name]), 'for', field_id + '_to');
|
||||
quickElement(
|
||||
'span', title_chosen, '',
|
||||
'class', 'help help-tooltip help-icon',
|
||||
'title', interpolate(
|
||||
gettext(
|
||||
'This is the list of chosen %s. You may remove some by ' +
|
||||
'selecting them in the box below and then clicking the ' +
|
||||
'"Remove" arrow between the two boxes.'
|
||||
),
|
||||
[field_name]
|
||||
)
|
||||
'p',
|
||||
selector_chosen_title,
|
||||
interpolate(gettext('Remove %s by selecting them and then select the "Remove" arrow button.'), [field_name]),
|
||||
'class', 'helptext'
|
||||
);
|
||||
|
||||
const filter_selected_p = quickElement('p', selector_chosen, '', 'id', field_id + '_filter_selected');
|
||||
@@ -102,7 +118,7 @@ Requires core.js and SelectBox.js.
|
||||
quickElement(
|
||||
'span', search_filter_selected_label, '',
|
||||
'class', 'help-tooltip search-label-icon',
|
||||
'title', interpolate(gettext("Type into this box to filter down the list of selected %s."), [field_name])
|
||||
'aria-label', interpolate(gettext("Type into this box to filter down the list of selected %s."), [field_name])
|
||||
);
|
||||
|
||||
filter_selected_p.appendChild(document.createTextNode(' '));
|
||||
@@ -110,21 +126,34 @@ Requires core.js and SelectBox.js.
|
||||
const filter_selected_input = quickElement('input', filter_selected_p, '', 'type', 'text', 'placeholder', gettext("Filter"));
|
||||
filter_selected_input.id = field_id + '_selected_input';
|
||||
|
||||
const to_box = quickElement('select', selector_chosen, '', 'id', field_id + '_to', 'multiple', '', 'size', from_box.size, 'name', from_box.name);
|
||||
to_box.className = 'filtered';
|
||||
|
||||
quickElement(
|
||||
'select',
|
||||
selector_chosen,
|
||||
'',
|
||||
'id', field_id + '_to',
|
||||
'multiple', '',
|
||||
'size', from_box.size,
|
||||
'name', from_box.name,
|
||||
'aria-labelledby', field_id + '_to_title',
|
||||
'class', 'filtered'
|
||||
);
|
||||
const warning_footer = quickElement('div', selector_chosen, '', 'class', 'list-footer-display');
|
||||
quickElement('span', warning_footer, '', 'id', field_id + '_list-footer-display-text');
|
||||
quickElement('span', warning_footer, ' (click to clear)', 'class', 'list-footer-display__clear');
|
||||
|
||||
const clear_all = quickElement('a', selector_chosen, gettext('Remove all'), 'title', interpolate(gettext('Click to remove all chosen %s at once.'), [field_name]), 'href', '#', 'id', field_id + '_remove_all_link');
|
||||
clear_all.className = 'selector-clearall';
|
||||
quickElement('span', warning_footer, ' ' + gettext('(click to clear)'), 'class', 'list-footer-display__clear');
|
||||
const clear_all = quickElement(
|
||||
'button',
|
||||
selector_chosen,
|
||||
interpolate(gettext('Remove all %s'), [field_name]),
|
||||
'id', field_id + '_remove_all',
|
||||
'class', 'selector-clearall',
|
||||
'type', 'button'
|
||||
);
|
||||
|
||||
from_box.name = from_box.name + '_old';
|
||||
|
||||
// Set up the JavaScript event handlers for the select box filter interface
|
||||
const move_selection = function(e, elem, move_func, from, to) {
|
||||
if (elem.classList.contains('active')) {
|
||||
if (!elem.hasAttribute('disabled')) {
|
||||
move_func(from, to);
|
||||
SelectFilter.refresh_icons(field_id);
|
||||
SelectFilter.refresh_filtered_selects(field_id);
|
||||
@@ -135,10 +164,10 @@ Requires core.js and SelectBox.js.
|
||||
choose_all.addEventListener('click', function(e) {
|
||||
move_selection(e, this, SelectBox.move_all, field_id + '_from', field_id + '_to');
|
||||
});
|
||||
add_link.addEventListener('click', function(e) {
|
||||
add_button.addEventListener('click', function(e) {
|
||||
move_selection(e, this, SelectBox.move, field_id + '_from', field_id + '_to');
|
||||
});
|
||||
remove_link.addEventListener('click', function(e) {
|
||||
remove_button.addEventListener('click', function(e) {
|
||||
move_selection(e, this, SelectBox.move, field_id + '_to', field_id + '_from');
|
||||
});
|
||||
clear_all.addEventListener('click', function(e) {
|
||||
@@ -223,13 +252,12 @@ Requires core.js and SelectBox.js.
|
||||
refresh_icons: function(field_id) {
|
||||
const from = document.getElementById(field_id + '_from');
|
||||
const to = document.getElementById(field_id + '_to');
|
||||
// Active if at least one item is selected
|
||||
document.getElementById(field_id + '_add_link').classList.toggle('active', SelectFilter.any_selected(from));
|
||||
document.getElementById(field_id + '_remove_link').classList.toggle('active', SelectFilter.any_selected(to));
|
||||
// Active if the corresponding box isn't empty
|
||||
document.getElementById(field_id + '_add_all_link').classList.toggle('active', from.querySelector('option'));
|
||||
document.getElementById(field_id + '_remove_all_link').classList.toggle('active', to.querySelector('option'));
|
||||
SelectFilter.refresh_filtered_warning(field_id);
|
||||
// Disabled if no items are selected.
|
||||
document.getElementById(field_id + '_add').disabled = !SelectFilter.any_selected(from);
|
||||
document.getElementById(field_id + '_remove').disabled = !SelectFilter.any_selected(to);
|
||||
// Disabled if the corresponding box is empty.
|
||||
document.getElementById(field_id + '_add_all').disabled = !from.querySelector('option');
|
||||
document.getElementById(field_id + '_remove_all').disabled = !to.querySelector('option');
|
||||
},
|
||||
filter_key_press: function(event, field_id, source, target) {
|
||||
const source_box = document.getElementById(field_id + source);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*global gettext, interpolate, ngettext*/
|
||||
/*global gettext, interpolate, ngettext, Actions*/
|
||||
'use strict';
|
||||
{
|
||||
function show(selector) {
|
||||
@@ -179,6 +179,9 @@
|
||||
}
|
||||
});
|
||||
}
|
||||
// Sync counter when navigating to the page, such as through the back
|
||||
// button.
|
||||
window.addEventListener('pageshow', (event) => updateCounter(actionCheckboxes, options));
|
||||
};
|
||||
|
||||
// Call function fn when the DOM is loaded and ready. If it is already
|
||||
|
||||
@@ -55,8 +55,9 @@
|
||||
if (elem.classList.contains('vManyToManyRawIdAdminField') && elem.value) {
|
||||
elem.value += ',' + chosenId;
|
||||
} else {
|
||||
document.getElementById(name).value = chosenId;
|
||||
elem.value = chosenId;
|
||||
}
|
||||
$(elem).trigger('change');
|
||||
const index = relatedWindows.indexOf(win);
|
||||
if (index > -1) {
|
||||
relatedWindows.splice(index, 1);
|
||||
@@ -79,13 +80,15 @@
|
||||
siblings.each(function() {
|
||||
const elm = $(this);
|
||||
elm.attr('href', elm.attr('data-href-template').replace('__fk__', value));
|
||||
elm.removeAttr('aria-disabled');
|
||||
});
|
||||
} else {
|
||||
siblings.removeAttr('href');
|
||||
siblings.attr('aria-disabled', true);
|
||||
}
|
||||
}
|
||||
|
||||
function updateRelatedSelectsOptions(currentSelect, win, objId, newRepr, newId) {
|
||||
function updateRelatedSelectsOptions(currentSelect, win, objId, newRepr, newId, skipIds = []) {
|
||||
// After create/edit a model from the options next to the current
|
||||
// select (+ or :pencil:) update ForeignKey PK of the rest of selects
|
||||
// in the page.
|
||||
@@ -94,11 +97,11 @@
|
||||
// Extract the model from the popup url '.../<model>/add/' or
|
||||
// '.../<model>/<id>/change/' depending the action (add or change).
|
||||
const modelName = path.split('/')[path.split('/').length - (objId ? 4 : 3)];
|
||||
// Exclude autocomplete selects.
|
||||
const selectsRelated = document.querySelectorAll(`[data-model-ref="${modelName}"] select:not(.admin-autocomplete)`);
|
||||
// Select elements with a specific model reference and context of "available-source".
|
||||
const selectsRelated = document.querySelectorAll(`[data-model-ref="${modelName}"] [data-context="available-source"]`);
|
||||
|
||||
selectsRelated.forEach(function(select) {
|
||||
if (currentSelect === select) {
|
||||
if (currentSelect === select || skipIds && skipIds.includes(select.id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -107,6 +110,11 @@
|
||||
if (!option) {
|
||||
option = new Option(newRepr, newId);
|
||||
select.options.add(option);
|
||||
// Update SelectBox cache for related fields.
|
||||
if (window.SelectBox !== undefined && !SelectBox.cache[currentSelect.id]) {
|
||||
SelectBox.add_to_cache(select.id, option);
|
||||
SelectBox.redisplay(select.id);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -134,9 +142,14 @@
|
||||
$(elem).trigger('change');
|
||||
} else {
|
||||
const toId = name + "_to";
|
||||
const toElem = document.getElementById(toId);
|
||||
const o = new Option(newRepr, newId);
|
||||
SelectBox.add_to_cache(toId, o);
|
||||
SelectBox.redisplay(toId);
|
||||
if (toElem && toElem.nodeName.toUpperCase() === 'SELECT') {
|
||||
const skipIds = [name + "_from"];
|
||||
updateRelatedSelectsOptions(toElem, win, null, newRepr, newId, skipIds);
|
||||
}
|
||||
}
|
||||
const index = relatedWindows.indexOf(win);
|
||||
if (index > -1) {
|
||||
@@ -193,6 +206,7 @@
|
||||
window.dismissChangeRelatedObjectPopup = dismissChangeRelatedObjectPopup;
|
||||
window.dismissDeleteRelatedObjectPopup = dismissDeleteRelatedObjectPopup;
|
||||
window.dismissChildPopups = dismissChildPopups;
|
||||
window.relatedWindows = relatedWindows;
|
||||
|
||||
// Kept for backward compatibility
|
||||
window.showAddAnotherPopup = showRelatedObjectPopup;
|
||||
|
||||
@@ -36,6 +36,24 @@ depends on core.js for utility functions like removeChildren or quickElement
|
||||
pgettext('abbrev. month December', 'Dec')
|
||||
],
|
||||
daysOfWeek: [
|
||||
gettext('Sunday'),
|
||||
gettext('Monday'),
|
||||
gettext('Tuesday'),
|
||||
gettext('Wednesday'),
|
||||
gettext('Thursday'),
|
||||
gettext('Friday'),
|
||||
gettext('Saturday')
|
||||
],
|
||||
daysOfWeekAbbrev: [
|
||||
pgettext('abbrev. day Sunday', 'Sun'),
|
||||
pgettext('abbrev. day Monday', 'Mon'),
|
||||
pgettext('abbrev. day Tuesday', 'Tue'),
|
||||
pgettext('abbrev. day Wednesday', 'Wed'),
|
||||
pgettext('abbrev. day Thursday', 'Thur'),
|
||||
pgettext('abbrev. day Friday', 'Fri'),
|
||||
pgettext('abbrev. day Saturday', 'Sat')
|
||||
],
|
||||
daysOfWeekInitial: [
|
||||
pgettext('one letter Sunday', 'S'),
|
||||
pgettext('one letter Monday', 'M'),
|
||||
pgettext('one letter Tuesday', 'T'),
|
||||
@@ -98,7 +116,7 @@ depends on core.js for utility functions like removeChildren or quickElement
|
||||
// Draw days-of-week header
|
||||
let tableRow = quickElement('tr', tableBody);
|
||||
for (let i = 0; i < 7; i++) {
|
||||
quickElement('th', tableRow, CalendarNamespace.daysOfWeek[(i + CalendarNamespace.firstDayOfWeek) % 7]);
|
||||
quickElement('th', tableRow, CalendarNamespace.daysOfWeekInitial[(i + CalendarNamespace.firstDayOfWeek) % 7]);
|
||||
}
|
||||
|
||||
const startingPos = new Date(year, month - 1, 1 - CalendarNamespace.firstDayOfWeek).getDay();
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
/*global gettext*/
|
||||
'use strict';
|
||||
{
|
||||
window.addEventListener('load', function() {
|
||||
// Add anchor tag for Show/Hide link
|
||||
const fieldsets = document.querySelectorAll('fieldset.collapse');
|
||||
for (const [i, elem] of fieldsets.entries()) {
|
||||
// Don't hide if fields in this fieldset have errors
|
||||
if (elem.querySelectorAll('div.errors, ul.errorlist').length === 0) {
|
||||
elem.classList.add('collapsed');
|
||||
const h2 = elem.querySelector('h2');
|
||||
const link = document.createElement('a');
|
||||
link.id = 'fieldsetcollapser' + i;
|
||||
link.className = 'collapse-toggle';
|
||||
link.href = '#';
|
||||
link.textContent = gettext('Show');
|
||||
h2.appendChild(document.createTextNode(' ('));
|
||||
h2.appendChild(link);
|
||||
h2.appendChild(document.createTextNode(')'));
|
||||
}
|
||||
}
|
||||
// Add toggle to hide/show anchor tag
|
||||
const toggleFunc = function(ev) {
|
||||
if (ev.target.matches('.collapse-toggle')) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
const fieldset = ev.target.closest('fieldset');
|
||||
if (fieldset.classList.contains('collapsed')) {
|
||||
// Show
|
||||
ev.target.textContent = gettext('Hide');
|
||||
fieldset.classList.remove('collapsed');
|
||||
} else {
|
||||
// Hide
|
||||
ev.target.textContent = gettext('Show');
|
||||
fieldset.classList.add('collapsed');
|
||||
}
|
||||
}
|
||||
};
|
||||
document.querySelectorAll('fieldset.module').forEach(function(el) {
|
||||
el.addEventListener('click', toggleFunc);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -85,6 +85,18 @@ function findPosY(obj) {
|
||||
return (this.getSeconds() < 10) ? '0' + this.getSeconds() : this.getSeconds();
|
||||
};
|
||||
|
||||
Date.prototype.getAbbrevDayName = function() {
|
||||
return typeof window.CalendarNamespace === "undefined"
|
||||
? '0' + this.getDay()
|
||||
: window.CalendarNamespace.daysOfWeekAbbrev[this.getDay()];
|
||||
};
|
||||
|
||||
Date.prototype.getFullDayName = function() {
|
||||
return typeof window.CalendarNamespace === "undefined"
|
||||
? '0' + this.getDay()
|
||||
: window.CalendarNamespace.daysOfWeek[this.getDay()];
|
||||
};
|
||||
|
||||
Date.prototype.getAbbrevMonthName = function() {
|
||||
return typeof window.CalendarNamespace === "undefined"
|
||||
? this.getTwoDigitMonth()
|
||||
@@ -99,6 +111,8 @@ function findPosY(obj) {
|
||||
|
||||
Date.prototype.strftime = function(format) {
|
||||
const fields = {
|
||||
a: this.getAbbrevDayName(),
|
||||
A: this.getFullDayName(),
|
||||
b: this.getAbbrevMonthName(),
|
||||
B: this.getFullMonthName(),
|
||||
c: this.toString(),
|
||||
|
||||
@@ -50,11 +50,11 @@
|
||||
// If forms are laid out as table rows, insert the
|
||||
// "add" button in a new table row:
|
||||
const numCols = $this.eq(-1).children().length;
|
||||
$parent.append('<tr class="' + options.addCssClass + '"><td colspan="' + numCols + '"><a href="#">' + options.addText + "</a></tr>");
|
||||
$parent.append('<tr class="' + options.addCssClass + '"><td colspan="' + numCols + '"><a role="button" class="addlink" href="#">' + options.addText + "</a></tr>");
|
||||
addButton = $parent.find("tr:last a");
|
||||
} else {
|
||||
// Otherwise, insert it immediately after the last form:
|
||||
$this.filter(":last").after('<div class="' + options.addCssClass + '"><a href="#">' + options.addText + "</a></div>");
|
||||
$this.filter(":last").after('<div class="' + options.addCssClass + '"><a role="button" class="addlink" href="#">' + options.addText + "</a></div>");
|
||||
addButton = $this.filter(":last").next().find("a");
|
||||
}
|
||||
}
|
||||
@@ -104,15 +104,15 @@
|
||||
if (row.is("tr")) {
|
||||
// If the forms are laid out in table rows, insert
|
||||
// the remove button into the last table cell:
|
||||
row.children(":last").append('<div><a class="' + options.deleteCssClass + '" href="#">' + options.deleteText + "</a></div>");
|
||||
row.children(":last").append('<div><a role="button" class="' + options.deleteCssClass + '" href="#">' + options.deleteText + "</a></div>");
|
||||
} else if (row.is("ul") || row.is("ol")) {
|
||||
// If they're laid out as an ordered/unordered list,
|
||||
// insert an <li> after the last list item:
|
||||
row.append('<li><a class="' + options.deleteCssClass + '" href="#">' + options.deleteText + "</a></li>");
|
||||
row.append('<li><a role="button" class="' + options.deleteCssClass + '" href="#">' + options.deleteText + "</a></li>");
|
||||
} else {
|
||||
// Otherwise, just insert the remove button as the
|
||||
// last child element of the form's container:
|
||||
row.children(":first").append('<span><a class="' + options.deleteCssClass + '" href="#">' + options.deleteText + "</a></span>");
|
||||
row.children(":first").append('<span><a role="button" class="' + options.deleteCssClass + '" href="#">' + options.deleteText + "</a></span>");
|
||||
}
|
||||
// Add delete handler for each row.
|
||||
row.find("a." + options.deleteCssClass).on('click', inlineDeleteHandler.bind(this));
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/*global opener */
|
||||
'use strict';
|
||||
{
|
||||
const initData = JSON.parse(document.getElementById('django-admin-popup-response-constants').dataset.popupResponse);
|
||||
|
||||
@@ -1,56 +1,51 @@
|
||||
'use strict';
|
||||
{
|
||||
window.addEventListener('load', function(e) {
|
||||
|
||||
function setTheme(mode) {
|
||||
if (mode !== "light" && mode !== "dark" && mode !== "auto") {
|
||||
console.error(`Got invalid theme mode: ${mode}. Resetting to auto.`);
|
||||
mode = "auto";
|
||||
}
|
||||
document.documentElement.dataset.theme = mode;
|
||||
localStorage.setItem("theme", mode);
|
||||
function setTheme(mode) {
|
||||
if (mode !== "light" && mode !== "dark" && mode !== "auto") {
|
||||
console.error(`Got invalid theme mode: ${mode}. Resetting to auto.`);
|
||||
mode = "auto";
|
||||
}
|
||||
document.documentElement.dataset.theme = mode;
|
||||
localStorage.setItem("theme", mode);
|
||||
}
|
||||
|
||||
function cycleTheme() {
|
||||
const currentTheme = localStorage.getItem("theme") || "auto";
|
||||
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
|
||||
function cycleTheme() {
|
||||
const currentTheme = localStorage.getItem("theme") || "auto";
|
||||
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
|
||||
|
||||
if (prefersDark) {
|
||||
// Auto (dark) -> Light -> Dark
|
||||
if (currentTheme === "auto") {
|
||||
setTheme("light");
|
||||
} else if (currentTheme === "light") {
|
||||
setTheme("dark");
|
||||
} else {
|
||||
setTheme("auto");
|
||||
}
|
||||
if (prefersDark) {
|
||||
// Auto (dark) -> Light -> Dark
|
||||
if (currentTheme === "auto") {
|
||||
setTheme("light");
|
||||
} else if (currentTheme === "light") {
|
||||
setTheme("dark");
|
||||
} else {
|
||||
// Auto (light) -> Dark -> Light
|
||||
if (currentTheme === "auto") {
|
||||
setTheme("dark");
|
||||
} else if (currentTheme === "dark") {
|
||||
setTheme("light");
|
||||
} else {
|
||||
setTheme("auto");
|
||||
}
|
||||
setTheme("auto");
|
||||
}
|
||||
} else {
|
||||
// Auto (light) -> Dark -> Light
|
||||
if (currentTheme === "auto") {
|
||||
setTheme("dark");
|
||||
} else if (currentTheme === "dark") {
|
||||
setTheme("light");
|
||||
} else {
|
||||
setTheme("auto");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function initTheme() {
|
||||
// set theme defined in localStorage if there is one, or fallback to auto mode
|
||||
const currentTheme = localStorage.getItem("theme");
|
||||
currentTheme ? setTheme(currentTheme) : setTheme("auto");
|
||||
}
|
||||
function initTheme() {
|
||||
// set theme defined in localStorage if there is one, or fallback to auto mode
|
||||
const currentTheme = localStorage.getItem("theme");
|
||||
currentTheme ? setTheme(currentTheme) : setTheme("auto");
|
||||
}
|
||||
|
||||
function setupTheme() {
|
||||
// Attach event handlers for toggling themes
|
||||
const buttons = document.getElementsByClassName("theme-toggle");
|
||||
Array.from(buttons).forEach((btn) => {
|
||||
btn.addEventListener("click", cycleTheme);
|
||||
});
|
||||
initTheme();
|
||||
}
|
||||
|
||||
setupTheme();
|
||||
window.addEventListener('load', function(_) {
|
||||
const buttons = document.getElementsByClassName("theme-toggle");
|
||||
Array.from(buttons).forEach((btn) => {
|
||||
btn.addEventListener("click", cycleTheme);
|
||||
});
|
||||
});
|
||||
|
||||
initTheme();
|
||||
}
|
||||
|
||||
29
assets/admin/js/unusable_password_field.js
Normal file
29
assets/admin/js/unusable_password_field.js
Normal file
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
// Fallback JS for browsers which do not support :has selector used in
|
||||
// admin/css/unusable_password_fields.css
|
||||
// Remove file once all supported browsers support :has selector
|
||||
try {
|
||||
// If browser does not support :has selector this will raise an error
|
||||
document.querySelector("form:has(input)");
|
||||
} catch (error) {
|
||||
console.log("Defaulting to javascript for usable password form management: " + error);
|
||||
// JS replacement for unsupported :has selector
|
||||
document.querySelectorAll('input[name="usable_password"]').forEach(option => {
|
||||
option.addEventListener('change', function() {
|
||||
const usablePassword = (this.value === "true" ? this.checked : !this.checked);
|
||||
const submit1 = document.querySelector('input[type="submit"].set-password');
|
||||
const submit2 = document.querySelector('input[type="submit"].unset-password');
|
||||
const messages = document.querySelector('#id_unusable_warning');
|
||||
document.getElementById('id_password1').closest('.form-row').hidden = !usablePassword;
|
||||
document.getElementById('id_password2').closest('.form-row').hidden = !usablePassword;
|
||||
if (messages) {
|
||||
messages.hidden = usablePassword;
|
||||
}
|
||||
if (submit1 && submit2) {
|
||||
submit1.hidden = !usablePassword;
|
||||
submit2.hidden = usablePassword;
|
||||
}
|
||||
});
|
||||
option.dispatchEvent(new Event('change'));
|
||||
});
|
||||
}
|
||||
1883
assets/admin/js/vendor/jquery/jquery.js
vendored
1883
assets/admin/js/vendor/jquery/jquery.js
vendored
File diff suppressed because it is too large
Load Diff
4
assets/admin/js/vendor/jquery/jquery.min.js
vendored
4
assets/admin/js/vendor/jquery/jquery.min.js
vendored
File diff suppressed because one or more lines are too long
2
assets/admin/js/vendor/xregexp/LICENSE.txt
vendored
2
assets/admin/js/vendor/xregexp/LICENSE.txt
vendored
@@ -1,6 +1,6 @@
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2007-2017 Steven Levithan <http://xregexp.com/>
|
||||
Copyright (c) 2007-present Steven Levithan <http://xregexp.com/>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
9160
assets/admin/js/vendor/xregexp/xregexp.js
vendored
9160
assets/admin/js/vendor/xregexp/xregexp.js
vendored
File diff suppressed because one or more lines are too long
177
assets/admin/js/vendor/xregexp/xregexp.min.js
vendored
177
assets/admin/js/vendor/xregexp/xregexp.min.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user