Changeset 22246 for extensions/rv_autocomplete
- Timestamp:
- Apr 17, 2013, 6:20:18 AM (12 years ago)
- Location:
- extensions/rv_autocomplete
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/rv_autocomplete/functions.inc.php
r22201 r22246 57 57 if ($q != strtolower($l)) 58 58 $ret['q'] = $q; 59 if ($item['counter'] > 0) 60 $ret['w'] = $item['counter']; 59 61 return $ret; 60 62 } -
extensions/rv_autocomplete/main.inc.php
r22214 r22246 45 45 global $template; 46 46 47 $core_src = get_root_url().'plugins/'.RVAC_ID.'/res/suggest-core.js'; 47 $plug_root = get_root_url().'plugins/'.RVAC_ID.'/'; 48 $core_src = $plug_root.'res/suggest-core.js'; 48 49 49 50 $data_src = rvac_get_data_file(); … … 51 52 $data_src = get_root_url().$data_src; 52 53 else 53 $data_src = get_root_url().'plugins/'.RVAC_ID.'/suggestions.php';54 $data_src = $plug_root.'suggestions.php'; 54 55 55 $fs = 'var RVAC={ };56 $fs = 'var RVAC={root:"'.$plug_root.'"}; 56 57 $("#qsearchInput").one("focus", function() { 57 58 var s; -
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 } -
extensions/rv_autocomplete/suggestions.php
r22201 r22246 23 23 24 24 $ds = str_replace( 25 array('\\/', '"q":', '"label":', '"value":' ),26 array('/', 'q:', 'label:', 'value:' ),25 array('\\/', '"q":', '"label":', '"value":', '"w":'), 26 array('/', 'q:', 'label:', 'value:', 'w:'), 27 27 json_encode($data['src'])); 28 28 $js = '$.extend(RVAC, {
Note: See TracChangeset
for help on using the changeset viewer.