PageSourceSearch

https://martinvogel.de/blog/index.php?/plugin/ls-js

js martinvogel.de collected 2026-10-03 19:11:41 UTC 6,165 bytes, 164 lines download raw bytes

1/*
2// +----------------------------------------------------------------------+
3// | Copyright (c) 2004 Bitflux GmbH                                      |
4// +----------------------------------------------------------------------+
5// | Licensed under the Apache License, Version 2.0 (the "License");      |
6// | you may not use this file except in compliance with the License.     |
7// | You may obtain a copy of the License at                              |
8// | http://www.apache.org/licenses/LICENSE-2.0                           |
9// | Unless required by applicable law or agreed to in writing, software  |
10// | distributed under the License is distributed on an "AS IS" BASIS,    |
11// | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or      |
12// | implied. See the License for the specific language governing         |
13// | permissions and limitations under the License.                       |
14// +----------------------------------------------------------------------+
15// | Author: Bitflux GmbH <[email protected]>                              |
16// +----------------------------------------------------------------------+
17
18*/
19var liveSearchReq = false;
20var t = null;
21var liveSearchLast = "";
22var isIE = false;
23
24// on !IE we only have to initialize it once
25if (window.XMLHttpRequest) {
26    liveSearchReq = new XMLHttpRequest();
27}
28
29function addLoadEvent(func) {
30  var oldonload = window.onload;
31  if (typeof window.onload != 'function') {
32    window.onload = func;
33  } else {
34    window.onload = function() {
35      oldonload();
36      func();
37    }
38  }
39}
40
41function liveSearchInit() {
42    if (navigator.userAgent.indexOf("Safari") > 0) {
43        document.getElementById('serendipityQuickSearchTermField').addEventListener("keydown", liveSearchKeyPress,false);
44        document.getElementById('searchform').addEventListener("submit", liveSearchSubmit,false);
45    } else if (navigator.product == "Gecko") {
46        document.getElementById('serendipityQuickSearchTermField').addEventListener("keypress", liveSearchKeyPress,false);
47        document.getElementById('searchform').addEventListener("submit", liveSearchSubmit,false);
48    } else {
49        document.getElementById('serendipityQuickSearchTermField').attachEvent("onkeydown", liveSearchKeyPress);
50        document.getElementById('searchform').attachEvent("onsubmit", liveSearchSubmit);
51        isIE = true;
52    }
53
54    if (document.getElementById('searchform').setAttribute) {
55        document.getElementById('searchform').setAttribute('autocomplete','off');
56        document.getElementById('serendipityQuickSearchTermField').setAttribute('autocomplete','off');
57    }
58
59	 document.onclick = liveSearchKeyPress
60}
61
62function liveSearchKeyPress(event) {
63    if (!event || typeof(event) == 'undefined' || typeof(event.keyCode) == 'undefined') return;
64    if (event.keyCode == 40 ) { //KEY DOWN
65        highlight = document.getElementById("LSHighlight");
66        if (!highlight) {
67            highlight = document.getElementById("LSResult").firstChild.firstChild.firstChild;
68        } else {
69            highlight.removeAttribute("id");
70            highlight = highlight.nextSibling;
71        }
72        if (highlight) {
73            highlight.setAttribute("id","LSHighlight");
74        }
75        if (!isIE) { event.preventDefault(); }
76    }
77    //KEY UP
78    else if (event.keyCode == 38 ) {
79        highlight = document.getElementById("LSHighlight");
80        if (!highlight) {
81            highlight = document.getElementById("LSResult").firstChild.firstChild.lastChild;
82        }
83        else {
84            highlight.removeAttribute("id");
85            highlight = highlight.previousSibling;
86        }
87        if (highlight) {
88                highlight.setAttribute("id","LSHighlight");
89        }
90        if (!isIE) { event.preventDefault(); }
91    }
92    //ESC or mouse click
93    else if (event.keyCode == 27 || (event.clientX)) {
94        highlight = document.getElementById("LSHighlight");
95        if (highlight) {
96            highlight.removeAttribute("id");
97        }
98        document.getElementById("LSResult").style.display = "none";
99	 } else {
100        liveSearchStart();
101    }
102}
103function liveSearchStart() {
104    if (t) {
105        window.clearTimeout(t);
106    }
107    t = window.setTimeout("liveSearchDoSearch()",200);
108}
109
110function liveSearchDoSearch() {
111    v = document.getElementById('serendipityQuickSearchTermField').value;
112    if (liveSearchLast != v && v.length > 3) {
113        if (liveSearchReq && liveSearchReq.readyState < 3) {
114            liveSearchReq.abort();
115        }
116
117        if (v == "") {
118            document.getElementById("LSResult").style.display = "none";
119            highlight = document.getElementById("LSHighlight");
120            if (highlight) {
121                highlight.removeAttribute("id");
122            }
123            return false;
124        }
125
126        if (window.XMLHttpRequest) {
127        // branch for IE/Windows ActiveX version
128        } else if (window.ActiveXObject) {
129            liveSearchReq = new ActiveXObject("Microsoft.XMLHTTP");
130        }
131
132        document.getElementById('LSResult').style.display = "block";
133        document.getElementById('LSResult').firstChild.innerHTML = '<div class="serendipity_livesearch_result">' + waittext + '</div>';
134
135        liveSearchReq.onreadystatechange= liveSearchProcessReqChange;
136        liveSearchReq.open("GET", lsbase + "s=" + v);
137        liveSearchLast = v;
138        liveSearchReq.send(null);
139    }
140}
141
142function liveSearchProcessReqChange() {
143
144    if (liveSearchReq.readyState == 4) {
145        var  res = document.getElementById("LSResult");
146        res.style.display = "block";
147		  rawResult = liveSearchReq.responseText.replace(/<[^>]+>/g, '')
148		  if (parseInt(rawResult) == 1) {
149		      res.firstChild.innerHTML = notfoundtext
150        } else {
151            res.firstChild.innerHTML = liveSearchReq.responseText;
152        }
153    }
154}
155
156function liveSearchSubmit() {
157    var highlight = document.getElementById("LSHighlight");
158    if (highlight && highlight.firstChild) {
159        document.getElementById('searchform').action = highlight.firstChild.getAttribute("href");
160        return false;
161    } else {
162        return true;
163    }
164}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.