aboutsummaryrefslogtreecommitdiffstats
path: root/themes
diff options
context:
space:
mode:
authormistic100 <mistic@piwigo.org>2013-06-15 15:45:41 +0000
committermistic100 <mistic@piwigo.org>2013-06-15 15:45:41 +0000
commit7850d828d83d54675ae5d54e0f96114c66059c42 (patch)
treec6fd029b289267c24d288d075190ddd8d5b3509c /themes
parent4afb44fa21f893e83030c10d9afd7304c5f397b5 (diff)
Merged revision(s) 23231 from trunk:
feature:2922 Add caseSensitive option to TokenInput (false by default) git-svn-id: http://piwigo.org/svn/branches/2.5@23232 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'themes')
-rw-r--r--themes/default/js/plugins/jquery.tokeninput.js21
1 files changed, 16 insertions, 5 deletions
diff --git a/themes/default/js/plugins/jquery.tokeninput.js b/themes/default/js/plugins/jquery.tokeninput.js
index c36a864f2..0bbf8336b 100644
--- a/themes/default/js/plugins/jquery.tokeninput.js
+++ b/themes/default/js/plugins/jquery.tokeninput.js
@@ -38,7 +38,8 @@ var DEFAULT_SETTINGS = {
onResult: null,
onAdd: null,
onDelete: null,
- allowCreation: false
+ allowCreation: false,
+ caseSensitive: false
};
// Default classes to use when theming
@@ -576,7 +577,9 @@ $.TokenList = function (input, url_or_data, settings) {
// Highlight the query part of the search term
function highlight_term(value, term) {
- return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + escape_regexp_chars(term) + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<b>$1</b>");
+ var param = "g";
+ if (!settings.caseSensitive) param+= "i";
+ return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + escape_regexp_chars(term) + ")(?![^<>]*>)(?![^&;]+;)", param), "<b>$1</b>");
}
function escape_regexp_chars(string) {
@@ -652,7 +655,8 @@ $.TokenList = function (input, url_or_data, settings) {
// Do a search and show the "searching" dropdown if the input is longer
// than settings.minChars
function do_search() {
- var query = input_box.val().toLowerCase();
+ var query = input_box.val();
+ if (!settings.caseSensitive) query = query.toLowerCase();
if(query && query.length) {
if(selected_token) {
@@ -716,7 +720,9 @@ $.TokenList = function (input, url_or_data, settings) {
cache.add(query, settings.jsonContainer ? results[settings.jsonContainer] : results);
// only populate the dropdown if the results are associated with the active search query
- if(input_box.val().toLowerCase() === query) {
+ var value = input_box.val();
+ if (!settings.caseSensitive) value = value.toLowerCase();
+ if(value === query) {
populate_dropdown(query, settings.jsonContainer ? results[settings.jsonContainer] : results);
}
};
@@ -726,7 +732,12 @@ $.TokenList = function (input, url_or_data, settings) {
} else if(settings.local_data) {
// Do the search through local data
var results = $.grep(settings.local_data, function (row) {
- return row.name.toLowerCase().indexOf(query.toLowerCase()) > -1;
+ if (settings.caseSensitive) {
+ return row.name.indexOf(query) > -1;
+ }
+ else {
+ return row.name.toLowerCase().indexOf(query.toLowerCase()) > -1;
+ }
});
if($.isFunction(settings.onResult)) {