forked from maccman/holla
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.js
More file actions
63 lines (50 loc) · 1.27 KB
/
Copy pathsearch.js
File metadata and controls
63 lines (50 loc) · 1.27 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var Search = Spine.Class.create();
Search.include(Spine.Events);
Search.models = [];
Search.Model = {
extended: function(){
Search.models.push(this);
}
};
Search.Record = Spine.Class.create({
init: function(value, record){
this.value = value;
this.record = record;
},
reload: function(){
return this;
}
});
Search.include({
init: function(){
this.proxyAll("queryModel", "queryRecord");
this.results = [];
},
query: function(params){
this.clear();
if ( !params ) return;
this.params = params.toLowerCase();
this.parent.models.forEach(this.queryModel);
this.trigger("change");
},
clear: function(){
this.results = [];
this.trigger("change");
},
each: function(callback){
this.results.forEach(callback);
},
// Private
queryModel: function(model){
var each = model.search_each || model.each;
each.call(model, this.queryRecord);
},
queryRecord: function(record) {
var attributes = (record.search_attributes || record.attributes).apply(record);
for (var key in attributes) {
var value = (attributes[key] + "").toLowerCase();
if (value.indexOf(this.params) != -1)
this.results.push(Search.Record.init(value, record));
}
}
});