forked from select2/select2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.js
More file actions
45 lines (41 loc) · 1.36 KB
/
Copy pathdata.js
File metadata and controls
45 lines (41 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(function ($, document, window, undefined) {
var s2 = window.s2 = window.s2 || {};
var data = s2.data = s2.data || {};
var util=s2.util;
data.local = util.clazz(Object, {
construct: function (select) {
this.select = select;
},
lookup: function () {
var data = [], self = this;
this.select.find(":selected").each(function () {
data.push(self.item($(this)));
});
return data;
},
query: function (params) {
var data = [], self = this;
self.select.find("option").each(function () {
var option = $(this);
if (self.matches(params, option)) {
data.push(self.item($(this)));
}
});
return data;
},
matches: function (params, option) {
if (params && params.term) {
var text = option.text().toUpperCase();
if (text.indexOf(params.term.toUpperCase()) >= 0) {
return true;
} else {
return false;
}
}
return true;
},
item: function (option) {
return {value: option.attr("value"), text: option.text(), element: option.get(0)};
}
});
})(jQuery, document, window);