summaryrefslogtreecommitdiff
path: root/alarm/node_modules/nwsapi/src/modules/nwsapi-traversal.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-10-18 08:59:09 +0200
committerMinteck <contact@minteck.org>2022-10-18 08:59:09 +0200
commit2c4ae43e688a9873e86211ea0e7aeb9ba770dd77 (patch)
tree17848d95522dab25d3cdeb9c4a6450e2a234861f /alarm/node_modules/nwsapi/src/modules/nwsapi-traversal.js
parent108525534c28013cfe1897c30e4565f9893f3766 (diff)
downloadpluralconnect-2c4ae43e688a9873e86211ea0e7aeb9ba770dd77.tar.gz
pluralconnect-2c4ae43e688a9873e86211ea0e7aeb9ba770dd77.tar.bz2
pluralconnect-2c4ae43e688a9873e86211ea0e7aeb9ba770dd77.zip
Update
Diffstat (limited to 'alarm/node_modules/nwsapi/src/modules/nwsapi-traversal.js')
-rw-r--r--alarm/node_modules/nwsapi/src/modules/nwsapi-traversal.js90
1 files changed, 90 insertions, 0 deletions
diff --git a/alarm/node_modules/nwsapi/src/modules/nwsapi-traversal.js b/alarm/node_modules/nwsapi/src/modules/nwsapi-traversal.js
new file mode 100644
index 0000000..9d2b62f
--- /dev/null
+++ b/alarm/node_modules/nwsapi/src/modules/nwsapi-traversal.js
@@ -0,0 +1,90 @@
+/*
+ * Element Traversal methods from Juriy Zaytsev (kangax)
+ * used to emulate Prototype up/down/previous/next methods
+ */
+
+(function(D){
+
+ // TODO: all of this needs tests
+ var match = D.match, select = D.select, root = document.documentElement,
+
+ // Use the Element Traversal API if available.
+ nextElement = 'nextElementSibling',
+ previousElement = 'previousElementSibling',
+ parentElement = 'parentElement';
+
+ // Fall back to the DOM Level 1 API.
+ if (!(nextElement in root)) nextElement = 'nextSibling';
+ if (!(previousElement in root)) previousElement = 'previousSibling';
+ if (!(parentElement in root)) parentElement = 'parentNode';
+
+ function walkElements(property, element, expr) {
+ var i = 0, isIndex = typeof expr == 'number';
+ if (typeof expr == 'undefined') {
+ isIndex = true;
+ expr = 0;
+ }
+ while ((element = element[property])) {
+ if (element.nodeType != 1) continue;
+ if (isIndex) {
+ ++i;
+ if (i == expr) return element;
+ } else if (match(element, expr)) {
+ return element;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @method up
+ * @param {HTMLElement} element element to walk from
+ * @param {String | Number} expr CSS expression or an index
+ * @return {HTMLElement | null}
+ */
+ function up(element, expr) {
+ return walkElements(parentElement, element, expr);
+ }
+ /**
+ * @method next
+ * @param {HTMLElement} element element to walk from
+ * @param {String | Number} expr CSS expression or an index
+ * @return {HTMLElement | null}
+ */
+ function next(element, expr) {
+ return walkElements(nextElement, element, expr);
+ }
+ /**
+ * @method previous
+ * @param {HTMLElement} element element to walk from
+ * @param {String | Number} expr CSS expression or an index
+ * @return {HTMLElement | null}
+ */
+ function previous(element, expr) {
+ return walkElements(previousElement, element, expr);
+ }
+ /**
+ * @method down
+ * @param {HTMLElement} element element to walk from
+ * @param {String | Number} expr CSS expression or an index
+ * @return {HTMLElement | null}
+ */
+ function down(element, expr) {
+ var isIndex = typeof expr == 'number', descendants, index, descendant;
+ if (expr === null) {
+ element = element.firstChild;
+ while (element && element.nodeType != 1) element = element[nextElement];
+ return element;
+ }
+ if (!isIndex && match(element, expr) || isIndex && expr === 0) return element;
+ descendants = select('*', element);
+ if (isIndex) return descendants[expr] || null;
+ index = 0;
+ while ((descendant = descendants[index]) && !match(descendant, expr)) { ++index; }
+ return descendant || null;
+ }
+ D.up = up;
+ D.down = down;
+ D.next = next;
+ D.previous = previous;
+})(NW.Dom);