Skip to content

Commit 900dd79

Browse files
authored
Remove jQuery .attr from the common global functions (#30023)
- Switched from jQuery `.attr` to plain javascript `getAttribute` - Tested the show/hide modal buttons, they work as before Signed-off-by: Yarden Shoham <[email protected]>
1 parent 75e2e5c commit 900dd79

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

web_src/js/features/common-global.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ export function initGlobalLinkActions() {
301301
const $this = $(this);
302302
const dataArray = $this.data();
303303
let filter = '';
304-
if ($this.attr('data-modal-id')) {
305-
filter += `#${$this.attr('data-modal-id')}`;
304+
if (this.getAttribute('data-modal-id')) {
305+
filter += `#${this.getAttribute('data-modal-id')}`;
306306
}
307307

308308
const $dialog = $(`.delete.modal${filter}`);
@@ -352,8 +352,7 @@ function initGlobalShowModal() {
352352
// If there is a ".{attr}" part like "data-modal-form.action", then the form's "action" attribute will be set.
353353
$('.show-modal').on('click', function (e) {
354354
e.preventDefault();
355-
const $el = $(this);
356-
const modalSelector = $el.attr('data-modal');
355+
const modalSelector = this.getAttribute('data-modal');
357356
const $modal = $(modalSelector);
358357
if (!$modal.length) {
359358
throw new Error('no modal for this action');
@@ -406,7 +405,7 @@ export function initGlobalButtons() {
406405
// a '.show-panel' element can show a panel, by `data-panel="selector"`
407406
// if it has "toggle" class, it toggles the panel
408407
e.preventDefault();
409-
const sel = $(this).attr('data-panel');
408+
const sel = this.getAttribute('data-panel');
410409
if (this.classList.contains('toggle')) {
411410
toggleElem(sel);
412411
} else {
@@ -417,12 +416,12 @@ export function initGlobalButtons() {
417416
$('.hide-panel').on('click', function (e) {
418417
// a `.hide-panel` element can hide a panel, by `data-panel="selector"` or `data-panel-closest="selector"`
419418
e.preventDefault();
420-
let sel = $(this).attr('data-panel');
419+
let sel = this.getAttribute('data-panel');
421420
if (sel) {
422421
hideElem($(sel));
423422
return;
424423
}
425-
sel = $(this).attr('data-panel-closest');
424+
sel = this.getAttribute('data-panel-closest');
426425
if (sel) {
427426
hideElem($(this).closest(sel));
428427
return;

0 commit comments

Comments
 (0)