Changeset 23232 for branches/2.5/themes


Ignore:
Timestamp:
Jun 15, 2013, 5:45:41 PM (11 years ago)
Author:
mistic100
Message:

Merged revision(s) 23231 from trunk:
feature:2922 Add caseSensitive option to TokenInput (false by default)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.5/themes/default/js/plugins/jquery.tokeninput.js

    r23230 r23232  
    3939    onAdd: null,
    4040    onDelete: null,
    41     allowCreation: false
     41    allowCreation: false,
     42    caseSensitive: false
    4243};
    4344
     
    577578    // Highlight the query part of the search term
    578579    function highlight_term(value, term) {
    579         return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + escape_regexp_chars(term) + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<b>$1</b>");
     580        var param = "g";
     581        if (!settings.caseSensitive) param+= "i";
     582        return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + escape_regexp_chars(term) + ")(?![^<>]*>)(?![^&;]+;)", param), "<b>$1</b>");
    580583    }
    581584   
     
    653656    // than settings.minChars
    654657    function do_search() {
    655         var query = input_box.val().toLowerCase();
     658        var query = input_box.val();
     659        if (!settings.caseSensitive) query = query.toLowerCase();
    656660
    657661        if(query && query.length) {
     
    717721
    718722                  // only populate the dropdown if the results are associated with the active search query
    719                   if(input_box.val().toLowerCase() === query) {
     723                  var value = input_box.val();
     724                  if (!settings.caseSensitive) value = value.toLowerCase();
     725                  if(value === query) {
    720726                      populate_dropdown(query, settings.jsonContainer ? results[settings.jsonContainer] : results);
    721727                  }
     
    727733                // Do the search through local data
    728734                var results = $.grep(settings.local_data, function (row) {
    729                     return row.name.toLowerCase().indexOf(query.toLowerCase()) > -1;
     735                    if (settings.caseSensitive) {
     736                        return row.name.indexOf(query) > -1;
     737                    }
     738                    else {
     739                        return row.name.toLowerCase().indexOf(query.toLowerCase()) > -1;
     740                    }
    730741                });
    731742
Note: See TracChangeset for help on using the changeset viewer.