Skip to content

Commit

Permalink
Upgrade to Baseline2024 compliant JS code (#307)
Browse files Browse the repository at this point in the history
Run `styleling --fix`.
  • Loading branch information
codingjoe authored Dec 10, 2024
1 parent 352811b commit 94c70dc
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions django_select2/static/django_select2/django_select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
}
}(function ($) {
'use strict'
var init = function ($element, options) {
const init = function ($element, options) {
$element.select2(options)
}

var initHeavy = function ($element, options) {
var settings = $.extend({
const initHeavy = function ($element, options) {
const settings = $.extend({
ajax: {
data: function (params) {
var result = {
const result = {
term: params.term,
page: params.page,
field_id: $element.data('field_id')
}

var dependentFields = $element.data('select2-dependent-fields')
let dependentFields = $element.data('select2-dependent-fields')
if (dependentFields) {
dependentFields = dependentFields.trim().split(/\s+/)
$.each(dependentFields, function (i, dependentField) {
Expand All @@ -49,16 +49,16 @@
}

$.fn.djangoSelect2 = function (options) {
var settings = $.extend({}, options)
const settings = $.extend({}, options)
$.each(this, function (i, element) {
var $element = $(element)
const $element = $(element)
if ($element.hasClass('django-select2-heavy')) {
initHeavy($element, settings)
} else {
init($element, settings)
}
$element.on('select2:select', function (e) {
var name = $(e.currentTarget).attr('name')
const name = $(e.currentTarget).attr('name')
$('[data-select2-dependent-fields~=' + name + ']').each(function () {
$(this).val('').trigger('change')
})
Expand All @@ -71,7 +71,7 @@
$('.django-select2').not('[name*=__prefix__]').djangoSelect2()

document.addEventListener('formset:added', (event) => {
$(event.target).find('.django-select2').djangoSelect2()
$(event.target).find('.django-select2').djangoSelect2()
})
})

Expand Down

0 comments on commit 94c70dc

Please sign in to comment.