[ Index ] |
|
Code source de Serendipity 1.2 |
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 <devel@bitflux.ch> | 16 // +----------------------------------------------------------------------+ 17 18 */ 19 var liveSearchReq = false; 20 var t = null; 21 var liveSearchLast = ""; 22 var isIE = false; 23 24 // on !IE we only have to initialize it once 25 if (window.XMLHttpRequest) { 26 liveSearchReq = new XMLHttpRequest(); 27 } 28 29 function 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 41 function 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 62 function liveSearchKeyPress(event) { 63 if (event.keyCode == 40 ) { //KEY DOWN 64 highlight = document.getElementById("LSHighlight"); 65 if (!highlight) { 66 highlight = document.getElementById("LSResult").firstChild.firstChild.firstChild; 67 } else { 68 highlight.removeAttribute("id"); 69 highlight = highlight.nextSibling; 70 } 71 if (highlight) { 72 highlight.setAttribute("id","LSHighlight"); 73 } 74 if (!isIE) { event.preventDefault(); } 75 } 76 //KEY UP 77 else if (event.keyCode == 38 ) { 78 highlight = document.getElementById("LSHighlight"); 79 if (!highlight) { 80 highlight = document.getElementById("LSResult").firstChild.firstChild.lastChild; 81 } 82 else { 83 highlight.removeAttribute("id"); 84 highlight = highlight.previousSibling; 85 } 86 if (highlight) { 87 highlight.setAttribute("id","LSHighlight"); 88 } 89 if (!isIE) { event.preventDefault(); } 90 } 91 //ESC or mouse click 92 else if (event.keyCode == 27 || (event.clientX)) { 93 highlight = document.getElementById("LSHighlight"); 94 if (highlight) { 95 highlight.removeAttribute("id"); 96 } 97 document.getElementById("LSResult").style.display = "none"; 98 } else { 99 liveSearchStart(); 100 } 101 } 102 function liveSearchStart() { 103 if (t) { 104 window.clearTimeout(t); 105 } 106 t = window.setTimeout("liveSearchDoSearch()",200); 107 } 108 109 function liveSearchDoSearch() { 110 v = document.getElementById('serendipityQuickSearchTermField').value; 111 if (liveSearchLast != v && v.length > 3) { 112 if (liveSearchReq && liveSearchReq.readyState < 3) { 113 liveSearchReq.abort(); 114 } 115 116 if (v == "") { 117 document.getElementById("LSResult").style.display = "none"; 118 highlight = document.getElementById("LSHighlight"); 119 if (highlight) { 120 highlight.removeAttribute("id"); 121 } 122 return false; 123 } 124 125 if (window.XMLHttpRequest) { 126 // branch for IE/Windows ActiveX version 127 } else if (window.ActiveXObject) { 128 liveSearchReq = new ActiveXObject("Microsoft.XMLHTTP"); 129 } 130 131 document.getElementById('LSResult').style.display = "block"; 132 document.getElementById('LSResult').firstChild.innerHTML = '<div class="serendipity_livesearch_result">' + waittext + '</div>'; 133 134 liveSearchReq.onreadystatechange= liveSearchProcessReqChange; 135 liveSearchReq.open("GET", lsbase + "s=" + v); 136 liveSearchLast = v; 137 liveSearchReq.send(null); 138 } 139 } 140 141 function liveSearchProcessReqChange() { 142 143 if (liveSearchReq.readyState == 4) { 144 var res = document.getElementById("LSResult"); 145 res.style.display = "block"; 146 rawResult = liveSearchReq.responseText.replace(/<[^>]+>/g, '') 147 if (parseInt(rawResult) == 1) { 148 res.firstChild.innerHTML = notfoundtext 149 } else { 150 res.firstChild.innerHTML = liveSearchReq.responseText; 151 } 152 } 153 } 154 155 function liveSearchSubmit() { 156 var highlight = document.getElementById("LSHighlight"); 157 if (highlight && highlight.firstChild) { 158 document.getElementById('searchform').action = highlight.firstChild.getAttribute("href"); 159 return false; 160 } else { 161 return true; 162 } 163 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Nov 24 09:00:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |