Changeset 22246 for extensions/rv_autocomplete/res
- Timestamp:
- Apr 17, 2013, 6:20:18 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/rv_autocomplete/res/suggest-core.js
r22201 r22246 93 93 } 94 94 95 RVAC.requestedContexts = {}; 96 RVAC.requestingContexts = 0; 97 98 RVAC.mergeData = function(data) { 99 RVAC.requestingContexts--; 100 var ctxq = data.ctxq + " " 101 , ctxl = data.ctxl + " "; 102 data = data.dataSource; 103 $.each(data, function(i,item) { 104 if (item.q) 105 item.q = ctxq + item.q; 106 else 107 item.q = ctxq + item.label.toLowerCase(); 108 item.label = ctxl + item.label; 109 item.ctx = 1; 110 }); 111 112 var ids=0, inew=0; 113 114 while (inew < data.length) { 115 while (RVAC.dataSource[ids].w > data[inew].w) 116 ids++; 117 RVAC.dataSource.splice(ids, 0, data[inew]); 118 RVAC.dataSourceAltLangIndex++; 119 inew++; 120 } 121 122 var inp = $("#qsearchInput"); 123 if (data.length && inp.is(":focus")) { 124 inp.autocomplete("search"); 125 } 126 }; 127 95 128 RVAC.start = function() { 96 129 var $input = $("#qsearchInput"); … … 124 157 window.location = (url + (/\?/.test(url) ? "&" : "?") + "acs=" + term); 125 158 } 126 159 127 160 return false; 128 161 }, … … 145 178 var item = RVAC.dataSource[i]; 146 179 if ( (item._matchIdx = item.q.search(matcher)) > -1 ) { 180 if (item.ctx && item._matchIdx>0) 181 continue; // context searches only at beginning 147 182 if (item.value !== -1) { 148 183 if (found.hasOwnProperty(item.value)) … … 157 192 158 193 if (res.length > RVAC.suggestions) {//try filter 159 // compute number of matched "words" or "expression "194 // compute number of matched "words" or "expressions" 160 195 found={}; 161 196 var foundWords=0, word; … … 202 237 } 203 238 239 var that = this; 240 if (!RVAC.requestingContexts && this.options.rv.q.length > 1) { 241 var eligible = $.grep( res, function(item) { 242 if (item._matchIdx > 0 243 || item.w <= 25 244 || item.value === -1 245 || item.value[0]!="$" || item.value[1]!="t") 246 return 0; 247 if (RVAC.requestedContexts.hasOwnProperty(item.value)) 248 return 0; 249 if (item.q.length - that.options.rv.q.length > 3) 250 return 0; 251 return 1; 252 } ); 253 254 if (eligible.length) { 255 item = eligible[0]; 256 RVAC.requestedContexts[item.value] = 1; 257 RVAC.requestingContexts++; 258 var s=document.createElement("script");s.type="text/javascript";s.async=true; 259 s.src=RVAC.root+"context_suggest.php?context="+encodeURIComponent(item.value)+"&ctxq="+encodeURIComponent(item.q)+"&ctxl="+encodeURIComponent(item.label); 260 document.body.appendChild(s); 261 } 262 } 263 204 264 response( res ); 205 265 }
Note: See TracChangeset
for help on using the changeset viewer.