Verified Commit 270f95ac authored by Théodore Biadala's avatar Théodore Biadala
Browse files

Issue #3439646 by Tom Konda, smustgrave: Some of string comparisons should use...

Issue #3439646 by Tom Konda, smustgrave: Some of string comparisons should use String.prototype.startsWith() or String.prototype.endsWith()

(cherry picked from commit f5cc6545)
parent 91b7e66d
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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.
+2 −2
Original line number Diff line number Diff line
@@ -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}/`);
  };

  /**
+6 −3
Original line number Diff line number Diff line
@@ -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),
    ];
  }

+1 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@
      _.chain(storage)
        .keys()
        .each((key) => {
          if (key.substring(0, 18) === 'Drupal.contextual.') {
          if (key.startsWith('Drupal.contextual.')) {
            storage.removeItem(key);
          }
        });
+4 −4
Original line number Diff line number Diff line
@@ -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 = ['#', '?', '&'];
Loading