diff --git a/core/core.libraries.yml b/core/core.libraries.yml index 1023741e42e5944b113f1036ce666ca75d8ec103..f4449213627edb678ff7dab02ac2ddc53aafccbd 100644 --- a/core/core.libraries.yml +++ b/core/core.libraries.yml @@ -381,6 +381,11 @@ drupal.states: - core/once - core/jquery.once.bc +drupal.string.includes: + version: VERSION + js: + misc/polyfills/string.includes.js: { weight: -20 } + drupal.tabbingmanager: version: VERSION js: diff --git a/core/misc/polyfills/string.includes.es6.js b/core/misc/polyfills/string.includes.es6.js new file mode 100644 index 0000000000000000000000000000000000000000..25eebd8d126c5d4ceea7a1167e84a2cf024a39c9 --- /dev/null +++ b/core/misc/polyfills/string.includes.es6.js @@ -0,0 +1,26 @@ +/** + * @file + * Provides a polyfill for String.includes(). + * + * This is needed for Internet Explorer 11 and Opera Mini. + * + * This has been copied from MDN Web Docs code samples. Code samples in the MDN + * Web Docs are licensed under CC0. + * + * @see https://web.archive.org/web/20210916035058/https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes + * @see https://developer.mozilla.org/en-US/docs/MDN/About#Code_samples_and_snippets + */ +/* eslint-disable strict, lines-around-directive, no-extend-native */ +if (!String.prototype.includes) { + String.prototype.includes = function (search, start) { + 'use strict'; + + if (search instanceof RegExp) { + throw TypeError('first argument must not be a RegExp'); + } + if (start === undefined) { + start = 0; + } + return this.indexOf(search, start) !== -1; + }; +} diff --git a/core/misc/polyfills/string.includes.js b/core/misc/polyfills/string.includes.js new file mode 100644 index 0000000000000000000000000000000000000000..1a1ea7cd04cb75fb2bff35e8c5bafaf13bfd2524 --- /dev/null +++ b/core/misc/polyfills/string.includes.js @@ -0,0 +1,22 @@ +/** +* DO NOT EDIT THIS FILE. +* See the following change record for more information, +* https://www.drupal.org/node/2815083 +* @preserve +**/ + +if (!String.prototype.includes) { + String.prototype.includes = function (search, start) { + 'use strict'; + + if (search instanceof RegExp) { + throw TypeError('first argument must not be a RegExp'); + } + + if (start === undefined) { + start = 0; + } + + return this.indexOf(search, start) !== -1; + }; +} \ No newline at end of file diff --git a/core/modules/block/block.libraries.yml b/core/modules/block/block.libraries.yml index 80df74c1c726edb1a36e6fbe2f0016e29d4157e3..b67d33870834bef2adf0426dee49271da3f71153 100644 --- a/core/modules/block/block.libraries.yml +++ b/core/modules/block/block.libraries.yml @@ -21,5 +21,6 @@ drupal.block.admin: - core/drupal.announce - core/drupal.debounce - core/drupal.dialog.ajax + - core/drupal.string.includes - core/once - core/jquery.once.bc diff --git a/core/modules/block/js/block.admin.es6.js b/core/modules/block/js/block.admin.es6.js index d475348b741c4443f3a679db15aada789bf1ba88..360fcf41ff0285b72cf74b77464315b81e66b628 100644 --- a/core/modules/block/js/block.admin.es6.js +++ b/core/modules/block/js/block.admin.es6.js @@ -46,7 +46,7 @@ function toggleBlockEntry(index, label) { const $label = $(label); const $row = $label.parent().parent(); - const textMatch = $label.text().toLowerCase().indexOf(query) !== -1; + const textMatch = $label.text().toLowerCase().includes(query); $row.toggle(textMatch); } diff --git a/core/modules/block/js/block.admin.js b/core/modules/block/js/block.admin.js index 28cdf71769faf1dc05bad9eecbdafd595bbe478d..7469333c70ab792e28588db1e149b25f9d6f1c34 100644 --- a/core/modules/block/js/block.admin.js +++ b/core/modules/block/js/block.admin.js @@ -18,7 +18,7 @@ function toggleBlockEntry(index, label) { var $label = $(label); var $row = $label.parent().parent(); - var textMatch = $label.text().toLowerCase().indexOf(query) !== -1; + var textMatch = $label.text().toLowerCase().includes(query); $row.toggle(textMatch); }