Simplified JavaScript with Array.prototype.includes().

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes
This commit is contained in:
Jon Dufresne 2020-06-22 18:08:35 -07:00 committed by Carlton Gibson
parent c2a835703f
commit dbae6de01e
5 changed files with 10 additions and 10 deletions

View File

@ -31,7 +31,7 @@
node.displayed = 1;
const node_text = node.text.toLowerCase();
for (const token of tokens) {
if (node_text.indexOf(token) === -1) {
if (!node_text.includes(token)) {
node.displayed = 0;
break; // Once the first token isn't found we're done
}

View File

@ -9,10 +9,10 @@
const name = triggeringLink.id.replace(name_regexp, '');
let href = triggeringLink.href;
if (add_popup) {
if (href.indexOf('?') === -1) {
href += '?_popup=1';
} else {
if (href.includes('?')) {
href += '&_popup=1';
} else {
href += '?_popup=1';
}
}
const win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes');

View File

@ -14,10 +14,10 @@
ready(function() {
function handleClick(event) {
event.preventDefault();
if (window.location.search.indexOf('&_popup=1') === -1) {
window.history.back(); // Go back if not a popup.
if (window.location.search.includes('&_popup=1')) {
window.close(); // Close the popup.
} else {
window.close(); // Otherwise, close the popup.
window.history.back(); // Otherwise, go back.
}
}

View File

@ -50,7 +50,7 @@ ol.inherits(GeometryTypeControl, ol.control.Control);
default_lat: 0,
default_lon: 0,
default_zoom: 12,
is_collection: options.geom_name.indexOf('Multi') > -1 || options.geom_name.indexOf('Collection') > -1
is_collection: options.geom_name.includes('Multi') || options.geom_name.includes('Collection')
};
// Altering using user-provided options

View File

@ -137,7 +137,7 @@ js_catalog_template = r"""
django.pgettext = function(context, msgid) {
var value = django.gettext(context + '\x04' + msgid);
if (value.indexOf('\x04') != -1) {
if (value.includes('\x04')) {
value = msgid;
}
return value;
@ -145,7 +145,7 @@ js_catalog_template = r"""
django.npgettext = function(context, singular, plural, count) {
var value = django.ngettext(context + '\x04' + singular, context + '\x04' + plural, count);
if (value.indexOf('\x04') != -1) {
if (value.includes('\x04')) {
value = django.ngettext(singular, plural, count);
}
return value;