Mark Lavin avatar Mark Lavin committed d270705

Label formatting callback function support. See #35.

Comments (0)

Files changed (1)

selectable/static/selectable/js/jquery.dj.selectable.js

         options: {
             removeIcon: "ui-icon-close",
             comboboxIcon: "ui-icon-triangle-1-s",
-            prepareQuery: null
+            prepareQuery: null,
+            highlightMatch: true,
+            formatLabel: null
         },
         
         _initDeck: function(hiddenInputs) {
                 }
             }).addClass("ui-widget ui-widget-content ui-corner-all");
             $(input).data("autocomplete")._renderItem = function(ul, item) {
-                var re = new RegExp("(?![^&;]+;)(?!<[^<>]*)(" +
-                $.ui.autocomplete.escapeRegex(this.term) +
-                ")(?![^<>]*>)(?![^&;]+;)", "gi");
-                var label = item.label.replace(re, "<span class='highlight'>$1</span>");
+                var label = item.label;
+                if (self.options.formatLabel) {
+                    label = self.options.formatLabel(label, item);
+                }
+                if (self.options.highlightMatch) {
+                    var re = new RegExp("(?![^&;]+;)(?!<[^<>]*)(" +
+                    $.ui.autocomplete.escapeRegex(this.term) +
+                    ")(?![^<>]*>)(?![^&;]+;)", "gi");
+                    label = label.replace(re, "<span class='highlight'>$1</span>");
+                }
                 var li =  $("<li></li>")
 			        .data("item.autocomplete", item)
-			        .append($("<a></a>").html(label))
+			        .append($("<a></a>").append(label))
 			        .appendTo(ul);
                 if (item.page) {
                     li.addClass('selectable-paginator');
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.