-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
188 lines (149 loc) · 4.5 KB
/
test.js
File metadata and controls
188 lines (149 loc) · 4.5 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
* Stubbed Content for Demo
*/
var items = [
{"id": "1", "body": "this is sparta", "html": "<li style=\"background-color: #779ECB;\">this is sparta</li>"},
{"id": "2", "body": "this is rome", "html": "<li style=\"background-color: #FFB347;\">this is rome</li>"},
{"id": "3", "body": "this is greece", "html": "<li style=\"background-color: #966FD6;\">this is greece</li>"},
{"id": "4", "body": "this is persia", "html": "<li style=\"background-color: #C23B22;\">this is persia</li>"},
{"id": "5", "body": "this is canadia", "html": "<li style=\"background-color: #990000;\">this is canadia</li>"},
{"id": "6", "body": "this is 'merica", "html": "<li style=\"background-color: #03C03C;\">this is 'merica</li>"}
];
/*
* Models & Collections
*/
var Item = Backbone.Model.extend({
});
var Items = Backbone.Collection.extend({
model: Item,
fetch: function(options){
var results = [];
var search = options.data.s;
_.each(items, function(item) {
if(item.body.indexOf(search) != -1) {
results.push(item);
}
});
if (search == "") {
results = items;
}
this.set(results);
}
});
var InfiniteItems = Backbone.Collection.extend({
model: Item,
fetch: _.debounce(function(options) {
var collection = this;
var offset = options.data.offset;
var limit = options.data.limit;
var addition = items.slice(offset, (offset+limit));
this.add(addition);
if (this.length >= items.length) {
return 'end_of_list';
}
}, 1500)
});
/* STANDARD USE DEMO */
/*
* Views
*/
var ItemView = Flunkybone.ModelView.extend({
initialize: function() {
_.bindObj(this);
}
});
var ItemsView = Flunkybone.CollectionView.extend({
modelView: ItemView,
initialize: function() {
_.bindObj(this);
}
});
/* Vars */
var items_collection = new Items();
var items_el = $(".items");
var items_collection_view = new ItemsView({
'collection': items_collection,
'el': items_el
});
_.each(items, function(item, i) {
window.setTimeout(function() {
items_collection.add(item);
}, i * 110);
});
/* FILTERABLE USE DEMO */
/*
* Views
*/
var FilterableItemView = Flunkybone.ModelView.extend({
initialize: function() {
_.bindObj(this);
}
});
var FilterableItemsView = Flunkybone.CollectionView.extend({
modelView: FilterableItemView,
initialize: function() {
_.bindObj(this);
/* Cached Elements */
this.items_el = this.$el.find('.filterable_items');
this.input_el = $(".search_filterable_items");
/* Subviews */
this.live_filter_items = new Flunkybone.FilterableCollectionView({
'el': this.items_el,
'collection': this.collection,
'input_el': this.input_el
});
}
});
/* Vars */
var filterable_items_collection = new Items();
var filterable_items_el = $(".filterable_items");
var filterable_items_collection_view = new FilterableItemsView({
'collection': filterable_items_collection,
'el': filterable_items_el
});
_.each(items, function(item, i) {
window.setTimeout(function() {
filterable_items_collection.add(item);
}, i);
});
/* INFINITE SCROLL DEMO */
/*
* Views
*/
var InfiniteItemView = Flunkybone.ModelView.extend({
initialize: function() {
_.bindObj(this);
}
});
var InfiniteItemsView = Flunkybone.CollectionView.extend({
modelView: InfiniteItemView,
initialize: function() {
_.bindObj(this);
/* Cached Elements */
this.items_el = this.$el;
this.scroll_el = $('.load_more');
/* Subviews */
this.infinite_items = new Flunkybone.InfiniteCollectionView({
'el': this.items_el,
'collection': this.collection,
'limit': 2,
'end_of_list_el': this.items_el.find('.end'),
'scroll_el': this.scroll_el,
'scroll_el_bottom_margin': 40,
'scroll_text_el': this.scroll_el.find('.text'),
'scroll_spinner_el': this.scroll_el.find('.spinner_gif')
});
}
});
/* Vars */
var infinite_items_collection = new InfiniteItems();
var infinite_items_el = $(".infinite_items");
var infinite_items_collection_view = new InfiniteItemsView({
'collection': infinite_items_collection,
'el': infinite_items_el
});
_.each(items.slice(0,2), function(item, i) {
window.setTimeout(function() {
infinite_items_collection.add(item);
}, i);
});