git ssb

0+

cel / text-node-searcher



Commit f5ce569dc892ce17e192a958a778eaf0f5a65044

Make work without globals

Charles Lehner committed on 12/19/2015, 12:58:10 AM
Parent: 039e38b052d8968548692f64b0458301b8cfe09c

Files changed

index.jschanged
index.jsView
@@ -70,15 +70,17 @@
7070 node = node.parentNode;
7171 } while (!node.nextSibling);
7272 node = node.nextSibling;
7373 }
74- } while (node.nodeType != Node.TEXT_NODE);
74 + } while (node.nodeType != node.TEXT_NODE);
7575 return node;
7676 }
7777
7878 function getPreviousTextNode(node, container, wrap) {
7979 do {
80- if (node == container) {
80 + if (!node) {
81 + node = container;
82 + } else if (node == container) {
8183 if (!wrap)
8284 return null;
8385 while (shouldDescendInto(node) && node.lastChild)
8486 node = node.lastChild;
@@ -89,9 +91,9 @@
8991 node = node.lastChild;
9092 } else {
9193 node = node.parentNode;
9294 }
93- } while (node.nodeType != Node.TEXT_NODE);
95 + } while (node.nodeType != node.TEXT_NODE);
9496 return node;
9597 }
9698
9799 function matchLast(re, str) {
@@ -110,9 +112,9 @@
110112 var startNode = sel.focusNode;
111113 var startOffset = 0;
112114 if (!startNode || !this.container.contains(startNode))
113115 startNode = getNextTextNode(this.container, this.container, true);
114- else if (startNode.nodeType != Node.TEXT_NODE)
116 + else if (startNode.nodeType != startNode.TEXT_NODE)
115117 startNode = getNextTextNode(startNode, this.container, true);
116118 else
117119 startOffset = sel.focusOffset;
118120
@@ -138,9 +140,9 @@
138140 var endNode = sel.anchorNode;
139141 var endOffset = 0;
140142 if (!endNode || !this.container.contains(endNode))
141143 endNode = getPreviousTextNode(endNode, this.container, true);
142- else if (endNode.nodeType != Node.TEXT_NODE)
144 + else if (endNode.nodeType != endNode.TEXT_NODE)
143145 endNode = getPreviousTextNode(this.container, this.container, true);
144146 else
145147 endOffset = sel.anchorOffset;
146148
@@ -158,9 +160,9 @@
158160 }
159161 }
160162 };
161163
162-if (global.module)
164 +if (typeof module != "undefined")
163165 module.exports = TextNodeSearcher;
164-else
166 +else if (global)
165167 global.TextNodeSearcher = TextNodeSearcher;
166168 }(this));

Built with git-ssb-web