diff --git a/.eslintrc b/.eslintrc
index b02487d913..46ef3fe926 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -16,8 +16,10 @@
"no-unused-vars": ["error", {"vars": "local", "args": "none"}],
"no-script-url": ["error"],
"no-shadow": ["error", {"hoist": "functions"}],
+ "no-var": ["error"],
"quotes": ["off", "single"],
"linebreak-style": ["error", "unix"],
+ "prefer-const": ["error"],
"semi": ["error", "always"],
"space-before-blocks": ["error", "always"],
"space-before-function-paren": ["error", {"anonymous": "never", "named": "never"}],
@@ -25,7 +27,8 @@
"strict": ["warn", "function"]
},
"env": {
- "browser": true
+ "browser": true,
+ "es6": true
},
"globals": {
"django": false
diff --git a/django/contrib/admin/bin/compress.py b/django/contrib/admin/bin/compress.py
index b390dbca46..52ddcf5295 100644
--- a/django/contrib/admin/bin/compress.py
+++ b/django/contrib/admin/bin/compress.py
@@ -36,6 +36,7 @@ and Java version 7 or later."""
cmd.append('-q')
cmd.extend([
'google-closure-compiler',
+ '--language_out=ECMASCRIPT_2015',
'--rewrite_polyfills=false',
'--js', str(to_compress),
'--js_output_file', str(to_compress_min),
diff --git a/django/contrib/admin/static/admin/js/SelectBox.js b/django/contrib/admin/static/admin/js/SelectBox.js
index 0e92836414..17f5925c3a 100644
--- a/django/contrib/admin/static/admin/js/SelectBox.js
+++ b/django/contrib/admin/static/admin/js/SelectBox.js
@@ -1,29 +1,27 @@
(function() {
'use strict';
- var SelectBox = {
+ const SelectBox = {
cache: {},
init: function(id) {
- var box = document.getElementById(id);
- var node;
+ const box = document.getElementById(id);
SelectBox.cache[id] = [];
- var cache = SelectBox.cache[id];
- var boxOptions = box.options;
- var boxOptionsLength = boxOptions.length;
- for (var i = 0, j = boxOptionsLength; i < j; i++) {
- node = boxOptions[i];
+ const cache = SelectBox.cache[id];
+ const boxOptions = box.options;
+ const boxOptionsLength = boxOptions.length;
+ for (let i = 0, j = boxOptionsLength; i < j; i++) {
+ const node = boxOptions[i];
cache.push({value: node.value, text: node.text, displayed: 1});
}
},
redisplay: function(id) {
// Repopulate HTML select box from cache
- var box = document.getElementById(id);
- var node;
+ const box = document.getElementById(id);
box.innerHTML = '';
- var cache = SelectBox.cache[id];
- for (var i = 0, j = cache.length; i < j; i++) {
- node = cache[i];
+ const cache = SelectBox.cache[id];
+ for (let i = 0, j = cache.length; i < j; i++) {
+ const node = cache[i];
if (node.displayed) {
- var new_option = new Option(node.text, node.value, false, false);
+ const new_option = new Option(node.text, node.value, false, false);
// Shows a tooltip when hovering over the option
new_option.title = node.text;
box.appendChild(new_option);
@@ -33,16 +31,15 @@
filter: function(id, text) {
// Redisplay the HTML select box, displaying only the choices containing ALL
// the words in text. (It's an AND search.)
- var tokens = text.toLowerCase().split(/\s+/);
- var node, token;
- var cache = SelectBox.cache[id];
- for (var i = 0, j = cache.length; i < j; i++) {
- node = cache[i];
+ const tokens = text.toLowerCase().split(/\s+/);
+ const cache = SelectBox.cache[id];
+ for (let i = 0, j = cache.length; i < j; i++) {
+ const node = cache[i];
node.displayed = 1;
- var node_text = node.text.toLowerCase();
- var numTokens = tokens.length;
- for (var k = 0; k < numTokens; k++) {
- token = tokens[k];
+ const node_text = node.text.toLowerCase();
+ const numTokens = tokens.length;
+ for (let k = 0; k < numTokens; k++) {
+ const token = tokens[k];
if (node_text.indexOf(token) === -1) {
node.displayed = 0;
break; // Once the first token isn't found we're done
@@ -52,10 +49,10 @@
SelectBox.redisplay(id);
},
delete_from_cache: function(id, value) {
- var node, delete_index = null;
- var cache = SelectBox.cache[id];
- for (var i = 0, j = cache.length; i < j; i++) {
- node = cache[i];
+ let delete_index = null;
+ const cache = SelectBox.cache[id];
+ for (let i = 0, j = cache.length; i < j; i++) {
+ const node = cache[i];
if (node.value === value) {
delete_index = i;
break;
@@ -68,10 +65,9 @@
},
cache_contains: function(id, value) {
// Check if an item is contained in the cache
- var node;
- var cache = SelectBox.cache[id];
- for (var i = 0, j = cache.length; i < j; i++) {
- node = cache[i];
+ const cache = SelectBox.cache[id];
+ for (let i = 0, j = cache.length; i < j; i++) {
+ const node = cache[i];
if (node.value === value) {
return true;
}
@@ -79,13 +75,12 @@
return false;
},
move: function(from, to) {
- var from_box = document.getElementById(from);
- var option;
- var boxOptions = from_box.options;
- var boxOptionsLength = boxOptions.length;
- for (var i = 0, j = boxOptionsLength; i < j; i++) {
- option = boxOptions[i];
- var option_value = option.value;
+ const from_box = document.getElementById(from);
+ const boxOptions = from_box.options;
+ const boxOptionsLength = boxOptions.length;
+ for (let i = 0, j = boxOptionsLength; i < j; i++) {
+ const option = boxOptions[i];
+ const option_value = option.value;
if (option.selected && SelectBox.cache_contains(from, option_value)) {
SelectBox.add_to_cache(to, {value: option_value, text: option.text, displayed: 1});
SelectBox.delete_from_cache(from, option_value);
@@ -95,13 +90,12 @@
SelectBox.redisplay(to);
},
move_all: function(from, to) {
- var from_box = document.getElementById(from);
- var option;
- var boxOptions = from_box.options;
- var boxOptionsLength = boxOptions.length;
- for (var i = 0, j = boxOptionsLength; i < j; i++) {
- option = boxOptions[i];
- var option_value = option.value;
+ const from_box = document.getElementById(from);
+ const boxOptions = from_box.options;
+ const boxOptionsLength = boxOptions.length;
+ for (let i = 0, j = boxOptionsLength; i < j; i++) {
+ const option = boxOptions[i];
+ const option_value = option.value;
if (SelectBox.cache_contains(from, option_value)) {
SelectBox.add_to_cache(to, {value: option_value, text: option.text, displayed: 1});
SelectBox.delete_from_cache(from, option_value);
@@ -124,10 +118,10 @@
} );
},
select_all: function(id) {
- var box = document.getElementById(id);
- var boxOptions = box.options;
- var boxOptionsLength = boxOptions.length;
- for (var i = 0; i < boxOptionsLength; i++) {
+ const box = document.getElementById(id);
+ const boxOptions = box.options;
+ const boxOptionsLength = boxOptions.length;
+ for (let i = 0; i < boxOptionsLength; i++) {
boxOptions[i].selected = 'selected';
}
}
diff --git a/django/contrib/admin/static/admin/js/SelectFilter2.js b/django/contrib/admin/static/admin/js/SelectFilter2.js
index b4f5c06803..c428aba822 100644
--- a/django/contrib/admin/static/admin/js/SelectFilter2.js
+++ b/django/contrib/admin/static/admin/js/SelectFilter2.js
@@ -12,12 +12,12 @@ Requires core.js and SelectBox.js.
// Don't initialize on empty forms.
return;
}
- var from_box = document.getElementById(field_id);
+ const from_box = document.getElementById(field_id);
from_box.id += '_from'; // change its ID
from_box.className = 'filtered';
- var ps = from_box.parentNode.getElementsByTagName('p');
- for (var i = 0; i < ps.length; i++) {
+ const ps = from_box.parentNode.getElementsByTagName('p');
+ for (let i = 0; i < ps.length; i++) {
if (ps[i].classList.contains("info")) {
// Remove
, because it just gets in the way.
from_box.parentNode.removeChild(ps[i]);
@@ -30,13 +30,13 @@ Requires core.js and SelectBox.js.
}
//
or
- var selector_div = quickElement('div', from_box.parentNode);
+ const selector_div = quickElement('div', from_box.parentNode);
selector_div.className = is_stacked ? 'selector stacked' : 'selector';
//
- var selector_available = quickElement('div', selector_div);
+ const selector_available = quickElement('div', selector_div);
selector_available.className = 'selector-available';
- var title_available = quickElement('h2', selector_available, interpolate(gettext('Available %s') + ' ', [field_name]));
+ const title_available = quickElement('h2', selector_available, interpolate(gettext('Available %s') + ' ', [field_name]));
quickElement(
'span', title_available, '',
'class', 'help help-tooltip help-icon',
@@ -50,10 +50,10 @@ Requires core.js and SelectBox.js.
)
);
- var filter_p = quickElement('p', selector_available, '', 'id', field_id + '_filter');
+ const filter_p = quickElement('p', selector_available, '', 'id', field_id + '_filter');
filter_p.className = 'selector-filter';
- var search_filter_label = quickElement('label', filter_p, '', 'for', field_id + '_input');
+ const search_filter_label = quickElement('label', filter_p, '', 'for', field_id + '_input');
quickElement(
'span', search_filter_label, '',
@@ -63,25 +63,25 @@ Requires core.js and SelectBox.js.
filter_p.appendChild(document.createTextNode(' '));
- var filter_input = quickElement('input', filter_p, '', 'type', 'text', 'placeholder', gettext("Filter"));
+ const filter_input = quickElement('input', filter_p, '', 'type', 'text', 'placeholder', gettext("Filter"));
filter_input.id = field_id + '_input';
selector_available.appendChild(from_box);
- var 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');
+ 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';
//
- var selector_chooser = quickElement('ul', selector_div);
+ const selector_chooser = quickElement('ul', selector_div);
selector_chooser.className = 'selector-chooser';
- var add_link = quickElement('a', quickElement('li', selector_chooser), gettext('Choose'), 'title', gettext('Choose'), 'href', '#', 'id', field_id + '_add_link');
+ 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';
- var remove_link = quickElement('a', quickElement('li', selector_chooser), gettext('Remove'), 'title', gettext('Remove'), 'href', '#', 'id', field_id + '_remove_link');
+ 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';
//
- var selector_chosen = quickElement('div', selector_div);
+ const selector_chosen = quickElement('div', selector_div);
selector_chosen.className = 'selector-chosen';
- var title_chosen = quickElement('h2', selector_chosen, interpolate(gettext('Chosen %s') + ' ', [field_name]));
+ const title_chosen = quickElement('h2', selector_chosen, interpolate(gettext('Chosen %s') + ' ', [field_name]));
quickElement(
'span', title_chosen, '',
'class', 'help help-tooltip help-icon',
@@ -95,15 +95,15 @@ Requires core.js and SelectBox.js.
)
);
- var to_box = quickElement('select', selector_chosen, '', 'id', field_id + '_to', 'multiple', '', 'size', from_box.size, 'name', from_box.name);
+ const to_box = quickElement('select', selector_chosen, '', 'id', field_id + '_to', 'multiple', '', 'size', from_box.size, 'name', from_box.name);
to_box.className = 'filtered';
- var 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');
+ 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';
from_box.name = from_box.name + '_old';
// Set up the JavaScript event handlers for the select box filter interface
- var move_selection = function(e, elem, move_func, from, to) {
+ const move_selection = function(e, elem, move_func, from, to) {
if (elem.classList.contains('active')) {
move_func(from, to);
SelectFilter.refresh_icons(field_id);
@@ -156,11 +156,11 @@ Requires core.js and SelectBox.js.
if (!is_stacked) {
// In horizontal mode, give the same height to the two boxes.
- var j_from_box = document.getElementById(field_id + '_from');
- var j_to_box = document.getElementById(field_id + '_to');
- var height = filter_p.offsetHeight + j_from_box.offsetHeight;
+ const j_from_box = document.getElementById(field_id + '_from');
+ const j_to_box = document.getElementById(field_id + '_to');
+ let height = filter_p.offsetHeight + j_from_box.offsetHeight;
- var j_to_box_style = window.getComputedStyle(j_to_box);
+ const j_to_box_style = window.getComputedStyle(j_to_box);
if (j_to_box_style.getPropertyValue('box-sizing') === 'border-box') {
// Add the padding and border to the final height.
height += parseInt(j_to_box_style.getPropertyValue('padding-top'), 10)
@@ -176,16 +176,15 @@ Requires core.js and SelectBox.js.
SelectFilter.refresh_icons(field_id);
},
any_selected: function(field) {
- var any_selected = false;
// Temporarily add the required attribute and check validity.
field.required = true;
- any_selected = field.checkValidity();
+ const any_selected = field.checkValidity();
field.required = false;
return any_selected;
},
refresh_icons: function(field_id) {
- var from = document.getElementById(field_id + '_from');
- var to = document.getElementById(field_id + '_to');
+ 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));
@@ -194,7 +193,7 @@ Requires core.js and SelectBox.js.
document.getElementById(field_id + '_remove_all_link').classList.toggle('active', to.querySelector('option'));
},
filter_key_press: function(event, field_id) {
- var from = document.getElementById(field_id + '_from');
+ const from = document.getElementById(field_id + '_from');
// don't submit form if user pressed Enter
if ((event.which && event.which === 13) || (event.keyCode && event.keyCode === 13)) {
from.selectedIndex = 0;
@@ -204,16 +203,16 @@ Requires core.js and SelectBox.js.
}
},
filter_key_up: function(event, field_id) {
- var from = document.getElementById(field_id + '_from');
- var temp = from.selectedIndex;
+ const from = document.getElementById(field_id + '_from');
+ const temp = from.selectedIndex;
SelectBox.filter(field_id + '_from', document.getElementById(field_id + '_input').value);
from.selectedIndex = temp;
},
filter_key_down: function(event, field_id) {
- var from = document.getElementById(field_id + '_from');
+ const from = document.getElementById(field_id + '_from');
// right arrow -- move across
if ((event.which && event.which === 39) || (event.keyCode && event.keyCode === 39)) {
- var old_index = from.selectedIndex;
+ const old_index = from.selectedIndex;
SelectBox.move(field_id + '_from', field_id + '_to');
from.selectedIndex = (old_index === from.length) ? from.length - 1 : old_index;
return;
@@ -231,7 +230,7 @@ Requires core.js and SelectBox.js.
window.addEventListener('load', function(e) {
document.querySelectorAll('select.selectfilter, select.selectfilterstacked').forEach(function(el) {
- var data = el.dataset;
+ const data = el.dataset;
SelectFilter.init(el.id, data.fieldName, parseInt(data.isStacked, 10));
});
});
diff --git a/django/contrib/admin/static/admin/js/actions.js b/django/contrib/admin/static/admin/js/actions.js
index 5598da3965..9cad455b60 100644
--- a/django/contrib/admin/static/admin/js/actions.js
+++ b/django/contrib/admin/static/admin/js/actions.js
@@ -1,13 +1,13 @@
/*global gettext, interpolate, ngettext*/
(function($) {
'use strict';
- var lastChecked;
+ let lastChecked;
$.fn.actions = function(opts) {
- var options = $.extend({}, $.fn.actions.defaults, opts);
- var actionCheckboxes = $(this);
- var list_editable_changed = false;
- var showQuestion = function() {
+ const options = $.extend({}, $.fn.actions.defaults, opts);
+ const actionCheckboxes = $(this);
+ let list_editable_changed = false;
+ const showQuestion = function() {
$(options.acrossClears).hide();
$(options.acrossQuestions).show();
$(options.allContainer).hide();
@@ -40,17 +40,17 @@
.parent().parent().toggleClass(options.selectedClass, checked);
},
updateCounter = function() {
- var sel = $(actionCheckboxes).filter(":checked").length;
+ const sel = $(actionCheckboxes).filter(":checked").length;
// data-actions-icnt is defined in the generated HTML
// and contains the total amount of objects in the queryset
- var actions_icnt = $('.action-counter').data('actionsIcnt');
+ const actions_icnt = $('.action-counter').data('actionsIcnt');
$(options.counterContainer).html(interpolate(
ngettext('%(sel)s of %(cnt)s selected', '%(sel)s of %(cnt)s selected', sel), {
sel: sel,
cnt: actions_icnt
}, true));
$(options.allToggle).prop("checked", function() {
- var value;
+ let value;
if (sel === actionCheckboxes.length) {
value = true;
showQuestion();
@@ -90,9 +90,9 @@
lastChecked = null;
$(actionCheckboxes).on('click', function(event) {
if (!event) { event = window.event; }
- var target = event.target ? event.target : event.srcElement;
+ const target = event.target ? event.target : event.srcElement;
if (lastChecked && $.data(lastChecked) !== $.data(target) && event.shiftKey === true) {
- var inrange = false;
+ let inrange = false;
$(lastChecked).prop("checked", target.checked)
.parent().parent().toggleClass(options.selectedClass, target.checked);
$(actionCheckboxes).each(function() {
@@ -118,7 +118,7 @@
}
});
$('form#changelist-form input[name="_save"]').on('click', function(event) {
- var action_changed = false;
+ let action_changed = false;
$('select option:selected', options.actionContainer).each(function() {
if ($(this).val()) {
action_changed = true;
@@ -145,7 +145,7 @@
selectedClass: "selected"
};
$(document).ready(function() {
- var $actionsEls = $('tr input.action-select');
+ const $actionsEls = $('tr input.action-select');
if ($actionsEls.length > 0) {
$actionsEls.actions();
}
diff --git a/django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js b/django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js
index 6470d0fbf6..d00656473d 100644
--- a/django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js
+++ b/django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js
@@ -4,7 +4,7 @@
//
(function() {
'use strict';
- var DateTimeShortcuts = {
+ const DateTimeShortcuts = {
calendars: [],
calendarInputs: [],
clockInputs: [],
@@ -28,16 +28,16 @@
timezoneWarningClass: 'timezonewarning', // class of the warning for timezone mismatch
timezoneOffset: 0,
init: function() {
- var body = document.getElementsByTagName('body')[0];
- var serverOffset = body.dataset.adminUtcOffset;
+ const body = document.getElementsByTagName('body')[0];
+ const serverOffset = body.dataset.adminUtcOffset;
if (serverOffset) {
- var localOffset = new Date().getTimezoneOffset() * -60;
+ const localOffset = new Date().getTimezoneOffset() * -60;
DateTimeShortcuts.timezoneOffset = localOffset - serverOffset;
}
- var inputs = document.getElementsByTagName('input');
- for (var i = 0; i < inputs.length; i++) {
- var inp = inputs[i];
+ const inputs = document.getElementsByTagName('input');
+ for (let i = 0; i < inputs.length; i++) {
+ const inp = inputs[i];
if (inp.type === 'text' && inp.classList.contains('vTimeField')) {
DateTimeShortcuts.addClock(inp);
DateTimeShortcuts.addTimezoneWarning(inp);
@@ -50,11 +50,11 @@
},
// Return the current time while accounting for the server timezone.
now: function() {
- var body = document.getElementsByTagName('body')[0];
- var serverOffset = body.dataset.adminUtcOffset;
+ const body = document.getElementsByTagName('body')[0];
+ const serverOffset = body.dataset.adminUtcOffset;
if (serverOffset) {
- var localNow = new Date();
- var localOffset = localNow.getTimezoneOffset() * -60;
+ const localNow = new Date();
+ const localOffset = localNow.getTimezoneOffset() * -60;
localNow.setTime(localNow.getTime() + 1000 * (serverOffset - localOffset));
return localNow;
} else {
@@ -63,8 +63,8 @@
},
// Add a warning when the time zone in the browser and backend do not match.
addTimezoneWarning: function(inp) {
- var warningClass = DateTimeShortcuts.timezoneWarningClass;
- var timezoneOffset = DateTimeShortcuts.timezoneOffset / 3600;
+ const warningClass = DateTimeShortcuts.timezoneWarningClass;
+ let timezoneOffset = DateTimeShortcuts.timezoneOffset / 3600;
// Only warn if there is a time zone mismatch.
if (!timezoneOffset) {
@@ -76,7 +76,7 @@
return;
}
- var message;
+ let message;
if (timezoneOffset > 0) {
message = ngettext(
'Note: You are %s hour ahead of server time.',
@@ -94,7 +94,7 @@
}
message = interpolate(message, [timezoneOffset]);
- var warning = document.createElement('span');
+ const warning = document.createElement('span');
warning.className = warningClass;
warning.textContent = message;
inp.parentNode.appendChild(document.createElement('br'));
@@ -102,22 +102,22 @@
},
// Add clock widget to a given field
addClock: function(inp) {
- var num = DateTimeShortcuts.clockInputs.length;
+ const num = DateTimeShortcuts.clockInputs.length;
DateTimeShortcuts.clockInputs[num] = inp;
DateTimeShortcuts.dismissClockFunc[num] = function() { DateTimeShortcuts.dismissClock(num); return true; };
// Shortcut links (clock icon and "Now" link)
- var shortcuts_span = document.createElement('span');
+ const shortcuts_span = document.createElement('span');
shortcuts_span.className = DateTimeShortcuts.shortCutsClass;
inp.parentNode.insertBefore(shortcuts_span, inp.nextSibling);
- var now_link = document.createElement('a');
+ const now_link = document.createElement('a');
now_link.href = "#";
now_link.textContent = gettext('Now');
now_link.addEventListener('click', function(e) {
e.preventDefault();
DateTimeShortcuts.handleClockQuicklink(num, -1);
});
- var clock_link = document.createElement('a');
+ const clock_link = document.createElement('a');
clock_link.href = '#';
clock_link.id = DateTimeShortcuts.clockLinkName + num;
clock_link.addEventListener('click', function(e) {
@@ -152,7 +152,7 @@
//
Cancel
//
- var clock_box = document.createElement('div');
+ const clock_box = document.createElement('div');
clock_box.style.display = 'none';
clock_box.style.position = 'absolute';
clock_box.className = 'clockbox module';
@@ -161,23 +161,23 @@
clock_box.addEventListener('click', function(e) { e.stopPropagation(); });
quickElement('h2', clock_box, gettext('Choose a time'));
- var time_list = quickElement('ul', clock_box);
+ const time_list = quickElement('ul', clock_box);
time_list.className = 'timelist';
// The list of choices can be overridden in JavaScript like this:
// DateTimeShortcuts.clockHours.name = [['3 a.m.', 3]];
// where name is the name attribute of the .
- var name = typeof DateTimeShortcuts.clockHours[inp.name] === 'undefined' ? 'default_' : inp.name;
+ const name = typeof DateTimeShortcuts.clockHours[inp.name] === 'undefined' ? 'default_' : inp.name;
DateTimeShortcuts.clockHours[name].forEach(function(element) {
- var time_link = quickElement('a', quickElement('li', time_list), gettext(element[0]), 'href', '#');
+ const time_link = quickElement('a', quickElement('li', time_list), gettext(element[0]), 'href', '#');
time_link.addEventListener('click', function(e) {
e.preventDefault();
DateTimeShortcuts.handleClockQuicklink(num, element[1]);
});
});
- var cancel_p = quickElement('p', clock_box);
+ const cancel_p = quickElement('p', clock_box);
cancel_p.className = 'calendar-cancel';
- var cancel_link = quickElement('a', cancel_p, gettext('Cancel'), 'href', '#');
+ const cancel_link = quickElement('a', cancel_p, gettext('Cancel'), 'href', '#');
cancel_link.addEventListener('click', function(e) {
e.preventDefault();
DateTimeShortcuts.dismissClock(num);
@@ -192,8 +192,8 @@
});
},
openClock: function(num) {
- var clock_box = document.getElementById(DateTimeShortcuts.clockDivName + num);
- var clock_link = document.getElementById(DateTimeShortcuts.clockLinkName + num);
+ const clock_box = document.getElementById(DateTimeShortcuts.clockDivName + num);
+ const clock_link = document.getElementById(DateTimeShortcuts.clockLinkName + num);
// Recalculate the clockbox position
// is it left-to-right or right-to-left layout ?
@@ -216,7 +216,7 @@
document.removeEventListener('click', DateTimeShortcuts.dismissClockFunc[num]);
},
handleClockQuicklink: function(num, val) {
- var d;
+ let d;
if (val === -1) {
d = DateTimeShortcuts.now();
}
@@ -229,23 +229,23 @@
},
// Add calendar widget to a given field.
addCalendar: function(inp) {
- var num = DateTimeShortcuts.calendars.length;
+ const num = DateTimeShortcuts.calendars.length;
DateTimeShortcuts.calendarInputs[num] = inp;
DateTimeShortcuts.dismissCalendarFunc[num] = function() { DateTimeShortcuts.dismissCalendar(num); return true; };
// Shortcut links (calendar icon and "Today" link)
- var shortcuts_span = document.createElement('span');
+ const shortcuts_span = document.createElement('span');
shortcuts_span.className = DateTimeShortcuts.shortCutsClass;
inp.parentNode.insertBefore(shortcuts_span, inp.nextSibling);
- var today_link = document.createElement('a');
+ const today_link = document.createElement('a');
today_link.href = '#';
today_link.appendChild(document.createTextNode(gettext('Today')));
today_link.addEventListener('click', function(e) {
e.preventDefault();
DateTimeShortcuts.handleCalendarQuickLink(num, 0);
});
- var cal_link = document.createElement('a');
+ const cal_link = document.createElement('a');
cal_link.href = '#';
cal_link.id = DateTimeShortcuts.calendarLinkName + num;
cal_link.addEventListener('click', function(e) {
@@ -281,7 +281,7 @@
//
//
Cancel
//
- var cal_box = document.createElement('div');
+ const cal_box = document.createElement('div');
cal_box.style.display = 'none';
cal_box.style.position = 'absolute';
cal_box.className = 'calendarbox module';
@@ -290,15 +290,15 @@
cal_box.addEventListener('click', function(e) { e.stopPropagation(); });
// next-prev links
- var cal_nav = quickElement('div', cal_box);
- var cal_nav_prev = quickElement('a', cal_nav, '<', 'href', '#');
+ const cal_nav = quickElement('div', cal_box);
+ const cal_nav_prev = quickElement('a', cal_nav, '<', 'href', '#');
cal_nav_prev.className = 'calendarnav-previous';
cal_nav_prev.addEventListener('click', function(e) {
e.preventDefault();
DateTimeShortcuts.drawPrev(num);
});
- var cal_nav_next = quickElement('a', cal_nav, '>', 'href', '#');
+ const cal_nav_next = quickElement('a', cal_nav, '>', 'href', '#');
cal_nav_next.className = 'calendarnav-next';
cal_nav_next.addEventListener('click', function(e) {
e.preventDefault();
@@ -306,15 +306,15 @@
});
// main box
- var cal_main = quickElement('div', cal_box, '', 'id', DateTimeShortcuts.calendarDivName2 + num);
+ const cal_main = quickElement('div', cal_box, '', 'id', DateTimeShortcuts.calendarDivName2 + num);
cal_main.className = 'calendar';
DateTimeShortcuts.calendars[num] = new Calendar(DateTimeShortcuts.calendarDivName2 + num, DateTimeShortcuts.handleCalendarCallback(num));
DateTimeShortcuts.calendars[num].drawCurrent();
// calendar shortcuts
- var shortcuts = quickElement('div', cal_box);
+ const shortcuts = quickElement('div', cal_box);
shortcuts.className = 'calendar-shortcuts';
- var day_link = quickElement('a', shortcuts, gettext('Yesterday'), 'href', '#');
+ let day_link = quickElement('a', shortcuts, gettext('Yesterday'), 'href', '#');
day_link.addEventListener('click', function(e) {
e.preventDefault();
DateTimeShortcuts.handleCalendarQuickLink(num, -1);
@@ -333,9 +333,9 @@
});
// cancel bar
- var cancel_p = quickElement('p', cal_box);
+ const cancel_p = quickElement('p', cal_box);
cancel_p.className = 'calendar-cancel';
- var cancel_link = quickElement('a', cancel_p, gettext('Cancel'), 'href', '#');
+ const cancel_link = quickElement('a', cancel_p, gettext('Cancel'), 'href', '#');
cancel_link.addEventListener('click', function(e) {
e.preventDefault();
DateTimeShortcuts.dismissCalendar(num);
@@ -349,18 +349,18 @@
});
},
openCalendar: function(num) {
- var cal_box = document.getElementById(DateTimeShortcuts.calendarDivName1 + num);
- var cal_link = document.getElementById(DateTimeShortcuts.calendarLinkName + num);
- var inp = DateTimeShortcuts.calendarInputs[num];
+ const cal_box = document.getElementById(DateTimeShortcuts.calendarDivName1 + num);
+ const cal_link = document.getElementById(DateTimeShortcuts.calendarLinkName + num);
+ const inp = DateTimeShortcuts.calendarInputs[num];
// Determine if the current value in the input has a valid date.
// If so, draw the calendar with that date's year and month.
if (inp.value) {
- var format = get_format('DATE_INPUT_FORMATS')[0];
- var selected = inp.value.strptime(format);
- var year = selected.getUTCFullYear();
- var month = selected.getUTCMonth() + 1;
- var re = /\d{4}/;
+ const format = get_format('DATE_INPUT_FORMATS')[0];
+ const selected = inp.value.strptime(format);
+ const year = selected.getUTCFullYear();
+ const month = selected.getUTCMonth() + 1;
+ const re = /\d{4}/;
if (re.test(year.toString()) && month >= 1 && month <= 12) {
DateTimeShortcuts.calendars[num].drawDate(month, year, selected);
}
@@ -392,7 +392,7 @@
DateTimeShortcuts.calendars[num].drawNextMonth();
},
handleCalendarCallback: function(num) {
- var format = get_format('DATE_INPUT_FORMATS')[0];
+ let format = get_format('DATE_INPUT_FORMATS')[0];
// the format needs to be escaped a little
format = format.replace('\\', '\\\\')
.replace('\r', '\\r')
@@ -406,7 +406,7 @@
};
},
handleCalendarQuickLink: function(num, offset) {
- var d = DateTimeShortcuts.now();
+ const d = DateTimeShortcuts.now();
d.setDate(d.getDate() + offset);
DateTimeShortcuts.calendarInputs[num].value = d.strftime(get_format('DATE_INPUT_FORMATS')[0]);
DateTimeShortcuts.calendarInputs[num].focus();
diff --git a/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js b/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
index 74298048fa..f45cf113f6 100644
--- a/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
+++ b/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
@@ -6,8 +6,8 @@
'use strict';
function showAdminPopup(triggeringLink, name_regexp, add_popup) {
- var name = triggeringLink.id.replace(name_regexp, '');
- var href = triggeringLink.href;
+ const name = triggeringLink.id.replace(name_regexp, '');
+ let href = triggeringLink.href;
if (add_popup) {
if (href.indexOf('?') === -1) {
href += '?_popup=1';
@@ -15,7 +15,7 @@
href += '&_popup=1';
}
}
- var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes');
+ const win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes');
win.focus();
return false;
}
@@ -25,8 +25,8 @@
}
function dismissRelatedLookupPopup(win, chosenId) {
- var name = win.name;
- var elem = document.getElementById(name);
+ const name = win.name;
+ const elem = document.getElementById(name);
if (elem.classList.contains('vManyToManyRawIdAdminField') && elem.value) {
elem.value += ',' + chosenId;
} else {
@@ -40,15 +40,15 @@
}
function updateRelatedObjectLinks(triggeringLink) {
- var $this = $(triggeringLink);
- var siblings = $this.nextAll('.view-related, .change-related, .delete-related');
+ const $this = $(triggeringLink);
+ const siblings = $this.nextAll('.view-related, .change-related, .delete-related');
if (!siblings.length) {
return;
}
- var value = $this.val();
+ const value = $this.val();
if (value) {
siblings.each(function() {
- var elm = $(this);
+ const elm = $(this);
elm.attr('href', elm.attr('data-href-template').replace('__fk__', value));
});
} else {
@@ -57,10 +57,10 @@
}
function dismissAddRelatedObjectPopup(win, newId, newRepr) {
- var name = win.name;
- var elem = document.getElementById(name);
+ const name = win.name;
+ const elem = document.getElementById(name);
if (elem) {
- var elemName = elem.nodeName.toUpperCase();
+ const elemName = elem.nodeName.toUpperCase();
if (elemName === 'SELECT') {
elem.options[elem.options.length] = new Option(newRepr, newId, true, true);
} else if (elemName === 'INPUT') {
@@ -73,8 +73,8 @@
// Trigger a change event to update related links if required.
$(elem).trigger('change');
} else {
- var toId = name + "_to";
- var o = new Option(newRepr, newId);
+ const toId = name + "_to";
+ const o = new Option(newRepr, newId);
SelectBox.add_to_cache(toId, o);
SelectBox.redisplay(toId);
}
@@ -82,9 +82,9 @@
}
function dismissChangeRelatedObjectPopup(win, objId, newRepr, newId) {
- var id = win.name.replace(/^edit_/, '');
- var selectsSelector = interpolate('#%s, #%s_from, #%s_to', [id, id, id]);
- var selects = $(selectsSelector);
+ const id = win.name.replace(/^edit_/, '');
+ const selectsSelector = interpolate('#%s, #%s_from, #%s_to', [id, id, id]);
+ const selects = $(selectsSelector);
selects.find('option').each(function() {
if (this.value === objId) {
this.textContent = newRepr;
@@ -101,9 +101,9 @@
}
function dismissDeleteRelatedObjectPopup(win, objId) {
- var id = win.name.replace(/^delete_/, '');
- var selectsSelector = interpolate('#%s, #%s_from, #%s_to', [id, id, id]);
- var selects = $(selectsSelector);
+ const id = win.name.replace(/^delete_/, '');
+ const selectsSelector = interpolate('#%s, #%s_from, #%s_to', [id, id, id]);
+ const selects = $(selectsSelector);
selects.find('option').each(function() {
if (this.value === objId) {
$(this).remove();
@@ -132,7 +132,7 @@
$('body').on('click', '.related-widget-wrapper-link', function(e) {
e.preventDefault();
if (this.href) {
- var event = $.Event('django:show-related', {href: this.href});
+ const event = $.Event('django:show-related', {href: this.href});
$(this).trigger(event);
if (!event.isDefaultPrevented()) {
showRelatedObjectPopup(this);
@@ -140,7 +140,7 @@
}
});
$('body').on('change', '.related-widget-wrapper select', function(e) {
- var event = $.Event('django:update-related');
+ const event = $.Event('django:update-related');
$(this).trigger(event);
if (!event.isDefaultPrevented()) {
updateRelatedObjectLinks(this);
@@ -149,7 +149,7 @@
$('.related-widget-wrapper select').trigger('change');
$('body').on('click', '.related-lookup', function(e) {
e.preventDefault();
- var event = $.Event('django:lookup-related');
+ const event = $.Event('django:lookup-related');
$(this).trigger(event);
if (!event.isDefaultPrevented()) {
showRelatedObjectLookupPopup(this);
diff --git a/django/contrib/admin/static/admin/js/autocomplete.js b/django/contrib/admin/static/admin/js/autocomplete.js
index 65c0702dd9..0689d0e305 100644
--- a/django/contrib/admin/static/admin/js/autocomplete.js
+++ b/django/contrib/admin/static/admin/js/autocomplete.js
@@ -1,7 +1,7 @@
(function($) {
'use strict';
- var init = function($element, options) {
- var settings = $.extend({
+ const init = function($element, options) {
+ const settings = $.extend({
ajax: {
data: function(params) {
return {
@@ -15,9 +15,9 @@
};
$.fn.djangoAdminSelect2 = function(options) {
- var settings = $.extend({}, options);
+ const settings = $.extend({}, options);
$.each(this, function(i, element) {
- var $element = $(element);
+ const $element = $(element);
init($element, settings);
});
return this;
diff --git a/django/contrib/admin/static/admin/js/calendar.js b/django/contrib/admin/static/admin/js/calendar.js
index a4c047aa72..6c71287211 100644
--- a/django/contrib/admin/static/admin/js/calendar.js
+++ b/django/contrib/admin/static/admin/js/calendar.js
@@ -7,7 +7,7 @@ depends on core.js for utility functions like removeChildren or quickElement
(function() {
'use strict';
// CalendarNamespace -- Provides a collection of HTML calendar-related helper functions
- var CalendarNamespace = {
+ const CalendarNamespace = {
monthsOfYear: [
gettext('January'),
gettext('February'),
@@ -36,7 +36,7 @@ depends on core.js for utility functions like removeChildren or quickElement
return (((year % 4) === 0) && ((year % 100) !== 0 ) || ((year % 400) === 0));
},
getDaysInMonth: function(month, year) {
- var days;
+ let days;
if (month === 1 || month === 3 || month === 5 || month === 7 || month === 8 || month === 10 || month === 12) {
days = 31;
}
@@ -52,11 +52,11 @@ depends on core.js for utility functions like removeChildren or quickElement
return days;
},
draw: function(month, year, div_id, callback, selected) { // month = 1-12, year = 1-9999
- var today = new Date();
- var todayDay = today.getDate();
- var todayMonth = today.getMonth() + 1;
- var todayYear = today.getFullYear();
- var todayClass = '';
+ const today = new Date();
+ const todayDay = today.getDate();
+ const todayMonth = today.getMonth() + 1;
+ const todayYear = today.getFullYear();
+ let todayClass = '';
// Use UTC functions here because the date field does not contain time
// and using the UTC function variants prevent the local time offset
@@ -69,33 +69,33 @@ depends on core.js for utility functions like removeChildren or quickElement
//
// The day variable above will be 1 instead of 2 in, say, US Pacific time
// zone.
- var isSelectedMonth = false;
+ let isSelectedMonth = false;
if (typeof selected !== 'undefined') {
isSelectedMonth = (selected.getUTCFullYear() === year && (selected.getUTCMonth() + 1) === month);
}
month = parseInt(month);
year = parseInt(year);
- var calDiv = document.getElementById(div_id);
+ const calDiv = document.getElementById(div_id);
removeChildren(calDiv);
- var calTable = document.createElement('table');
+ const calTable = document.createElement('table');
quickElement('caption', calTable, CalendarNamespace.monthsOfYear[month - 1] + ' ' + year);
- var tableBody = quickElement('tbody', calTable);
+ const tableBody = quickElement('tbody', calTable);
// Draw days-of-week header
- var tableRow = quickElement('tr', tableBody);
- for (var i = 0; i < 7; i++) {
+ let tableRow = quickElement('tr', tableBody);
+ for (let i = 0; i < 7; i++) {
quickElement('th', tableRow, CalendarNamespace.daysOfWeek[(i + CalendarNamespace.firstDayOfWeek) % 7]);
}
- var startingPos = new Date(year, month - 1, 1 - CalendarNamespace.firstDayOfWeek).getDay();
- var days = CalendarNamespace.getDaysInMonth(month, year);
+ const startingPos = new Date(year, month - 1, 1 - CalendarNamespace.firstDayOfWeek).getDay();
+ const days = CalendarNamespace.getDaysInMonth(month, year);
- var nonDayCell;
+ let nonDayCell;
// Draw blanks before first of month
tableRow = quickElement('tr', tableBody);
- for (i = 0; i < startingPos; i++) {
+ for (let i = 0; i < startingPos; i++) {
nonDayCell = quickElement('td', tableRow, ' ');
nonDayCell.className = "nonday";
}
@@ -109,8 +109,8 @@ depends on core.js for utility functions like removeChildren or quickElement
}
// Draw days of month
- var currentDay = 1;
- for (i = startingPos; currentDay <= days; i++) {
+ let currentDay = 1;
+ for (let i = startingPos; currentDay <= days; i++) {
if (i % 7 === 0 && currentDay !== 1) {
tableRow = quickElement('tr', tableBody);
}
@@ -128,8 +128,8 @@ depends on core.js for utility functions like removeChildren or quickElement
todayClass += "selected";
}
- var cell = quickElement('td', tableRow, '', 'class', todayClass);
- var link = quickElement('a', cell, currentDay, 'href', '#');
+ const cell = quickElement('td', tableRow, '', 'class', todayClass);
+ const link = quickElement('a', cell, currentDay, 'href', '#');
link.addEventListener('click', calendarMonth(year, month));
currentDay++;
}
diff --git a/django/contrib/admin/static/admin/js/change_form.js b/django/contrib/admin/static/admin/js/change_form.js
index 7fc8991727..c6ca0ac11b 100644
--- a/django/contrib/admin/static/admin/js/change_form.js
+++ b/django/contrib/admin/static/admin/js/change_form.js
@@ -1,11 +1,11 @@
(function() {
'use strict';
- var inputTags = ['BUTTON', 'INPUT', 'SELECT', 'TEXTAREA'];
- var modelName = document.getElementById('django-admin-form-add-constants').dataset.modelName;
+ const inputTags = ['BUTTON', 'INPUT', 'SELECT', 'TEXTAREA'];
+ const modelName = document.getElementById('django-admin-form-add-constants').dataset.modelName;
if (modelName) {
- var form = document.getElementById(modelName + '_form');
- for (var i = 0; i < form.elements.length; i++) {
- var element = form.elements[i];
+ const form = document.getElementById(modelName + '_form');
+ for (let i = 0; i < form.elements.length; i++) {
+ const element = form.elements[i];
// HTMLElement.offsetParent returns null when the element is not
// rendered.
if (inputTags.includes(element.tagName) && !element.disabled && element.offsetParent) {
diff --git a/django/contrib/admin/static/admin/js/collapse.js b/django/contrib/admin/static/admin/js/collapse.js
index 1d8f602d40..3b001b9c53 100644
--- a/django/contrib/admin/static/admin/js/collapse.js
+++ b/django/contrib/admin/static/admin/js/collapse.js
@@ -3,14 +3,14 @@
'use strict';
window.addEventListener('load', function() {
// Add anchor tag for Show/Hide link
- var fieldsets = document.querySelectorAll('fieldset.collapse');
- for (var i = 0; i < fieldsets.length; i++) {
- var elem = fieldsets[i];
+ const fieldsets = document.querySelectorAll('fieldset.collapse');
+ for (let i = 0; i < fieldsets.length; i++) {
+ const elem = fieldsets[i];
// Don't hide if fields in this fieldset have errors
if (elem.querySelectorAll('div.errors, ul.errorlist').length === 0) {
elem.classList.add('collapsed');
- var h2 = elem.querySelector('h2');
- var link = document.createElement('a');
+ const h2 = elem.querySelector('h2');
+ const link = document.createElement('a');
link.id = 'fieldsetcollapser' + i;
link.className = 'collapse-toggle';
link.href = '#';
@@ -21,11 +21,11 @@
}
}
// Add toggle to hide/show anchor tag
- var toggleFunc = function(ev) {
+ const toggleFunc = function(ev) {
if (ev.target.matches('.collapse-toggle')) {
ev.preventDefault();
ev.stopPropagation();
- var fieldset = ev.target.closest('fieldset');
+ const fieldset = ev.target.closest('fieldset');
if (fieldset.classList.contains('collapsed')) {
// Show
ev.target.textContent = gettext('Hide');
@@ -37,8 +37,8 @@
}
}
};
- var inlineDivs = document.querySelectorAll('fieldset.module');
- for (i = 0; i < inlineDivs.length; i++) {
+ const inlineDivs = document.querySelectorAll('fieldset.module');
+ for (let i = 0; i < inlineDivs.length; i++) {
inlineDivs[i].addEventListener('click', toggleFunc);
}
});
diff --git a/django/contrib/admin/static/admin/js/collapse.min.js b/django/contrib/admin/static/admin/js/collapse.min.js
index 67b2d21335..6041c4b037 100644
--- a/django/contrib/admin/static/admin/js/collapse.min.js
+++ b/django/contrib/admin/static/admin/js/collapse.min.js
@@ -1,2 +1,2 @@
-(function(){window.addEventListener("load",function(){for(var d=document.querySelectorAll("fieldset.collapse"),b=0;b
' + options.addText + "");
addButton = $parent.find("tr:last a");
} else {
@@ -60,10 +60,10 @@
addButton.on('click', addInlineClickHandler);
};
- var addInlineClickHandler = function(e) {
+ const addInlineClickHandler = function(e) {
e.preventDefault();
- var template = $("#" + options.prefix + "-empty");
- var row = template.clone(true);
+ const template = $("#" + options.prefix + "-empty");
+ const row = template.clone(true);
row.removeClass(options.emptyCssClass)
.addClass(options.formCssClass)
.attr("id", options.prefix + "-" + nextIndex);
@@ -94,7 +94,7 @@
* The "X" button that is part of every unsaved inline.
* (When saved, it is replaced with a "Delete" checkbox.)
*/
- var addInlineDeleteButton = function(row) {
+ const addInlineDeleteButton = function(row) {
if (row.is("tr")) {
// If the forms are laid out in table rows, insert
// the remove button into the last table cell:
@@ -112,14 +112,14 @@
row.find("a." + options.deleteCssClass).on('click', inlineDeleteHandler.bind(this));
};
- var inlineDeleteHandler = function(e1) {
+ const inlineDeleteHandler = function(e1) {
e1.preventDefault();
- var deleteButton = $(e1.target);
- var row = deleteButton.closest('.' + options.formCssClass);
- var inlineGroup = row.closest('.inline-group');
+ const deleteButton = $(e1.target);
+ const row = deleteButton.closest('.' + options.formCssClass);
+ const inlineGroup = row.closest('.inline-group');
// Remove the parent form containing this button,
// and also remove the relevant row with non-field errors:
- var prevRow = row.prev();
+ const prevRow = row.prev();
if (prevRow.length && prevRow.hasClass('row-form-errors')) {
prevRow.remove();
}
@@ -131,7 +131,7 @@
}
$(document).trigger('formset:removed', [row, options.prefix]);
// Update the TOTAL_FORMS form count.
- var forms = $("." + options.formCssClass);
+ const forms = $("." + options.formCssClass);
$("#id_" + options.prefix + "-TOTAL_FORMS").val(forms.length);
// Show add button again once below maximum number.
if ((maxForms.val() === '') || (maxForms.val() - forms.length) > 0) {
@@ -141,8 +141,8 @@
toggleDeleteButtonVisibility(inlineGroup);
// Also, update names and ids for all remaining form controls so
// they remain in sequence:
- var i, formCount;
- var updateElementCallback = function() {
+ let i, formCount;
+ const updateElementCallback = function() {
updateElementIndex(this, options.prefix, i);
};
for (i = 0, formCount = forms.length; i < formCount; i++) {
@@ -151,7 +151,7 @@
}
};
- var toggleDeleteButtonVisibility = function(inlineGroup) {
+ const toggleDeleteButtonVisibility = function(inlineGroup) {
if ((minForms.val() !== '') && (minForms.val() - totalForms.val()) >= 0) {
inlineGroup.find('.inline-deletelink').hide();
} else {
@@ -175,7 +175,7 @@
// Show the add button if allowed to add more items.
// Note that max_num = None translates to a blank string.
- var showAddButton = maxForms.val() === '' || (maxForms.val() - totalForms.val()) > 0;
+ const showAddButton = maxForms.val() === '' || (maxForms.val() - totalForms.val()) > 0;
if ($this.length && showAddButton) {
addButton.parent().show();
} else {
@@ -202,9 +202,9 @@
// Tabular inlines ---------------------------------------------------------
$.fn.tabularFormset = function(selector, options) {
- var $rows = $(this);
+ const $rows = $(this);
- var reinitDateTimeShortCuts = function() {
+ const reinitDateTimeShortCuts = function() {
// Reinitialize the calendar and clock widgets by force
if (typeof DateTimeShortcuts !== "undefined") {
$(".datetimeshortcuts").remove();
@@ -212,24 +212,24 @@
}
};
- var updateSelectFilter = function() {
+ const updateSelectFilter = function() {
// If any SelectFilter widgets are a part of the new form,
// instantiate a new SelectFilter instance for it.
if (typeof SelectFilter !== 'undefined') {
$('.selectfilter').each(function(index, value) {
- var namearr = value.name.split('-');
+ const namearr = value.name.split('-');
SelectFilter.init(value.id, namearr[namearr.length - 1], false);
});
$('.selectfilterstacked').each(function(index, value) {
- var namearr = value.name.split('-');
+ const namearr = value.name.split('-');
SelectFilter.init(value.id, namearr[namearr.length - 1], true);
});
}
};
- var initPrepopulatedFields = function(row) {
+ const initPrepopulatedFields = function(row) {
row.find('.prepopulated_field').each(function() {
- var field = $(this),
+ const field = $(this),
input = field.find('input, select, textarea'),
dependency_list = input.data('dependency_list') || [],
dependencies = [];
@@ -262,15 +262,15 @@
// Stacked inlines ---------------------------------------------------------
$.fn.stackedFormset = function(selector, options) {
- var $rows = $(this);
- var updateInlineLabel = function(row) {
+ const $rows = $(this);
+ const updateInlineLabel = function(row) {
$(selector).find(".inline_label").each(function(i) {
- var count = i + 1;
+ const count = i + 1;
$(this).html($(this).html().replace(/(#\d+)/g, "#" + count));
});
};
- var reinitDateTimeShortCuts = function() {
+ const reinitDateTimeShortCuts = function() {
// Reinitialize the calendar and clock widgets by force, yuck.
if (typeof DateTimeShortcuts !== "undefined") {
$(".datetimeshortcuts").remove();
@@ -278,23 +278,23 @@
}
};
- var updateSelectFilter = function() {
+ const updateSelectFilter = function() {
// If any SelectFilter widgets were added, instantiate a new instance.
if (typeof SelectFilter !== "undefined") {
$(".selectfilter").each(function(index, value) {
- var namearr = value.name.split('-');
+ const namearr = value.name.split('-');
SelectFilter.init(value.id, namearr[namearr.length - 1], false);
});
$(".selectfilterstacked").each(function(index, value) {
- var namearr = value.name.split('-');
+ const namearr = value.name.split('-');
SelectFilter.init(value.id, namearr[namearr.length - 1], true);
});
}
};
- var initPrepopulatedFields = function(row) {
+ const initPrepopulatedFields = function(row) {
row.find('.prepopulated_field').each(function() {
- var field = $(this),
+ const field = $(this),
input = field.find('input, select, textarea'),
dependency_list = input.data('dependency_list') || [],
dependencies = [];
@@ -329,9 +329,9 @@
$(document).ready(function() {
$(".js-inline-admin-formset").each(function() {
- var data = $(this).data(),
- inlineOptions = data.inlineFormset,
- selector;
+ const data = $(this).data(),
+ inlineOptions = data.inlineFormset;
+ let selector;
switch(data.inlineType) {
case "stacked":
selector = inlineOptions.name + "-group .inline-related";
diff --git a/django/contrib/admin/static/admin/js/inlines.min.js b/django/contrib/admin/static/admin/js/inlines.min.js
index ba67b03ac8..d8b4bf2a87 100644
--- a/django/contrib/admin/static/admin/js/inlines.min.js
+++ b/django/contrib/admin/static/admin/js/inlines.min.js
@@ -1,11 +1,11 @@
-(function(b){b.fn.formset=function(c){var a=b.extend({},b.fn.formset.defaults,c),e=b(this),l=e.parent(),m=function(a,d,h){var g=new RegExp("("+d+"-(\\d+|__prefix__))");d=d+"-"+h;b(a).prop("for")&&b(a).prop("for",b(a).prop("for").replace(g,d));a.id&&(a.id=a.id.replace(g,d));a.name&&(a.name=a.name.replace(g,d))},f=b("#id_"+a.prefix+"-TOTAL_FORMS").prop("autocomplete","off"),n=parseInt(f.val(),10),h=b("#id_"+a.prefix+"-MAX_NUM_FORMS").prop("autocomplete","off"),q=b("#id_"+a.prefix+"-MIN_NUM_FORMS").prop("autocomplete",
-"off"),t=function(g){g.preventDefault();g=b("#"+a.prefix+"-empty");var d=g.clone(!0);d.removeClass(a.emptyCssClass).addClass(a.formCssClass).attr("id",a.prefix+"-"+n);r(d);d.find("*").each(function(){m(this,a.prefix,f.val())});d.insertBefore(b(g));b(f).val(parseInt(f.val(),10)+1);n+=1;""!==h.val()&&0>=h.val()-f.val()&&k.parent().hide();p(d.closest(".inline-group"));a.added&&a.added(d);b(document).trigger("formset:added",[d,a.prefix])},r=function(b){b.is("tr")?b.children(":last").append('"):b.is("ul")||b.is("ol")?b.append(''+a.deleteText+""):b.children(":first").append(''+a.deleteText+"");b.find("a."+a.deleteCssClass).on("click",u.bind(this))},u=function(g){g.preventDefault();var d=b(g.target).closest("."+a.formCssClass);g=d.closest(".inline-group");var f=d.prev();f.length&&f.hasClass("row-form-errors")&&f.remove();
-d.remove();--n;a.removed&&a.removed(d);b(document).trigger("formset:removed",[d,a.prefix]);d=b("."+a.formCssClass);b("#id_"+a.prefix+"-TOTAL_FORMS").val(d.length);(""===h.val()||0'+a.addText+"");k=l.find("tr:last a")}else e.filter(":last").after('"),k=e.filter(":last").next().find("a");k.on("click",t)})();c=""===h.val()||
-0 tr.form-row",
-b(c).tabularFormset(c,a.options)}})})})(django.jQuery);
+'use strict';(function(b){b.fn.formset=function(c){const a=b.extend({},b.fn.formset.defaults,c),e=b(this),l=e.parent(),m=function(a,d,h){const g=new RegExp("("+d+"-(\\d+|__prefix__))");d=d+"-"+h;b(a).prop("for")&&b(a).prop("for",b(a).prop("for").replace(g,d));a.id&&(a.id=a.id.replace(g,d));a.name&&(a.name=a.name.replace(g,d))},f=b("#id_"+a.prefix+"-TOTAL_FORMS").prop("autocomplete","off");let n=parseInt(f.val(),10);const h=b("#id_"+a.prefix+"-MAX_NUM_FORMS").prop("autocomplete","off"),q=b("#id_"+
+a.prefix+"-MIN_NUM_FORMS").prop("autocomplete","off");let k;const t=function(g){g.preventDefault();g=b("#"+a.prefix+"-empty");const d=g.clone(!0);d.removeClass(a.emptyCssClass).addClass(a.formCssClass).attr("id",a.prefix+"-"+n);r(d);d.find("*").each(function(){m(this,a.prefix,f.val())});d.insertBefore(b(g));b(f).val(parseInt(f.val(),10)+1);n+=1;""!==h.val()&&0>=h.val()-f.val()&&k.parent().hide();p(d.closest(".inline-group"));a.added&&a.added(d);b(document).trigger("formset:added",[d,a.prefix])},r=
+function(b){b.is("tr")?b.children(":last").append('"):b.is("ul")||b.is("ol")?b.append(''+a.deleteText+""):b.children(":first").append(''+a.deleteText+"");b.find("a."+a.deleteCssClass).on("click",u.bind(this))},u=function(g){g.preventDefault();var d=b(g.target).closest("."+a.formCssClass);g=d.closest(".inline-group");
+var f=d.prev();f.length&&f.hasClass("row-form-errors")&&f.remove();d.remove();--n;a.removed&&a.removed(d);b(document).trigger("formset:removed",[d,a.prefix]);d=b("."+a.formCssClass);b("#id_"+a.prefix+"-TOTAL_FORMS").val(d.length);(""===h.val()||0'+a.addText+"");k=l.find("tr:last a")}else e.filter(":last").after('"),
+k=e.filter(":last").next().find("a");k.on("click",t)})();c=""===h.val()||0 tr.form-row",b(c).tabularFormset(c,a.options)}})})})(django.jQuery);
diff --git a/django/contrib/admin/static/admin/js/jquery.init.js b/django/contrib/admin/static/admin/js/jquery.init.js
index f3ac162514..98bbd4a277 100644
--- a/django/contrib/admin/static/admin/js/jquery.init.js
+++ b/django/contrib/admin/static/admin/js/jquery.init.js
@@ -1,8 +1,7 @@
-/*global django:true, jQuery:false*/
+/*global jQuery:false*/
/* Puts the included jQuery into our own namespace using noConflict and passing
* it 'true'. This ensures that the included jQuery doesn't pollute the global
* namespace (i.e. this preserves pre-existing values for both window.$ and
* window.jQuery).
*/
-var django = django || {};
-django.jQuery = jQuery.noConflict(true);
+window.django = {jQuery: jQuery.noConflict(true)};
diff --git a/django/contrib/admin/static/admin/js/popup_response.js b/django/contrib/admin/static/admin/js/popup_response.js
index b4a07e7454..aa46e8f7be 100644
--- a/django/contrib/admin/static/admin/js/popup_response.js
+++ b/django/contrib/admin/static/admin/js/popup_response.js
@@ -1,7 +1,7 @@
/*global opener */
(function() {
'use strict';
- var initData = JSON.parse(document.getElementById('django-admin-popup-response-constants').dataset.popupResponse);
+ const initData = JSON.parse(document.getElementById('django-admin-popup-response-constants').dataset.popupResponse);
switch(initData.action) {
case 'change':
opener.dismissChangeRelatedObjectPopup(window, initData.value, initData.obj, initData.new_value);
diff --git a/django/contrib/admin/static/admin/js/prepopulate.js b/django/contrib/admin/static/admin/js/prepopulate.js
index bef45a3adb..5189501753 100644
--- a/django/contrib/admin/static/admin/js/prepopulate.js
+++ b/django/contrib/admin/static/admin/js/prepopulate.js
@@ -11,15 +11,15 @@
allowUnicode - Unicode support of the URLify'd string
*/
return this.each(function() {
- var prepopulatedField = $(this);
+ const prepopulatedField = $(this);
- var populate = function() {
+ const populate = function() {
// Bail if the field's value has been changed by the user
if (prepopulatedField.data('_changed')) {
return;
}
- var values = [];
+ const values = [];
$.each(dependencies, function(i, field) {
field = $(field);
if (field.val().length > 0) {
diff --git a/django/contrib/admin/static/admin/js/prepopulate.min.js b/django/contrib/admin/static/admin/js/prepopulate.min.js
index 43c1b79e52..fbfe3dd325 100644
--- a/django/contrib/admin/static/admin/js/prepopulate.min.js
+++ b/django/contrib/admin/static/admin/js/prepopulate.min.js
@@ -1 +1 @@
-(function(b){b.fn.prepopulate=function(d,f,g){return this.each(function(){var a=b(this),h=function(){if(!a.data("_changed")){var e=[];b.each(d,function(a,c){c=b(c);0 ');
+ const dateField = $(' ');
$('#qunit-fixture').append(dateField);
DateTimeShortcuts.init();
- var shortcuts = $('.datetimeshortcuts');
+ const shortcuts = $('.datetimeshortcuts');
assert.equal(shortcuts.length, 1);
assert.equal(shortcuts.find('a:first').text(), 'Today');
assert.equal(shortcuts.find('a:last .date-icon').length, 1);
@@ -23,8 +23,8 @@ QUnit.test('init', function(assert) {
});
QUnit.test('custom time shortcuts', function(assert) {
- var $ = django.jQuery;
- var timeField = $('');
+ const $ = django.jQuery;
+ const timeField = $('');
$('#qunit-fixture').append(timeField);
DateTimeShortcuts.clockHours.time_test = [['3 a.m.', 3]];
DateTimeShortcuts.init();
@@ -32,9 +32,9 @@ QUnit.test('custom time shortcuts', function(assert) {
});
QUnit.test('time zone offset warning', function(assert) {
- var $ = django.jQuery;
- var savedOffset = $('body').attr('data-admin-utc-offset');
- var timeField = $('');
+ const $ = django.jQuery;
+ const savedOffset = $('body').attr('data-admin-utc-offset');
+ const timeField = $('');
$('#qunit-fixture').append(timeField);
$('body').attr('data-admin-utc-offset', new Date().getTimezoneOffset() * -60 + 3600);
DateTimeShortcuts.init();
diff --git a/js_tests/admin/SelectBox.test.js b/js_tests/admin/SelectBox.test.js
index bca4941fa6..4f3a27c149 100644
--- a/js_tests/admin/SelectBox.test.js
+++ b/js_tests/admin/SelectBox.test.js
@@ -5,14 +5,14 @@
QUnit.module('admin.SelectBox');
QUnit.test('init: no options', function(assert) {
- var $ = django.jQuery;
+ const $ = django.jQuery;
$('').appendTo('#qunit-fixture');
SelectBox.init('id');
assert.equal(SelectBox.cache.id.length, 0);
});
QUnit.test('filter', function(assert) {
- var $ = django.jQuery;
+ const $ = django.jQuery;
$('').appendTo('#qunit-fixture');
$('').appendTo('#id');
$('').appendTo('#id');
diff --git a/js_tests/admin/SelectFilter2.test.js b/js_tests/admin/SelectFilter2.test.js
index fd0f309a04..3f85e70fe9 100644
--- a/js_tests/admin/SelectFilter2.test.js
+++ b/js_tests/admin/SelectFilter2.test.js
@@ -5,7 +5,7 @@
QUnit.module('admin.SelectFilter2');
QUnit.test('init', function(assert) {
- var $ = django.jQuery;
+ const $ = django.jQuery;
$('').appendTo('#qunit-fixture');
$('').appendTo('#id');
SelectFilter.init('id', 'things', 0);
diff --git a/js_tests/admin/actions.test.js b/js_tests/admin/actions.test.js
index 8d15dbd55e..10c9578dff 100644
--- a/js_tests/admin/actions.test.js
+++ b/js_tests/admin/actions.test.js
@@ -9,7 +9,7 @@ QUnit.module('admin.actions', {
window._actions_icnt = '100';
/* eslint-enable */
- var $ = django.jQuery;
+ const $ = django.jQuery;
$('#qunit-fixture').append($('#result-table').text());
$('tr input.action-select').actions();
@@ -17,7 +17,7 @@ QUnit.module('admin.actions', {
});
QUnit.test('check', function(assert) {
- var $ = django.jQuery;
+ const $ = django.jQuery;
assert.notOk($('.action-select').is(':checked'));
$('#action-toggle').click();
assert.ok($('.action-select').is(':checked'));
diff --git a/js_tests/admin/core.test.js b/js_tests/admin/core.test.js
index ad5b91a903..dea638b779 100644
--- a/js_tests/admin/core.test.js
+++ b/js_tests/admin/core.test.js
@@ -42,7 +42,7 @@ QUnit.test('Date.getTwoDigitSecond', function(assert) {
});
QUnit.test('Date.strftime', function(assert) {
- var date = new Date(2014, 6, 1, 11, 0, 5);
+ const date = new Date(2014, 6, 1, 11, 0, 5);
assert.equal(date.strftime('%Y-%m-%d %H:%M:%S'), '2014-07-01 11:00:05');
assert.equal(date.strftime('%B %d, %Y'), 'July 01, 2014');
});
@@ -50,26 +50,26 @@ QUnit.test('Date.strftime', function(assert) {
QUnit.test('String.strptime', function(assert) {
// Use UTC functions for extracting dates since the calendar uses them as
// well. Month numbering starts with 0 (January).
- var firstParsedDate = '1988-02-26'.strptime('%Y-%m-%d');
+ const firstParsedDate = '1988-02-26'.strptime('%Y-%m-%d');
assert.equal(firstParsedDate.getUTCDate(), 26);
assert.equal(firstParsedDate.getUTCMonth(), 1);
assert.equal(firstParsedDate.getUTCFullYear(), 1988);
// A %y value in the range of [69, 99] is in the previous century.
- var secondParsedDate = '26/02/88'.strptime('%d/%m/%y');
+ const secondParsedDate = '26/02/88'.strptime('%d/%m/%y');
assert.equal(secondParsedDate.getUTCDate(), 26);
assert.equal(secondParsedDate.getUTCMonth(), 1);
assert.equal(secondParsedDate.getUTCFullYear(), 1988);
- var format = django.get_format('DATE_INPUT_FORMATS')[0];
- var thirdParsedDate = '1983-11-20'.strptime(format);
+ const format = django.get_format('DATE_INPUT_FORMATS')[0];
+ const thirdParsedDate = '1983-11-20'.strptime(format);
assert.equal(thirdParsedDate.getUTCDate(), 20);
assert.equal(thirdParsedDate.getUTCMonth(), 10);
assert.equal(thirdParsedDate.getUTCFullYear(), 1983);
// A %y value in the range of [00, 68] is in the current century.
- var fourthParsedDate = '27/09/68'.strptime('%d/%m/%y');
+ const fourthParsedDate = '27/09/68'.strptime('%d/%m/%y');
assert.equal(fourthParsedDate.getUTCDate(), 27);
assert.equal(fourthParsedDate.getUTCMonth(), 8);
assert.equal(fourthParsedDate.getUTCFullYear(), 2068);
@@ -80,10 +80,9 @@ QUnit.test('String.strptime', function(assert) {
// Feb 26, 1988 00:00:00 EEST is Feb 25, 21:00:00 UTC.
// Checking timezones from GMT+0100 to GMT+1200
- var i, tz, date;
- for (i = 1; i <= 12; i++) {
- tz = i > 9 ? '' + i : '0' + i;
- date = new Date(Date.parse('Feb 26, 1988 00:00:00 GMT+' + tz + '00'));
+ for (let i = 1; i <= 12; i++) {
+ const tz = i > 9 ? '' + i : '0' + i;
+ const date = new Date(Date.parse('Feb 26, 1988 00:00:00 GMT+' + tz + '00'));
assert.notEqual(date.getUTCDate(), 26);
assert.equal(date.getUTCDate(), 25);
assert.equal(date.getUTCMonth(), 1);
@@ -91,9 +90,9 @@ QUnit.test('String.strptime', function(assert) {
}
// Checking timezones from GMT+0000 to GMT-1100
- for (i = 0; i <= 11; i++) {
- tz = i > 9 ? '' + i : '0' + i;
- date = new Date(Date.parse('Feb 26, 1988 00:00:00 GMT-' + tz + '00'));
+ for (let i = 0; i <= 11; i++) {
+ const tz = i > 9 ? '' + i : '0' + i;
+ const date = new Date(Date.parse('Feb 26, 1988 00:00:00 GMT-' + tz + '00'));
assert.equal(date.getUTCDate(), 26);
assert.equal(date.getUTCMonth(), 1);
assert.equal(date.getUTCFullYear(), 1988);
diff --git a/js_tests/admin/inlines.test.js b/js_tests/admin/inlines.test.js
index 62a4281190..7c8493742b 100644
--- a/js_tests/admin/inlines.test.js
+++ b/js_tests/admin/inlines.test.js
@@ -4,8 +4,8 @@
QUnit.module('admin.inlines: tabular formsets', {
beforeEach: function() {
- var $ = django.jQuery;
- var that = this;
+ const $ = django.jQuery;
+ const that = this;
this.addText = 'Add another';
$('#qunit-fixture').append($('#tabular-formset').text());
@@ -25,14 +25,14 @@ QUnit.test('no forms', function(assert) {
});
QUnit.test('add form', function(assert) {
- var addButton = this.table.find('.add-row a');
+ const addButton = this.table.find('.add-row a');
assert.equal(addButton.text(), this.addText);
addButton.click();
assert.ok(this.table.find('#first-1'));
});
QUnit.test('added form has remove button', function(assert) {
- var addButton = this.table.find('.add-row a');
+ const addButton = this.table.find('.add-row a');
assert.equal(addButton.text(), this.addText);
addButton.click();
assert.equal(this.table.find('#first-1 .inline-deletelink').length, 1);
@@ -40,9 +40,9 @@ QUnit.test('added form has remove button', function(assert) {
QUnit.test('add/remove form events', function(assert) {
assert.expect(6);
- var $ = django.jQuery;
- var $document = $(document);
- var addButton = this.table.find('.add-row a');
+ const $ = django.jQuery;
+ const $document = $(document);
+ const addButton = this.table.find('.add-row a');
$document.on('formset:added', function(event, $row, formsetName) {
assert.ok(true, 'event `formset:added` triggered');
assert.equal(true, $row.is('#first-1'));
@@ -50,8 +50,8 @@ QUnit.test('add/remove form events', function(assert) {
$document.off('formset:added');
});
addButton.click();
- var deletedRow = $('#first-1');
- var deleteLink = this.table.find('.inline-deletelink');
+ const deletedRow = $('#first-1');
+ const deleteLink = this.table.find('.inline-deletelink');
$document.on('formset:removed', function(event, $row, formsetName) {
assert.ok(true, 'event `formset:removed` triggered');
assert.equal(true, $row.is(deletedRow));
@@ -62,13 +62,13 @@ QUnit.test('add/remove form events', function(assert) {
});
QUnit.test('existing add button', function(assert) {
- var $ = django.jQuery;
+ const $ = django.jQuery;
$('#qunit-fixture').empty(); // Clear the table added in beforeEach
$('#qunit-fixture').append($('#tabular-formset').text());
this.table = $('table.inline');
this.inlineRow = this.table.find('tr');
this.table.append('');
- var addButton = this.table.find('.add-button');
+ const addButton = this.table.find('.add-button');
this.inlineRow.tabularFormset('table.inline tr', {
prefix: 'first',
deleteText: 'Remove',
@@ -82,7 +82,7 @@ QUnit.test('existing add button', function(assert) {
QUnit.module('admin.inlines: tabular formsets with validation errors', {
beforeEach: function() {
- var $ = django.jQuery;
+ const $ = django.jQuery;
$('#qunit-fixture').append($('#tabular-formset-with-validation-error').text());
this.table = $('table.inline');
@@ -94,7 +94,7 @@ QUnit.module('admin.inlines: tabular formsets with validation errors', {
});
QUnit.test('first form has delete checkbox and no button', function(assert) {
- var tr = this.inlineRows.slice(0, 1);
+ const tr = this.inlineRows.slice(0, 1);
assert.ok(tr.hasClass('dynamic-second'));
assert.ok(tr.hasClass('has_original'));
assert.equal(tr.find('td.delete input').length, 1);
@@ -102,14 +102,14 @@ QUnit.test('first form has delete checkbox and no button', function(assert) {
});
QUnit.test('dynamic form has remove button', function(assert) {
- var tr = this.inlineRows.slice(1, 2);
+ const tr = this.inlineRows.slice(1, 2);
assert.ok(tr.hasClass('dynamic-second'));
assert.notOk(tr.hasClass('has_original'));
assert.equal(tr.find('.inline-deletelink').length, 1);
});
QUnit.test('dynamic template has nothing', function(assert) {
- var tr = this.inlineRows.slice(2, 3);
+ const tr = this.inlineRows.slice(2, 3);
assert.ok(tr.hasClass('empty-form'));
assert.notOk(tr.hasClass('dynamic-second'));
assert.notOk(tr.hasClass('has_original'));
@@ -117,19 +117,19 @@ QUnit.test('dynamic template has nothing', function(assert) {
});
QUnit.test('removing a form-row also removed related row with non-field errors', function(assert) {
- var $ = django.jQuery;
+ const $ = django.jQuery;
assert.ok(this.table.find('.row-form-errors').length);
- var tr = this.inlineRows.slice(1, 2);
- var trWithErrors = tr.prev();
+ const tr = this.inlineRows.slice(1, 2);
+ const trWithErrors = tr.prev();
assert.ok(trWithErrors.hasClass('row-form-errors'));
- var deleteLink = tr.find('a.inline-deletelink');
+ const deleteLink = tr.find('a.inline-deletelink');
deleteLink.trigger($.Event('click', {target: deleteLink}));
assert.notOk(this.table.find('.row-form-errors').length);
});
QUnit.module('admin.inlines: tabular formsets with max_num', {
beforeEach: function() {
- var $ = django.jQuery;
+ const $ = django.jQuery;
$('#qunit-fixture').append($('#tabular-formset-with-validation-error').text());
this.table = $('table.inline');
this.maxNum = $('input.id_second-MAX_NUM_FORMS');
@@ -142,14 +142,14 @@ QUnit.module('admin.inlines: tabular formsets with max_num', {
});
QUnit.test('does not show the add button if already at max_num', function(assert) {
- var addButton = this.table.find('tr.add_row > td > a');
+ const addButton = this.table.find('tr.add_row > td > a');
assert.notOk(addButton.is(':visible'));
});
QUnit.test('make addButton visible again', function(assert) {
- var $ = django.jQuery;
- var addButton = this.table.find('tr.add_row > td > a');
- var removeButton = this.table.find('tr.form-row:first').find('a.inline-deletelink');
+ const $ = django.jQuery;
+ const addButton = this.table.find('tr.add_row > td > a');
+ const removeButton = this.table.find('tr.form-row:first').find('a.inline-deletelink');
removeButton.trigger($.Event( "click", { target: removeButton } ));
assert.notOk(addButton.is(':visible'));
});
@@ -157,7 +157,7 @@ QUnit.test('make addButton visible again', function(assert) {
QUnit.module('admin.inlines: tabular formsets with min_num', {
beforeEach: function() {
- var $ = django.jQuery;
+ const $ = django.jQuery;
$('#qunit-fixture').append($('#tabular-formset-with-validation-error').text());
this.table = $('table.inline');
this.minNum = $('input#id_second-MIN_NUM_FORMS');
@@ -174,8 +174,8 @@ QUnit.test('does not show the remove buttons if already at min_num', function(as
});
QUnit.test('make removeButtons visible again', function(assert) {
- var $ = django.jQuery;
- var addButton = this.table.find('tr.add-row > td > a');
+ const $ = django.jQuery;
+ const addButton = this.table.find('tr.add-row > td > a');
addButton.trigger($.Event( "click", { target: addButton } ));
assert.equal(this.table.find('.inline-deletelink:visible').length, 2);
});
diff --git a/js_tests/admin/jsi18n-mocks.test.js b/js_tests/admin/jsi18n-mocks.test.js
index f04b0576f6..13d5b0e33c 100644
--- a/js_tests/admin/jsi18n-mocks.test.js
+++ b/js_tests/admin/jsi18n-mocks.test.js
@@ -1,6 +1,6 @@
(function(globals) {
'use strict';
- var django = globals.django || (globals.django = {});
+ const django = globals.django;
django.pluralidx = function(count) { return (count === 1) ? 0 : 1; };
@@ -69,7 +69,7 @@
};
django.get_format = function(format_type) {
- var value = django.formats[format_type];
+ const value = django.formats[format_type];
if (typeof value === 'undefined') {
return format_type;
} else {
diff --git a/js_tests/gis/mapwidget.test.js b/js_tests/gis/mapwidget.test.js
index 4198cbf2b6..d9b3fe2576 100644
--- a/js_tests/gis/mapwidget.test.js
+++ b/js_tests/gis/mapwidget.test.js
@@ -5,8 +5,8 @@
QUnit.module('gis.OLMapWidget');
QUnit.test('MapWidget.featureAdded', function(assert) {
- var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
- var widget = new MapWidget(options);
+ const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
+ const widget = new MapWidget(options);
assert.equal(widget.featureCollection.getLength(), 1);
widget.serializeFeatures();
assert.equal(
@@ -17,14 +17,14 @@ QUnit.test('MapWidget.featureAdded', function(assert) {
});
QUnit.test('MapWidget.map_srid', function(assert) {
- var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
- var widget = new MapWidget(options);
+ const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
+ const widget = new MapWidget(options);
assert.equal(widget.map.getView().getProjection().getCode(), 'EPSG:3857', 'SRID 3857');
});
QUnit.test('MapWidget.defaultCenter', function(assert) {
- var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
- var widget = new MapWidget(options);
+ const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
+ let widget = new MapWidget(options);
assert.equal(widget.defaultCenter().toString(), '0,0', 'Default center at 0, 0');
options.default_lat = 47.08;
options.default_lon = 6.81;
@@ -38,32 +38,32 @@ QUnit.test('MapWidget.defaultCenter', function(assert) {
});
QUnit.test('MapWidget.interactions', function(assert) {
- var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
- var widget = new MapWidget(options);
+ const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
+ const widget = new MapWidget(options);
assert.equal(Object.keys(widget.interactions).length, 2);
assert.equal(widget.interactions.draw.getActive(), false, "Draw is inactive with an existing point");
assert.equal(widget.interactions.modify.getActive(), true, "Modify is active with an existing point");
});
QUnit.test('MapWidget.clearFeatures', function(assert) {
- var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
- var widget = new MapWidget(options);
- var initial_value = document.getElementById('id_point').value;
+ const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
+ const widget = new MapWidget(options);
+ const initial_value = document.getElementById('id_point').value;
widget.clearFeatures();
assert.equal(document.getElementById('id_point').value, "");
document.getElementById('id_point').value = initial_value;
});
QUnit.test('MapWidget.multipolygon', function(assert) {
- var options = {id: 'id_multipolygon', map_id: 'id_multipolygon_map', geom_name: 'MultiPolygon'};
- var widget = new MapWidget(options);
+ const options = {id: 'id_multipolygon', map_id: 'id_multipolygon_map', geom_name: 'MultiPolygon'};
+ const widget = new MapWidget(options);
assert.ok(widget.options.is_collection);
assert.equal(widget.interactions.draw.getActive(), true, "Draw is active with no existing content");
});
QUnit.test('MapWidget.IsCollection', function(assert) {
- var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
- var widget = new MapWidget(options);
+ const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
+ let widget = new MapWidget(options);
assert.notOk(widget.options.is_collection);
// Empty the default initial Point
document.getElementById('id_point').value = "";
| | |