Fixed #31028 -- Used classList API to check, add and remove DOM classes.

Thanks to Claude Paroz for review.
This commit is contained in:
Jon Dufresne 2019-11-28 06:21:37 -08:00 committed by Carlton Gibson
parent c8bd37a860
commit 46a0edc3ba
4 changed files with 10 additions and 11 deletions

View File

@ -26,10 +26,10 @@ Requires jQuery, core.js, and SelectBox.js.
var ps = from_box.parentNode.getElementsByTagName('p');
for (var i = 0; i < ps.length; i++) {
if (ps[i].className.indexOf("info") !== -1) {
if (ps[i].classList.contains("info")) {
// Remove <p class="info">, because it just gets in the way.
from_box.parentNode.removeChild(ps[i]);
} else if (ps[i].className.indexOf("help") !== -1) {
} else if (ps[i].classList.contains("help")) {
// Move help text up to the top so it isn't below the select
// boxes or wrapped off on the side to the right of the add
// button:
@ -112,7 +112,7 @@ Requires jQuery, core.js, and SelectBox.js.
// Set up the JavaScript event handlers for the select box filter interface
var move_selection = function(e, elem, move_func, from, to) {
if (elem.className.indexOf('active') !== -1) {
if (elem.classList.contains('active')) {
move_func(from, to);
SelectFilter.refresh_icons(field_id);
}

View File

@ -38,11 +38,11 @@
var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
var inp = inputs[i];
if (inp.type === 'text' && inp.className.match(/vTimeField/)) {
if (inp.type === 'text' && inp.classList.contains('vTimeField')) {
DateTimeShortcuts.addClock(inp);
DateTimeShortcuts.addTimezoneWarning(inp);
}
else if (inp.type === 'text' && inp.className.match(/vDateField/)) {
else if (inp.type === 'text' && inp.classList.contains('vDateField')) {
DateTimeShortcuts.addCalendar(inp);
DateTimeShortcuts.addTimezoneWarning(inp);
}

View File

@ -44,7 +44,7 @@
function dismissRelatedLookupPopup(win, chosenId) {
var name = windowname_to_id(win.name);
var elem = document.getElementById(name);
if (elem.className.indexOf('vManyToManyRawIdAdminField') !== -1 && elem.value) {
if (elem.classList.contains('vManyToManyRawIdAdminField') && elem.value) {
elem.value += ',' + chosenId;
} else {
document.getElementById(name).value = chosenId;
@ -81,7 +81,7 @@
if (elemName === 'SELECT') {
elem.options[elem.options.length] = new Option(newRepr, newId, true, true);
} else if (elemName === 'INPUT') {
if (elem.className.indexOf('vManyToManyRawIdAdminField') !== -1 && elem.value) {
if (elem.classList.contains('vManyToManyRawIdAdminField') && elem.value) {
elem.value += ',' + newId;
} else {
elem.value = newId;

View File

@ -8,7 +8,7 @@ var GeometryTypeControl = function(opt_options) {
var element = document.createElement('div');
element.className = 'switch-type type-' + options.type + ' ol-control ol-unselectable';
if (options.active) {
element.className += " type-active";
element.classList.add("type-active");
}
var self = this;
@ -21,10 +21,9 @@ var GeometryTypeControl = function(opt_options) {
type: options.type
});
options.widget.map.addInteraction(options.widget.interactions.draw);
var className = options.widget.currentGeometryType.element.className.replace(/ type-active/g, '');
options.widget.currentGeometryType.element.className = className;
options.widget.currentGeometryType.element.classList.remove('type-active');
options.widget.currentGeometryType = self;
element.className += " type-active";
element.classList.add("type-active");
}
};