luci-base: cbi.js: utilize node.closest() if available
authorJo-Philipp Wich <jo@mein.io>
Sat, 20 Oct 2018 07:55:59 +0000 (09:55 +0200)
committerJo-Philipp Wich <jo@mein.io>
Mon, 5 Nov 2018 10:01:45 +0000 (11:01 +0100)
Use node.closest() in findParent() when available since it should be faster
than manaually traversing the ancestor chain.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/cbi.js

index f4b0ba34916c5c5ca6d1ccda128f68d62eb5c9c0..7248c517798e3fe9c1a8ac77e92c5f1325c054f0 100644 (file)
@@ -1606,6 +1606,9 @@ function matchesElem(node, selector)
 
 function findParent(node, selector)
 {
+       if (node.closest)
+               return node.closest(selector);
+
        while (node)
                if (matchesElem(node, selector))
                        return node;