Commit f5ce569dc892ce17e192a958a778eaf0f5a65044
Make work without globals
Charles Lehner committed on 12/19/2015, 12:58:10 AMParent: 039e38b052d8968548692f64b0458301b8cfe09c
Files changed
index.js | changed |
index.js | |||
---|---|---|---|
@@ -70,15 +70,17 @@ | |||
70 | 70 … | node = node.parentNode; | |
71 | 71 … | } while (!node.nextSibling); | |
72 | 72 … | node = node.nextSibling; | |
73 | 73 … | } | |
74 | - } while (node.nodeType != Node.TEXT_NODE); | ||
74 … | + } while (node.nodeType != node.TEXT_NODE); | ||
75 | 75 … | return node; | |
76 | 76 … | } | |
77 | 77 … | ||
78 | 78 … | function getPreviousTextNode(node, container, wrap) { | |
79 | 79 … | do { | |
80 | - if (node == container) { | ||
80 … | + if (!node) { | ||
81 … | + node = container; | ||
82 … | + } else if (node == container) { | ||
81 | 83 … | if (!wrap) | |
82 | 84 … | return null; | |
83 | 85 … | while (shouldDescendInto(node) && node.lastChild) | |
84 | 86 … | node = node.lastChild; | |
@@ -89,9 +91,9 @@ | |||
89 | 91 … | node = node.lastChild; | |
90 | 92 … | } else { | |
91 | 93 … | node = node.parentNode; | |
92 | 94 … | } | |
93 | - } while (node.nodeType != Node.TEXT_NODE); | ||
95 … | + } while (node.nodeType != node.TEXT_NODE); | ||
94 | 96 … | return node; | |
95 | 97 … | } | |
96 | 98 … | ||
97 | 99 … | function matchLast(re, str) { | |
@@ -110,9 +112,9 @@ | |||
110 | 112 … | var startNode = sel.focusNode; | |
111 | 113 … | var startOffset = 0; | |
112 | 114 … | if (!startNode || !this.container.contains(startNode)) | |
113 | 115 … | startNode = getNextTextNode(this.container, this.container, true); | |
114 | - else if (startNode.nodeType != Node.TEXT_NODE) | ||
116 … | + else if (startNode.nodeType != startNode.TEXT_NODE) | ||
115 | 117 … | startNode = getNextTextNode(startNode, this.container, true); | |
116 | 118 … | else | |
117 | 119 … | startOffset = sel.focusOffset; | |
118 | 120 … | ||
@@ -138,9 +140,9 @@ | |||
138 | 140 … | var endNode = sel.anchorNode; | |
139 | 141 … | var endOffset = 0; | |
140 | 142 … | if (!endNode || !this.container.contains(endNode)) | |
141 | 143 … | endNode = getPreviousTextNode(endNode, this.container, true); | |
142 | - else if (endNode.nodeType != Node.TEXT_NODE) | ||
144 … | + else if (endNode.nodeType != endNode.TEXT_NODE) | ||
143 | 145 … | endNode = getPreviousTextNode(this.container, this.container, true); | |
144 | 146 … | else | |
145 | 147 … | endOffset = sel.anchorOffset; | |
146 | 148 … | ||
@@ -158,9 +160,9 @@ | |||
158 | 160 … | } | |
159 | 161 … | } | |
160 | 162 … | }; | |
161 | 163 … | ||
162 | -if (global.module) | ||
164 … | +if (typeof module != "undefined") | ||
163 | 165 … | module.exports = TextNodeSearcher; | |
164 | -else | ||
166 … | +else if (global) | ||
165 | 167 … | global.TextNodeSearcher = TextNodeSearcher; | |
166 | 168 … | }(this)); |
Built with git-ssb-web