Changeset 28805 for extensions/rv_autocomplete/res
- Timestamp:
- Jun 26, 2014, 10:21:57 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/rv_autocomplete/res/suggest-core.js
r28778 r28805 69 69 70 70 function ac_normalize(str) { 71 return str.replace(RVAC.rSpaceLike, ' ').replace(/ {2,}/g, ' '). replace(/(^ | $)/g, '');72 } 73 74 function ac_analyze(input, lastFocusStr) {71 return str.replace(RVAC.rSpaceLike, ' ').replace(/ {2,}/g, ' ').trim(); 72 } 73 74 function ac_analyze(input, previous) { 75 75 var intent="", quoted=0, brackets=0, is_complex=0, scope="", i=0; 76 76 77 if (lastFocusStr.length) { 78 if (input.indexOf(lastFocusStr) == 0) { 79 i = lastFocusStr.length; 77 var lastIgnoreMatchStr = previous.lastIgnoreMatchStr, 78 lastFocusStr = previous.lastFocusStr; 79 if (previous.lastIgnoreMatchStr.length) { 80 if (input.indexOf(previous.input) != 0) 81 lastIgnoreMatchStr = lastFocusStr; // some chars deleted from previous 82 if (lastFocusStr.length && input.indexOf(lastIgnoreMatchStr) == 0) { 83 i = lastIgnoreMatchStr.length; 80 84 is_complex = 1; 81 85 } 82 86 else 83 last FocusStr = "";87 lastIgnoreMatchStr = lastFocusStr = ""; 84 88 } 85 89 … … 152 156 scope: scope, 153 157 lastFocusStr: lastFocusStr, 158 lastIgnoreMatchStr: lastIgnoreMatchStr, 154 159 input: input 155 160 } … … 274 279 var $input = $("#qsearchInput"); 275 280 $input.autocomplete({ 276 rv:{lastFocusStr: "" }, minLength: 1,281 rv:{lastFocusStr: "", lastIgnoreMatchStr: ""}, minLength: 1, 277 282 278 283 focus: function(event,ui) { … … 306 311 this.setSelectionRange(999, 999); 307 312 308 expr.lastFocusStr = this.value;313 expr.lastFocusStr = expr.lastIgnoreMatchStr = this.value; 309 314 return false; 310 315 }, … … 326 331 } 327 332 else { 328 this.value = this.value. replace( / $/, '');333 this.value = this.value.trim(); 329 334 var form = $(this).parents("form"); 330 335 form.append( $("<input type='hidden' name='acs' />").val(ac.term) ); … … 336 341 337 342 source: function(request, response) { 338 this.options.rv = ac_analyze(request.term, this.options.rv .lastFocusStr);343 this.options.rv = ac_analyze(request.term, this.options.rv); 339 344 340 345 var res = ac_search(this.options.rv); … … 347 352 348 353 while ( (matches = raw_q.match(/^[ &.,;!\?-]*[^ &.,;!\?-]+[ &.,;!\?-]+/)) != null ) { 349 current.last FocusStr += raw_q.substr(0, matches[0].length);354 current.lastIgnoreMatchStr += raw_q.substr(0, matches[0].length); 350 355 current.raw_q = raw_q = raw_q.substr(matches[0].length); 351 356 current.q = remove_accents( ac_normalize( raw_q.toLowerCase() ) ); … … 368 373 + "</a></li>"; 369 374 370 return $(s) 371 .appendTo(ul); 375 return $(s).appendTo(ul); 372 376 }; 373 377 378 if (window.localStorage) { 379 RVAC.searchHistory = "pwgAutoComplete" in localStorage ? JSON.parse( localStorage.getItem("pwgAutoComplete") ) : []; 380 $input.parents("form").on( "submit", function() { 381 var val = $input.val().trim(); 382 //TODO - save to storage... 383 } ); 384 } 374 385 }; 375 386
Note: See TracChangeset
for help on using the changeset viewer.