Skip to content

Commit

Permalink
Replace attr with getAttribute and setAttribute
Browse files Browse the repository at this point in the history
This replaces jQuery's `attr` function with the vanilla JavaScript
`getAttribute` and `setAttribute`.
  • Loading branch information
p8 committed Feb 21, 2023
1 parent 9241762 commit 8d399fe
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/js/select2/dropdown/search.js
Expand Up @@ -91,7 +91,8 @@ define([

container.on('results:focus', function (params) {
if (params.data._resultId) {
self.$search[0].setAttribute('aria-activedescendant', params.data._resultId);
self.$search[0]
.setAttribute('aria-activedescendant', params.data._resultId);
} else {
self.$search.removeAttr('aria-activedescendant');
}
Expand Down
2 changes: 1 addition & 1 deletion src/js/select2/selection/allowClear.js
Expand Up @@ -100,7 +100,7 @@ define([
return;
}

var rendered = this.$selection.find('.select2-selection__rendered')[0]
var rendered = this.$selection.find('.select2-selection__rendered')[0];
var selectionId = null;
if(rendered != null) {
selectionId = rendered.getAttribute('id');
Expand Down
6 changes: 4 additions & 2 deletions src/js/select2/selection/base.js
Expand Up @@ -28,7 +28,8 @@ define([
}

if(this.$element[0].getAttribute('title')) {
$selection[0].setAttribute('title', this.$element[0].getAttribute('title'))
$selection[0]
.setAttribute('title', this.$element[0].getAttribute('title'));
}
$selection[0].setAttribute('tabindex', this._tabindex);
$selection[0].setAttribute('aria-disabled', 'false');
Expand Down Expand Up @@ -62,7 +63,8 @@ define([
});

container.on('results:focus', function (params) {
self.$selection[0].setAttribute('aria-activedescendant', params.data._resultId);
self.$selection[0]
.setAttribute('aria-activedescendant', params.data._resultId);
});

container.on('selection:update', function (params) {
Expand Down
6 changes: 4 additions & 2 deletions src/js/select2/selection/multiple.js
Expand Up @@ -27,7 +27,8 @@ define([
MultipleSelection.__super__.bind.apply(this, arguments);

var id = container.id + '-container';
var rendered = this.$selection.find('.select2-selection__rendered')[0]

var rendered = this.$selection.find('.select2-selection__rendered')[0];
if(rendered != null) {
rendered.setAttribute('id', id);
}
Expand Down Expand Up @@ -109,7 +110,8 @@ define([

var $selections = [];

var selectionIdPrefix = this.$selection.find('.select2-selection__rendered')[0]
var selectionIdPrefix = this.$selection
.find('.select2-selection__rendered')[0]
.getAttribute('id') + '-choice-';

for (var d = 0; d < data.length; d++) {
Expand Down
6 changes: 4 additions & 2 deletions src/js/select2/selection/search.js
Expand Up @@ -72,7 +72,8 @@ define([

container.on('results:focus', function (params) {
if (params.data._resultId) {
self.$search[0].setAttribute('aria-activedescendant', params.data._resultId);
self.$search[0]
.setAttribute('aria-activedescendant', params.data._resultId);
} else {
self.$search.removeAttr('aria-activedescendant');
}
Expand Down Expand Up @@ -180,7 +181,8 @@ define([
* @private
*/
Search.prototype._transferTabIndex = function (decorated) {
this.$search[0].setAttribute('tabindex', this.$selection[0].getAttribute('tabindex'));
this.$search[0]
.setAttribute('tabindex', this.$selection[0].getAttribute('tabindex'));
this.$selection[0].setAttribute('tabindex', '-1');
};

Expand Down
2 changes: 1 addition & 1 deletion src/js/select2/selection/single.js
Expand Up @@ -32,7 +32,7 @@ define([

var id = container.id + '-container';

var rendered = this.$selection.find('.select2-selection__rendered')[0]
var rendered = this.$selection.find('.select2-selection__rendered')[0];
if(rendered != null) {
rendered.setAttribute('id', id);
rendered.setAttribute('role', 'textbox');
Expand Down

0 comments on commit 8d399fe

Please sign in to comment.