Skip to content

Commit 8ebb250

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 7997b86 commit 8ebb250

File tree

12 files changed

+136
-148
lines changed

12 files changed

+136
-148
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ repos:
4343
- repo: https://github.com/codingjoe/esupgrade
4444
rev: 2025.3.1
4545
hooks:
46-
- id: esupgrade
47-
exclude: '(^djangoproject\/static\/js\/lib\/.*$)'
46+
- id: esupgrade
47+
exclude: '(^djangoproject\/static\/js\/lib\/.*$)'
4848

4949
- repo: https://github.com/psf/black-pre-commit-mirror
5050
rev: 25.12.0
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
document.addEventListener('DOMContentLoaded', function () {
2-
document
3-
.querySelectorAll('button[data-clipboard-content]')
4-
.forEach(function (el) {
5-
el.addEventListener('click', function (e) {
6-
// Copy to clipboard and flash the button for a second
7-
navigator.clipboard.writeText(el.dataset.clipboardContent);
8-
el.style.backgroundColor = 'rebeccapurple';
9-
el.style.color = 'white';
10-
window.setTimeout(function () {
11-
el.style.backgroundColor = '';
12-
el.style.color = '';
13-
}, 1000);
14-
});
1+
document.addEventListener('DOMContentLoaded', () => {
2+
for (const el of document.querySelectorAll(
3+
'button[data-clipboard-content]',
4+
)) {
5+
el.addEventListener('click', (e) => {
6+
// Copy to clipboard and flash the button for a second
7+
navigator.clipboard.writeText(el.dataset.clipboardContent);
8+
el.style.backgroundColor = 'rebeccapurple';
9+
el.style.color = 'white';
10+
window.setTimeout(() => {
11+
el.style.backgroundColor = '';
12+
el.style.color = '';
13+
}, 1000);
1514
});
15+
}
1616
});

djangoproject/static/js/dashboard/detail.js

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
$(function () {
2-
var element = $('#graph');
3-
var url = element.data('path') + element.data('metric') + '.json?days=365';
4-
var hover = {
5-
show: function (x, y, message) {
1+
$(() => {
2+
const element = $('#graph');
3+
const url = `${element.data('path') + element.data('metric')}.json?days=365`;
4+
const hover = {
5+
show: (x, y, message) => {
66
$('<div id="hover">')
77
.html(message)
88
.css({ top: y, left: x })
99
.appendTo('body')
1010
.show();
1111
},
12-
hide: function () {
12+
hide: () => {
1313
$('#hover').remove();
1414
},
1515
};
1616

17-
$.getJSON(url, function (response) {
18-
for (var i = 0; i < response.data.length; i++) {
17+
$.getJSON(url, (response) => {
18+
for (const i = 0; i < response.data.length; i++) {
1919
response.data[i][0] = response.data[i][0] * 1000;
2020
}
21-
var options = {
21+
const options = {
2222
xaxis: {
2323
mode: 'time',
2424
tickColor: 'rgba(0,0,0,0)',
@@ -41,27 +41,21 @@ $(function () {
4141
align: 'center',
4242
};
4343
}
44-
var plot = $.plot(element, [response.data], options);
44+
const plot = $.plot(element, [response.data], options);
4545

46-
var format_message = function (timestamp, measurement) {
47-
var unit = measurement == 1 ? response.unit : response.unit_plural;
48-
return (
49-
formatTimestamp(timestamp, response.period) +
50-
'<br>' +
51-
measurement +
52-
' ' +
53-
unit
54-
);
46+
const format_message = (timestamp, measurement) => {
47+
const unit = measurement == 1 ? response.unit : response.unit_plural;
48+
return `${formatTimestamp(timestamp, response.period)}<br>${measurement} ${unit}`;
5549
};
5650

57-
var previousPoint = null;
58-
element.bind('plothover', function (event, pos, item) {
51+
const previousPoint = null;
52+
element.bind('plothover', (event, pos, item) => {
5953
if (item) {
6054
if (previousPoint != item.dataIndex) {
6155
previousPoint = item.dataIndex;
6256
hover.hide();
63-
var x, y;
64-
var message = format_message.apply(null, item.datapoint);
57+
const x, y;
58+
const message = format_message.apply(null, item.datapoint);
6559
if (response.period == 'instant') {
6660
x = item.pageX + 10;
6761
y = item.pageY + 10;

djangoproject/static/js/dashboard/index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
$(function () {
2-
$('.metric .sparkline').each(function (index, elem) {
3-
var element = $(elem);
4-
var valueElement = element.parent().find('.value a');
5-
var timestampElement = element.parent().find('.timestamp');
6-
var originalValue = valueElement.html();
7-
var green = '#93D7B7';
1+
$(() => {
2+
$('.metric .sparkline').each((index, elem) => {
3+
const element = $(elem);
4+
const valueElement = element.parent().find('.value a');
5+
const timestampElement = element.parent().find('.timestamp');
6+
const originalValue = valueElement.html();
7+
const green = '#93D7B7';
88

9-
var url = element.data('path') + element.data('metric') + '.json';
10-
$.getJSON(url, function (response) {
9+
const url = `${element.data('path') + element.data('metric')}.json`;
10+
$.getJSON(url, (response) => {
1111
response.data = convertSecondsToMilliseconds(response.data);
1212
$.plot(element, [response.data], {
1313
xaxis: { show: false, mode: 'time' },
@@ -26,7 +26,7 @@ $(function () {
2626
},
2727
});
2828

29-
element.bind('plothover', function (event, pos, item) {
29+
element.bind('plothover', (event, pos, item) => {
3030
if (item) {
3131
valueElement.html(item.datapoint[1]);
3232
timestampElement.html(

djangoproject/static/js/dashboard/utils.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function formatTimestamp(timestamp, period) {
2-
var d = new Date(timestamp);
2+
const d = new Date(timestamp);
33
if (period == 'instant') {
44
return $.plot.formatDate(d, '%b %d, %h:%M %p');
55
} else if (period == 'daily') {
@@ -8,18 +8,14 @@ function formatTimestamp(timestamp, period) {
88
// A bit more complicated than the above: the timestamp is in the
99
// middle of the week, so we have to bracket the date. This is
1010
// something of a fudge here, but it works well enough.
11-
var start = new Date(d.getTime() - 3 * 24 * 60 * 60 * 1000);
12-
var end = new Date(d.getTime() + 3 * 24 * 60 * 60 * 1000);
13-
return (
14-
$.plot.formatDate(start, '%b %d') +
15-
' - ' +
16-
$.plot.formatDate(end, '%b %d')
17-
);
11+
const start = new Date(d.getTime() - 3 * 24 * 60 * 60 * 1000);
12+
const end = new Date(d.getTime() + 3 * 24 * 60 * 60 * 1000);
13+
return `${$.plot.formatDate(start, '%b %d')} - ${$.plot.formatDate(end, '%b %d')}`;
1814
}
1915
}
2016

2117
function convertSecondsToMilliseconds(data) {
22-
for (var i = 0; i < data.length; i++) {
18+
for (const i = 0; i < data.length; i++) {
2319
data[i][0] = data[i][0] * 1000;
2420
}
2521
return data;

djangoproject/static/js/djangoproject.js

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,41 @@
1-
// Toggle persistent display of documentation version and language options
2-
document.querySelectorAll('.doc-switcher li.current').forEach(function (el) {
1+
for (const el of document.querySelectorAll('.doc-switcher li.current')) {
32
el.addEventListener('click', function () {
43
this.parentElement.classList.toggle('open');
54
});
6-
});
5+
}
76

8-
// Propagate the current fragment identifier when switching docs versions
9-
document.querySelectorAll('#doc-versions a').forEach(function (el) {
7+
for (const el of document.querySelectorAll('#doc-versions a')) {
108
el.addEventListener('click', function () {
119
this.href = this.href.split('#')[0] + window.location.hash;
1210
});
13-
});
11+
}
1412

15-
// Fade out and remove message elements when close icon is clicked
16-
document.querySelectorAll('.messages li .close').forEach(function (el) {
13+
for (const el of document.querySelectorAll('.messages li .close')) {
1714
el.addEventListener('click', function () {
1815
this.parentElement.addEventListener('transitionend', function () {
1916
this.style.display = 'none';
2017
});
2118

2219
this.parentElement.classList.add('fade-out');
2320
});
24-
});
21+
}
2522

26-
// Check all console tab inputs of the same type when one's label is clicked
27-
document.querySelectorAll('.console-block label').forEach(function (el) {
28-
el.addEventListener('click', function (e) {
23+
for (const el of document.querySelectorAll('.console-block label')) {
24+
el.addEventListener('click', (e) => {
2925
const input_id = e.currentTarget.getAttribute('for');
3026
const selector = input_id.endsWith('unix') ? '.c-tab-unix' : '.c-tab-win';
3127

32-
document.querySelectorAll(selector).forEach(function (input_el) {
28+
for (const input_el of document.querySelectorAll(selector)) {
3329
input_el.checked = true;
34-
});
30+
}
3531
});
36-
});
32+
}
3733

3834
// Add animation class to feature icons when they are fully visible
39-
(function () {
35+
(() => {
4036
const observer = new IntersectionObserver(
41-
function (entries) {
42-
entries.forEach(function (entry) {
37+
(entries) => {
38+
entries.forEach((entry) => {
4339
if (!entry.isIntersecting) {
4440
return;
4541
}
@@ -52,9 +48,9 @@ document.querySelectorAll('.console-block label').forEach(function (el) {
5248
{ threshold: 1.0 },
5349
);
5450

55-
document.querySelectorAll('.list-features i').forEach(function (el) {
51+
for (const el of document.querySelectorAll('.list-features i')) {
5652
observer.observe(el);
57-
});
53+
}
5854
})();
5955

6056
// Toggle mobile menu on button click
@@ -66,7 +62,7 @@ document.querySelector('.menu-button').addEventListener('click', function () {
6662
});
6763

6864
// Update search input placeholder text based on the user's operating system
69-
(function () {
65+
(() => {
7066
const el = document.getElementById('id_q');
7167

7268
if (!el) {
@@ -81,7 +77,7 @@ document.querySelector('.menu-button').addEventListener('click', function () {
8177
})();
8278

8379
// Focus, select, and scroll to search input when key combination is pressed
84-
window.addEventListener('keydown', function (e) {
80+
window.addEventListener('keydown', (e) => {
8581
const is_ctrl_k = (e.metaKey || e.ctrlKey) && e.key === 'k';
8682

8783
if (!(is_ctrl_k || e.key === '/')) {
@@ -103,7 +99,7 @@ window.addEventListener('keydown', function (e) {
10399
});
104100

105101
// Add copy buttons to code snippets
106-
(function () {
102+
(() => {
107103
const button_el = document.createElement('span');
108104

109105
button_el.classList.add('btn-clipboard');
@@ -112,13 +108,12 @@ window.addEventListener('keydown', function (e) {
112108

113109
const selector = '.snippet-filename, .code-block-caption';
114110

115-
document.querySelectorAll(selector).forEach(function (el) {
111+
for (const el of document.querySelectorAll(selector)) {
116112
el.insertBefore(button_el.cloneNode(true), null);
117-
});
113+
}
118114
})();
119115

120-
// Attach copy functionality to dynamically-created buttons
121-
document.querySelectorAll('.btn-clipboard').forEach(function (el) {
116+
for (const el of document.querySelectorAll('.btn-clipboard')) {
122117
el.addEventListener('click', function () {
123118
const success_el = document.createElement('span');
124119

@@ -133,15 +128,15 @@ document.querySelectorAll('.btn-clipboard').forEach(function (el) {
133128
function on_success(el) {
134129
success_el.innerText = 'Copied!';
135130

136-
setTimeout(function () {
131+
setTimeout(() => {
137132
success_el.classList.add('fade-out');
138133
}, 1000);
139134
}
140135

141136
function on_error(el) {
142137
success_el.innerText = 'Could not copy!';
143138

144-
setTimeout(function () {
139+
setTimeout(() => {
145140
success_el.classList.add('fade-out');
146141
}, 5000);
147142
}
@@ -150,10 +145,10 @@ document.querySelectorAll('.btn-clipboard').forEach(function (el) {
150145

151146
navigator.clipboard.writeText(text).then(on_success, on_error);
152147
});
153-
});
148+
}
154149

155150
// Compensate for floating warning element when scrolling to a URL hash in docs
156-
(function () {
151+
(() => {
157152
const warning_el = document.querySelector('.doc-floating-warning');
158153

159154
if (!warning_el) {
@@ -186,7 +181,7 @@ document.querySelectorAll('.btn-clipboard').forEach(function (el) {
186181
})();
187182

188183
// Update donate button text on fundraising page based on interval selection
189-
(function () {
184+
(() => {
190185
const el = document.querySelector('#donate #id_interval');
191186

192187
if (!el) {
@@ -201,7 +196,7 @@ document.querySelectorAll('.btn-clipboard').forEach(function (el) {
201196
})();
202197

203198
// Manage custom donation amount input on fundraising page
204-
(function () {
199+
(() => {
205200
const el = document.querySelector('#donate #id_amount');
206201

207202
if (!el) {
@@ -231,7 +226,7 @@ document.querySelectorAll('.btn-clipboard').forEach(function (el) {
231226
})();
232227

233228
// Manage amount and membership level fields on corporate membership page
234-
(function () {
229+
(() => {
235230
const form_el = document.querySelector('.corporate-membership-join-form');
236231

237232
if (!form_el) {

0 commit comments

Comments
 (0)