From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../todomvc/vanilla-examples/es2015/src/helpers.js | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/vanilla-examples/es2015/src/helpers.js (limited to 'third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/vanilla-examples/es2015/src/helpers.js') diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/vanilla-examples/es2015/src/helpers.js b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/vanilla-examples/es2015/src/helpers.js new file mode 100644 index 0000000000..154fc48351 --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/vanilla-examples/es2015/src/helpers.js @@ -0,0 +1,53 @@ +'use strict'; + + +// Allow for looping on nodes by chaining: +// qsa('.foo').forEach(function () {}) +NodeList.prototype.forEach = Array.prototype.forEach; + +// Get element(s) by CSS selector: +function qs(selector, scope) { + return (scope || document).querySelector(selector); +} + +function qsa(selector, scope) { + return (scope || document).querySelectorAll(selector); +} + +// addEventListener wrapper: +function $on(target, type, callback, useCapture) { + target.addEventListener(type, callback, !!useCapture); +} + +// Attach a handler to event for all elements that match the selector, +// now or in the future, based on a root element +function $delegate(target, selector, type, handler) { + let dispatchEvent = event => { + const targetElement = event.target; + const potentialElements = qsa(selector, target); + const hasMatch = Array.prototype.indexOf.call(potentialElements, targetElement) >= 0; + + if (hasMatch) { + handler.call(targetElement, event); + } + }; + + // https://developer.mozilla.org/en-US/docs/Web/Events/blur + const useCapture = type === 'blur' || type === 'focus'; + + $on(target, type, dispatchEvent, useCapture); +} + +// Find the element's parent with the given tag name: +// $parent(qs('a'), 'div') +function $parent(element, tagName) { + if (!element.parentNode) { + return; + } + + if (element.parentNode.tagName.toLowerCase() === tagName.toLowerCase()) { + return element.parentNode; + } + + return $parent(element.parentNode, tagName); +} -- cgit v1.2.3