Issue #3439646 by Tom Konda, smustgrave: Some of string comparisons should use String.prototype.startsWith() or String.prototype.endsWith()
parent
d436711365
commit
f5cc65456a
|
@ -84,7 +84,7 @@
|
|||
// jQuery UI does not support percentages on heights, convert to pixels.
|
||||
if (
|
||||
typeof optionValue === 'string' &&
|
||||
/%$/.test(optionValue) &&
|
||||
optionValue.endsWith('%') &&
|
||||
/height/i.test(option)
|
||||
) {
|
||||
// Take offsets in account.
|
||||
|
|
|
@ -448,7 +448,7 @@ window.Drupal = { behaviors: {}, locale: {} };
|
|||
|
||||
// Consider URLs that match this site's base URL but use HTTPS instead of HTTP
|
||||
// as local as well.
|
||||
if (protocol === 'http:' && absoluteUrl.indexOf('https:') === 0) {
|
||||
if (protocol === 'http:' && absoluteUrl.startsWith('https:')) {
|
||||
protocol = 'https:';
|
||||
}
|
||||
let baseUrl = `${protocol}//${
|
||||
|
@ -469,7 +469,7 @@ window.Drupal = { behaviors: {}, locale: {} };
|
|||
|
||||
// The given URL matches the site's base URL, or has a path under the site's
|
||||
// base URL.
|
||||
return absoluteUrl === baseUrl || absoluteUrl.indexOf(`${baseUrl}/`) === 0;
|
||||
return absoluteUrl === baseUrl || absoluteUrl.startsWith(`${baseUrl}/`);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,15 +29,18 @@
|
|||
const regexVertical = /top|center|bottom/;
|
||||
const regexOffset = /[+-]\d+(\.[\d]+)?%?/;
|
||||
const regexPosition = /^\w+/;
|
||||
const regexPercent = /%$/;
|
||||
const _position = $.fn.position;
|
||||
|
||||
function getOffsets(offsets, width, height) {
|
||||
return [
|
||||
parseFloat(offsets[0]) *
|
||||
(regexPercent.test(offsets[0]) ? width / 100 : 1),
|
||||
(typeof offsets[0] === 'string' && offsets[0].endsWith('%')
|
||||
? width / 100
|
||||
: 1),
|
||||
parseFloat(offsets[1]) *
|
||||
(regexPercent.test(offsets[1]) ? height / 100 : 1),
|
||||
(typeof offsets[1] === 'string' && offsets[1].endsWith('%')
|
||||
? height / 100
|
||||
: 1),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
_.chain(storage)
|
||||
.keys()
|
||||
.each((key) => {
|
||||
if (key.substring(0, 18) === 'Drupal.contextual.') {
|
||||
if (key.startsWith('Drupal.contextual.')) {
|
||||
storage.removeItem(key);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
drupalSettings.path.baseUrl.length,
|
||||
);
|
||||
// Ensure we have a correct path.
|
||||
if (viewHref && path.substring(0, viewHref.length + 1) === `${viewHref}/`) {
|
||||
if (viewHref && path.startsWith(`${viewHref}/`)) {
|
||||
returnObj.view_args = decodeURIComponent(
|
||||
path.substring(viewHref.length + 1, path.length),
|
||||
);
|
||||
|
@ -80,7 +80,7 @@
|
|||
Drupal.Views.pathPortion = function (href) {
|
||||
// Remove e.g. http://example.com if present.
|
||||
const protocol = window.location.protocol;
|
||||
if (href.substring(0, protocol.length) === protocol) {
|
||||
if (href.startsWith(protocol)) {
|
||||
// 2 is the length of the '//' that normally follows the protocol.
|
||||
href = href.substring(href.indexOf('/', protocol.length + 2));
|
||||
}
|
||||
|
@ -99,8 +99,8 @@
|
|||
Drupal.Views.getPath = function (href) {
|
||||
href = Drupal.Views.pathPortion(href);
|
||||
href = href.substring(drupalSettings.path.baseUrl.length, href.length);
|
||||
if (href.startsWith('?q=')) {
|
||||
// 3 is the length of the '?q=' added to the URL without clean URLs.
|
||||
if (href.substring(0, 3) === '?q=') {
|
||||
href = href.substring(3, href.length);
|
||||
}
|
||||
const chars = ['#', '?', '&'];
|
||||
|
|
|
@ -245,8 +245,9 @@
|
|||
// Set the URL to go to the anchor.
|
||||
elementSettings.url = $link.attr('href');
|
||||
if (
|
||||
Drupal.Views.getPath(elementSettings.url).substring(0, 21) !==
|
||||
'admin/structure/views'
|
||||
!Drupal.Views.getPath(elementSettings.url).startsWith(
|
||||
'admin/structure/views',
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
@ -273,8 +274,9 @@
|
|||
// Set the URL to go to the anchor.
|
||||
elementSettings.url = $(submit.form).attr('action');
|
||||
if (
|
||||
Drupal.Views.getPath(elementSettings.url).substring(0, 21) !==
|
||||
'admin/structure/views'
|
||||
!Drupal.Views.getPath(elementSettings.url).startsWith(
|
||||
'admin/structure/views',
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -820,7 +820,6 @@ module.exports = {
|
|||
const regexVertical = /top|center|bottom/;
|
||||
const regexOffset = /[+-]\d+(\.[\d]+)?%?/;
|
||||
const regexPosition = /^\w+/;
|
||||
const regexPercent = /%$/;
|
||||
let positions = offset.split(' ');
|
||||
if (positions.length === 1) {
|
||||
if (regexHorizontal.test(positions[0])) {
|
||||
|
@ -837,13 +836,13 @@ module.exports = {
|
|||
return {
|
||||
horizontalOffset: horizontalOffset
|
||||
? parseFloat(horizontalOffset[0]) *
|
||||
(regexPercent.test(horizontalOffset[0])
|
||||
(horizontalOffset[0].endsWith('%')
|
||||
? element.offsetWidth / 100
|
||||
: 1)
|
||||
: 0,
|
||||
verticalOffset: verticalOffset
|
||||
? parseFloat(verticalOffset[0]) *
|
||||
(regexPercent.test(verticalOffset[0])
|
||||
(verticalOffset[0].endsWith('%')
|
||||
? element.offsetWidth / 100
|
||||
: 1)
|
||||
: 0,
|
||||
|
|
Loading…
Reference in New Issue