Skip to content

Commit a0a3778

Browse files
committed
Add esupgrade pre-commit hook
1 parent a237571 commit a0a3778

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ repos:
4343
rev: v1.0.2
4444
hooks:
4545
- id: sphinx-lint
46+
- repo: https://github.com/codingjoe/esupgrade
47+
rev: 2025.8.0
48+
hooks:
49+
- id: esupgrade
4650
ci:
4751
autoupdate_schedule: weekly
4852
skip:

django_select2/static/django_select2/django_select2.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
/* global define, jQuery */
2-
(function (factory) {
2+
((factory => {
33
if (typeof define === 'function' && define.amd) {
44
define(['jquery'], factory)
55
} else if (typeof module === 'object' && module.exports) {
66
module.exports = factory(require('jquery'))
77
} else {
88
// Browser globals - prefer Django's jQuery to avoid conflicts
9-
factory(window.django?.jQuery || jQuery)
9+
factory(globalThis.django?.jQuery || jQuery)
1010
}
11-
}(function ($) {
11+
})($ => {
1212
'use strict'
13-
const init = function ($element, options) {
13+
const init = ($element, options) => {
1414
$element.select2(options)
1515
}
1616

17-
const initHeavy = function ($element, options) {
17+
function initHeavy ($element, options) {
1818
const settings = $.extend({
1919
ajax: {
20-
data: function (params) {
20+
data: params => {
2121
const result = {
2222
term: params.term,
2323
page: params.page,
@@ -26,13 +26,13 @@
2626

2727
let dependentFields = $element.data('select2-dependent-fields')
2828
if (dependentFields) {
29-
const findElement = function (selector) {
29+
function findElement (selector) {
3030
const result = $(selector, $element.closest(`:has(${selector})`))
3131
if (result.length > 0) return result
3232
else return null
3333
}
3434
dependentFields = dependentFields.trim().split(/\s+/)
35-
$.each(dependentFields, function (i, dependentField) {
35+
$.each(dependentFields, (i, dependentField) => {
3636
const nameIs = `[name=${dependentField}]`
3737
const nameEndsWith = `[name$=-${dependentField}]`
3838
result[dependentField] = (findElement(nameIs) || findElement(nameEndsWith)).val()
@@ -41,7 +41,7 @@
4141

4242
return result
4343
},
44-
processResults: function (data, page) {
44+
processResults: (data, page) => {
4545
return {
4646
results: data.results,
4747
pagination: {
@@ -57,24 +57,24 @@
5757

5858
$.fn.djangoSelect2 = function (options) {
5959
const settings = $.extend({}, options)
60-
$.each(this, function (i, element) {
60+
$.each(this, (i, element) => {
6161
const $element = $(element)
6262
if ($element.hasClass('django-select2-heavy')) {
6363
initHeavy($element, settings)
6464
} else {
6565
init($element, settings)
6666
}
67-
$element.on('select2:select', function (e) {
67+
$element.on('select2:select', e => {
6868
const name = $(e.currentTarget).attr('name')
69-
$('[data-select2-dependent-fields~=' + name + ']').each(function () {
69+
$(`[data-select2-dependent-fields~=${name}]`).each(function () {
7070
$(this).val('').trigger('change')
7171
})
7272
})
7373
})
7474
return this
7575
}
7676

77-
$(function () {
77+
$(() => {
7878
$('.django-select2').not('[name*=__prefix__]').djangoSelect2()
7979

8080
document.addEventListener('formset:added', (event) => {

0 commit comments

Comments
 (0)