index.jsView |
---|
22 | 22 … | .replace(/u/ig, "[uùûü]") |
23 | 23 … | .replace(/y/ig, "[yÿ]"); |
24 | 24 … | } |
25 | 25 … | |
| 26 … | +function quoteRegex(str) { |
| 27 … | + return str.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1"); |
| 28 … | +} |
| 29 … | + |
26 | 30 … | function setSelection(startNode, startOffset, endNode, endOffset) { |
27 | 31 … | var range = document.createRange(); |
28 | 32 … | range.setStart(startNode, startOffset); |
29 | 33 … | range.setEnd(endNode, endOffset); |
41 | 45 … | if (str == this.queryStr) |
42 | 46 … | return; |
43 | 47 … | |
44 | 48 … | this.queryStr = str; |
45 | | - this.query = new RegExp(addAccents(str), "ig"); |
| 49 … | + this.query = new RegExp(addAccents(quoteRegex(str)), "ig"); |
46 | 50 … | }; |
47 | 51 … | |
48 | 52 … | function shouldDescendInto(node) { |
49 | 53 … | return node.nodeName != "SCRIPT" && node.nodeName != "STYLE"; |
104 | 108 … | |
105 | 109 … | var sel = window.getSelection(); |
106 | 110 … | var startNode = sel.focusNode; |
107 | 111 … | var startOffset = 0; |
108 | | - if (!startNode || startNode.nodeType != Node.TEXT_NODE || |
109 | | - !this.container.contains(startNode)) |
| 112 … | + if (!startNode || !this.container.contains(startNode)) |
| 113 … | + startNode = getNextTextNode(this.container, this.container, true); |
| 114 … | + else if (startNode.nodeType != Node.TEXT_NODE) |
110 | 115 … | startNode = getNextTextNode(startNode, this.container, true); |
111 | 116 … | else |
112 | 117 … | startOffset = sel.focusOffset; |
113 | 118 … | |
131 | 136 … | |
132 | 137 … | var sel = window.getSelection(); |
133 | 138 … | var endNode = sel.anchorNode; |
134 | 139 … | var endOffset = 0; |
135 | | - if (!endNode || endNode.nodeType != Node.TEXT_NODE || |
136 | | - !this.container.contains(endNode)) |
| 140 … | + if (!endNode || !this.container.contains(endNode)) |
137 | 141 … | endNode = getPreviousTextNode(endNode, this.container, true); |
| 142 … | + else if (endNode.nodeType != Node.TEXT_NODE) |
| 143 … | + endNode = getPreviousTextNode(this.container, this.container, true); |
138 | 144 … | else |
139 | 145 … | endOffset = sel.anchorOffset; |
140 | 146 … | |
141 | 147 … | for (var node = endNode; node; |