Skip to content
This repository was archived by the owner on Sep 10, 2023. It is now read-only.

Commit 4ef6c21

Browse files
committed
Break out settings object into more readable thing
1 parent b7b489d commit 4ef6c21

File tree

1 file changed

+26
-29
lines changed

1 file changed

+26
-29
lines changed

src/jquery.tokeninput.js

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,43 @@
1111
(function ($) {
1212
// Default settings
1313
var DEFAULT_SETTINGS = {
14-
// Search settings
14+
// Search settings
1515
method: "GET",
16-
contentType: "json",
1716
queryParam: "q",
1817
searchDelay: 300,
1918
minChars: 1,
2019
propertyToSearch: "name",
2120
jsonContainer: null,
21+
contentType: "json",
2222

23-
// Display settings
23+
// Prepopulation settings
24+
prePopulate: null,
25+
processPrePopulate: false,
26+
27+
// Display settings
2428
hintText: "Type in a search term",
2529
noResultsText: "No results",
2630
searchingText: "Searching...",
2731
deleteText: "×",
2832
animateDropdown: true,
33+
theme: null,
34+
resultsFormatter: function(item){ return "<li>" + item[this.propertyToSearch]+ "</li>" },
35+
tokenFormatter: function(item) { return "<li><p>" + item[this.propertyToSearch] + "</p></li>" },
2936

30-
// Tokenization settings
37+
// Tokenization settings
3138
tokenLimit: null,
3239
tokenDelimiter: ",",
3340
preventDuplicates: false,
34-
35-
// Output settings
3641
tokenValue: "id",
3742

38-
// Prepopulation settings
39-
prePopulate: null,
40-
processPrePopulate: false,
41-
42-
// Manipulation settings
43-
idPrefix: "token-input-",
44-
45-
// Formatters
46-
resultsFormatter: function(item){ return "<li>" + item[this.propertyToSearch]+ "</li>" },
47-
tokenFormatter: function(item) { return "<li><p>" + item[this.propertyToSearch] + "</p></li>" },
48-
49-
// Callbacks
43+
// Callbacks
5044
onResult: null,
5145
onAdd: null,
5246
onDelete: null,
53-
onReady: null
47+
onReady: null,
48+
49+
// Other settings
50+
idPrefix: "token-input-"
5451
};
5552

5653
// Default classes to use when theming
@@ -115,8 +112,8 @@ var methods = {
115112
return this;
116113
},
117114
get: function() {
118-
return this.data("tokenInputObject").getTokens();
119-
}
115+
return this.data("tokenInputObject").getTokens();
116+
}
120117
}
121118

122119
// Expose the .tokenInput function to jQuery as a plugin
@@ -412,10 +409,10 @@ $.TokenList = function (input, url_or_data, settings) {
412409
}
413410
});
414411
}
415-
412+
416413
this.getTokens = function() {
417-
return saved_tokens;
418-
}
414+
return saved_tokens;
415+
}
419416

420417
//
421418
// Private functions
@@ -656,7 +653,7 @@ $.TokenList = function (input, url_or_data, settings) {
656653
function highlight_term(value, term) {
657654
return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<b>$1</b>");
658655
}
659-
656+
660657
function find_value_and_highlight_term(template, value, term) {
661658
return template.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + value + ")(?![^<>]*>)(?![^&;]+;)", "g"), highlight_term(value, term));
662659
}
@@ -679,11 +676,11 @@ $.TokenList = function (input, url_or_data, settings) {
679676

680677
$.each(results, function(index, value) {
681678
var this_li = settings.resultsFormatter(value);
682-
683-
this_li = find_value_and_highlight_term(this_li ,value[settings.propertyToSearch], query);
684-
679+
680+
this_li = find_value_and_highlight_term(this_li ,value[settings.propertyToSearch], query);
681+
685682
this_li = $(this_li).appendTo(dropdown_ul);
686-
683+
687684
if(index % 2) {
688685
this_li.addClass(settings.classes.dropdownItem);
689686
} else {

0 commit comments

Comments
 (0)