r102984 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102983‎ | r102984 | r102985 >
Date:14:11, 14 November 2011
Author:yaron
Status:deferred
Tags:
Comment:
Moved highlighting code for autocompletion, fixed so that it highlights values after the first one, if there are multiple values allowed
Modified paths:
  • /trunk/extensions/SemanticForms/libs/SemanticForms.js (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/libs/SemanticForms.js
@@ -13,6 +13,29 @@
1414
1515 // Activate autocomplete functionality for the specified field
1616 (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+
1740 jQuery.fn.attachAutocomplete = function() {
1841 return this.each(function() {
1942 // Get all the necessary values from the input's "autocompletesettings"
@@ -29,22 +52,6 @@
3053 }
3154 }
3255
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 -
4956 // Modify the delimiter. If it's "\n", change it to an actual
5057 // newline - otherwise, add a space to the end.
5158 // This doesn't cover the case of a delimiter that's a newline
@@ -57,6 +64,9 @@
5865 delimiter += " ";
5966 }
6067 }
 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;
6171
6272 /* extending jquery functions */
6373 jQuery.extend( jQuery.ui.autocomplete, {