Index: trunk/extensions/SemanticForms/libs/SemanticForms.js |
— | — | @@ -13,6 +13,29 @@ |
14 | 14 | |
15 | 15 | // Activate autocomplete functionality for the specified field |
16 | 16 | (function(jQuery) { |
| 17 | + |
| 18 | + /* extending jQuery functions for custom highlighting */ |
| 19 | + jQuery.ui.autocomplete.prototype._renderItem = function( ul, item) { |
| 20 | + |
| 21 | + var delim = this.element.context.delimiter; |
| 22 | + if ( delim == null ) { |
| 23 | + term = this.term; |
| 24 | + } else { |
| 25 | + term = this.term.split( delim ).pop(); |
| 26 | + } |
| 27 | + var re = new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"); |
| 28 | + var loc = item.label.search(re); |
| 29 | + if (loc >= 0) { |
| 30 | + var t = item.label.substr(0, loc) + '<strong>' + item.label.substr(loc, term.length) + '</strong>' + item.label.substr(loc + term.length); |
| 31 | + } else { |
| 32 | + var t = item.label; |
| 33 | + } |
| 34 | + return jQuery( "<li></li>" ) |
| 35 | + .data( "item.autocomplete", item ) |
| 36 | + .append( " <a>" + t + "</a>" ) |
| 37 | + .appendTo( ul ); |
| 38 | + }; |
| 39 | + |
17 | 40 | jQuery.fn.attachAutocomplete = function() { |
18 | 41 | return this.each(function() { |
19 | 42 | // Get all the necessary values from the input's "autocompletesettings" |
— | — | @@ -29,22 +52,6 @@ |
30 | 53 | } |
31 | 54 | } |
32 | 55 | |
33 | | - /* extending jQuery functions for custom highlighting */ |
34 | | - jQuery.ui.autocomplete.prototype._renderItem = function( ul, item) { |
35 | | - |
36 | | - var re = new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + this.term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"); |
37 | | - var loc = item.label.search(re); |
38 | | - if (loc >= 0) { |
39 | | - var t = item.label.substr(0, loc) + '<strong>' + item.label.substr(loc, this.term.length) + '</strong>' + item.label.substr(loc + this.term.length); |
40 | | - } else { |
41 | | - var t = item.label; |
42 | | - } |
43 | | - return jQuery( "<li></li>" ) |
44 | | - .data( "item.autocomplete", item ) |
45 | | - .append( " <a>" + t + "</a>" ) |
46 | | - .appendTo( ul ); |
47 | | - }; |
48 | | - |
49 | 56 | // Modify the delimiter. If it's "\n", change it to an actual |
50 | 57 | // newline - otherwise, add a space to the end. |
51 | 58 | // This doesn't cover the case of a delimiter that's a newline |
— | — | @@ -57,6 +64,9 @@ |
58 | 65 | delimiter += " "; |
59 | 66 | } |
60 | 67 | } |
| 68 | + // Store this value within the object, so that it can be used |
| 69 | + // during highlighting of the search term as well. |
| 70 | + this.delimiter = delimiter; |
61 | 71 | |
62 | 72 | /* extending jquery functions */ |
63 | 73 | jQuery.extend( jQuery.ui.autocomplete, { |