git ssb

0+

cel / text-node-searcher



Tree: 0cbc09f8c35d3f52a860beea7d78733855882fd0

Files: 0cbc09f8c35d3f52a860beea7d78733855882fd0 / index.js

1800 bytesRaw
1(function (global) {
2
3function addAccents(str) {
4 // http://www.the-art-of-web.com/javascript/search-highlight/
5 return str
6 // .replace(/([ao])e/ig, "$1")
7 .replace(/e/ig, "[eèéêë]")
8 .replace(/a/ig, "([aàâä]|ae)")
9 .replace(/i/ig, "[iîï]")
10 .replace(/o/ig, "([oôö]|oe)")
11 .replace(/u/ig, "[uùûü]")
12 .replace(/y/ig, "[yÿ]");
13}
14
15function setSelection(startNode, startOffset, endNode, endOffset) {
16 var range = document.createRange();
17 range.setStart(startNode, startOffset);
18 range.setEnd(endNode, endOffset);
19
20 var sel = window.getSelection();
21 sel.removeAllRanges();
22 sel.addRange(range);
23}
24
25function Searcher(container) {
26 this.container = container;
27}
28
29Searcher.prototype.highlight = function () {
30 // if (this.isHighlighted)
31
32};
33
34Searcher.prototype.setQuery = function (str) {
35 if (str == this.queryStr)
36 return;
37
38 this.queryStr = str;
39 this.queryLen = str.length;
40 this.query = new RegExp(addAccents(str), "i");
41};
42
43Searcher.prototype.selectNext = function () {
44 // Searcher_selectNext(this.container);
45 var sel = window.getSelection();
46 // var range = sel.getRangeAt(0);
47 setSelection(sel.anchorNode, sel.anchorOffset + 1,
48 sel.extentNode, sel.extentOffset + 1);
49};
50
51Searcher.prototype.selectPrev = function () {
52};
53
54/*
55function Searcher_selectNext(parentNode) {
56 for (var el = parentNode.firstChild; el; el = el.nextSibling) {
57 if (el.firstChild) {
58 Searcher_selectNext(parentNode);
59 } else if (el.nodeType == 3) { // NODE_TEXT
60 var text = el.nodeValue;
61 void text;
62 }
63 }
64}
65*/
66
67/*
68var range = document.createRange();
69
70range.setStart(startNode, startOffset);
71range.setEnd(endNode, endOffset);
72
73var s = window.getSelection();
74l.removeAllRanges();
75s.addRange(range);
76*/
77
78if (global.module)
79 module.exports = Searcher;
80else
81 global.Searcher = Searcher;
82}(this));
83

Built with git-ssb-web