livelist-rails 0.0.12 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,328 +1,375 @@
1
- (function() {
2
- var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
3
- __hasProp = Object.prototype.hasOwnProperty,
4
- __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
1
+ // ------ lib/utilities.js -------
2
+ // Generated by CoffeeScript 1.4.0
3
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
5
4
 
6
- window.Utilities = (function() {
5
+ window.Utilities = (function() {
7
6
 
8
- function Utilities() {
9
- this.setOptions = __bind(this.setOptions, this);
10
- }
11
-
12
- Utilities.prototype.setOptions = function(options, context) {
13
- var _this = this;
14
- if (context == null) context = this;
15
- return _.each(options, function(value, option) {
16
- return context[option] = value;
17
- });
18
- };
19
-
20
- return Utilities;
21
-
22
- })();
7
+ function Utilities() {
8
+ this.setOptions = __bind(this.setOptions, this);
23
9
 
24
- window.LiveList = (function(_super) {
10
+ }
25
11
 
26
- __extends(LiveList, _super);
27
-
28
- function LiveList(options) {
29
- this.listSelector = options.list.renderTo;
30
- this.resourceName = options.global.resourceName;
31
- this.resourceNameSingular = options.global.resourceNameSingular;
32
- this.urlPrefix = options.global.urlPrefix || ("/" + this.resourceName);
33
- this.httpMethod = options.global.httpMethod || 'get';
34
- this.eventName = "livelist:" + this.resourceName;
35
- this.search = new Search(options.search, this);
36
- this.filters = new Filters(options.filters, this);
37
- this.pagination = new Pagination(options.pagination, this);
38
- this.list = new List(options.list, this);
12
+ Utilities.prototype.setOptions = function(options, context) {
13
+ var _this = this;
14
+ if (context == null) {
15
+ context = this;
39
16
  }
40
-
41
- return LiveList;
42
-
43
- })(Utilities);
44
-
45
- window.List = (function(_super) {
46
-
47
- __extends(List, _super);
48
-
49
- function List(options, livelist) {
50
- this.renderIndex = __bind(this.renderIndex, this);
51
- this.removeFetchingIndication = __bind(this.removeFetchingIndication, this);
52
- this.displayFetchingIndication = __bind(this.displayFetchingIndication, this);
53
- var _this = this;
54
- this.fetchRequest = null;
55
- this.livelist = livelist;
56
- this.listTemplate = "{{#" + this.livelist.resourceName + "}}{{>" + this.livelist.resourceNameSingular + "}}{{/" + this.livelist.resourceName + "}}";
57
- this.listItemTemplate = '<li>{{id}}</li>';
58
- this.fetchingIndicationClass = 'updating';
59
- this.renderTo = "ul#" + this.livelist.resourceName;
60
- this.setOptions(options);
61
- $(this.renderTo).bind(this.livelist.eventName, function(event, params) {
62
- return _this.fetch({
63
- presets: null,
64
- page: params != null ? params.page : void 0
65
- });
66
- });
67
- this.fetch({
68
- presets: this.livelist.filters.getPresets()
17
+ return _.each(options, function(value, option) {
18
+ return context[option] = value;
19
+ });
20
+ };
21
+
22
+ return Utilities;
23
+
24
+ })();
25
+
26
+ // ------ lib/livelist.js -------
27
+ // Generated by CoffeeScript 1.4.0
28
+ var __hasProp = {}.hasOwnProperty,
29
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
30
+
31
+ window.LiveList = (function(_super) {
32
+
33
+ __extends(LiveList, _super);
34
+
35
+ function LiveList(options) {
36
+ this.listSelector = options.list.renderTo;
37
+ this.resourceName = options.global.resourceName;
38
+ this.resourceNameSingular = options.global.resourceNameSingular;
39
+ this.urlPrefix = options.global.urlPrefix || ("/" + this.resourceName);
40
+ this.httpMethod = options.global.httpMethod || 'get';
41
+ this.eventName = "livelist:" + this.resourceName;
42
+ this.search = new Search(options.search, this);
43
+ this.filters = new Filters(options.filters, this);
44
+ this.pagination = new Pagination(options.pagination, this);
45
+ this.list = new List(options.list, this);
46
+ }
47
+
48
+ return LiveList;
49
+
50
+ })(Utilities);
51
+
52
+ // ------ lib/list.js -------
53
+ // Generated by CoffeeScript 1.4.0
54
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
55
+ __hasProp = {}.hasOwnProperty,
56
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
57
+
58
+ window.List = (function(_super) {
59
+
60
+ __extends(List, _super);
61
+
62
+ function List(options, livelist) {
63
+ this.renderIndex = __bind(this.renderIndex, this);
64
+
65
+ this.removeFetchingIndication = __bind(this.removeFetchingIndication, this);
66
+
67
+ this.displayFetchingIndication = __bind(this.displayFetchingIndication, this);
68
+
69
+ var _this = this;
70
+ this.fetchRequest = null;
71
+ this.livelist = livelist;
72
+ this.listTemplate = "{{#" + this.livelist.resourceName + "}}{{>" + this.livelist.resourceNameSingular + "}}{{/" + this.livelist.resourceName + "}}";
73
+ this.listItemTemplate = '<li>{{id}}</li>';
74
+ this.fetchingIndicationClass = 'updating';
75
+ this.renderTo = "ul#" + this.livelist.resourceName;
76
+ this.setOptions(options);
77
+ $(this.renderTo).bind(this.livelist.eventName, function(event, params) {
78
+ return _this.fetch({
79
+ presets: null,
80
+ page: params != null ? params.page : void 0
69
81
  });
82
+ });
83
+ this.fetch({
84
+ presets: this.livelist.filters.getPresets()
85
+ });
86
+ }
87
+
88
+ List.prototype.displayFetchingIndication = function() {
89
+ return $(this.renderTo).addClass(this.fetchingIndicationClass);
90
+ };
91
+
92
+ List.prototype.removeFetchingIndication = function() {
93
+ return $(this.renderTo).removeClass(this.fetchingIndicationClass);
94
+ };
95
+
96
+ List.prototype.renderIndex = function(data, textStatus, jqXHR) {
97
+ this.livelist.data = data;
98
+ this.render();
99
+ this.livelist.pagination.render(this.livelist.data);
100
+ return this.livelist.filters.render(this.livelist.data);
101
+ };
102
+
103
+ List.prototype.fetch = function(options) {
104
+ var params, searchTerm;
105
+ if (this.fetchRequest) {
106
+ this.fetchRequest.abort();
70
107
  }
71
-
72
- List.prototype.displayFetchingIndication = function() {
73
- return $(this.renderTo).addClass(this.fetchingIndicationClass);
74
- };
75
-
76
- List.prototype.removeFetchingIndication = function() {
77
- return $(this.renderTo).removeClass(this.fetchingIndicationClass);
78
- };
79
-
80
- List.prototype.renderIndex = function(data, textStatus, jqXHR) {
81
- this.livelist.data = data;
82
- this.render();
83
- this.livelist.pagination.render(this.livelist.data);
84
- return this.livelist.filters.render(this.livelist.data);
85
- };
86
-
87
- List.prototype.fetch = function(options) {
88
- var params, searchTerm;
89
- if (this.fetchRequest) this.fetchRequest.abort();
90
- searchTerm = this.livelist.search.searchTerm();
91
- params = {};
92
- params.filters = this.livelist.filters.setPresets(options.presets);
93
- if (searchTerm) params.q = searchTerm;
94
- if (options.page) params.page = options.page;
95
- return this.fetchRequest = $.ajax({
96
- url: this.livelist.urlPrefix,
97
- type: this.livelist.httpMethod,
98
- dataType: 'json',
99
- data: params,
100
- beforeSend: this.displayFetchingIndication,
101
- success: this.renderIndex
102
- });
103
- };
104
-
105
- List.prototype.render = function() {
106
- var listHTML, partials;
107
- partials = {};
108
- partials[this.livelist.resourceNameSingular] = this.listItemTemplate;
109
- listHTML = Mustache.to_html(this.listTemplate, this.livelist.data, partials);
110
- $(this.renderTo).html(listHTML);
111
- return this.removeFetchingIndication();
112
- };
113
-
114
- return List;
115
-
116
- })(Utilities);
117
-
118
- window.LiveList.version = '0.0.7';
119
-
120
- window.Filters = (function(_super) {
121
-
122
- __extends(Filters, _super);
123
-
124
- function Filters(options, livelist) {
125
- this.handleAdvancedOptionsClick = __bind(this.handleAdvancedOptionsClick, this);
126
- var _this = this;
127
- this.livelist = livelist;
128
- this.filters = options.presets ? _.keys(options.presets) : [];
129
- this.initializeCookies();
130
- this.setOptions(options);
131
- $('input.filter_option', this.renderTo).live('change', function() {
132
- return $(_this.livelist.listSelector).trigger(_this.livelist.eventName);
133
- });
134
- $(this.advancedOptionsToggleSelector).click(this.handleAdvancedOptionsClick);
108
+ searchTerm = this.livelist.search.searchTerm();
109
+ params = {};
110
+ params.filters = this.livelist.filters.setPresets(options.presets);
111
+ if (searchTerm) {
112
+ params.q = searchTerm;
135
113
  }
114
+ if (options.page) {
115
+ params.page = options.page;
116
+ }
117
+ return this.fetchRequest = $.ajax({
118
+ url: this.livelist.urlPrefix,
119
+ type: this.livelist.httpMethod,
120
+ dataType: 'json',
121
+ data: params,
122
+ beforeSend: this.displayFetchingIndication,
123
+ success: this.renderIndex
124
+ });
125
+ };
126
+
127
+ List.prototype.render = function() {
128
+ var listHTML, partials;
129
+ partials = {};
130
+ partials[this.livelist.resourceNameSingular] = this.listItemTemplate;
131
+ listHTML = Mustache.to_html(this.listTemplate, this.livelist.data, partials);
132
+ $(this.renderTo).html(listHTML);
133
+ return this.removeFetchingIndication();
134
+ };
135
+
136
+ return List;
137
+
138
+ })(Utilities);
139
+
140
+ // ------ lib/version.js -------
141
+ // Generated by CoffeeScript 1.4.0
142
+
143
+ window.LiveList.version = '0.0.9';
144
+
145
+ // ------ lib/filters.js -------
146
+ // Generated by CoffeeScript 1.4.0
147
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
148
+ __hasProp = {}.hasOwnProperty,
149
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
150
+
151
+ window.Filters = (function(_super) {
152
+
153
+ __extends(Filters, _super);
154
+
155
+ function Filters(options, livelist) {
156
+ this.handleAdvancedOptionsClick = __bind(this.handleAdvancedOptionsClick, this);
157
+
158
+ var _this = this;
159
+ this.livelist = livelist;
160
+ this.filters = options.presets ? _.keys(options.presets) : [];
161
+ this.initializeCookies();
162
+ this.setOptions(options);
163
+ $('input.filter_option', this.renderTo).live('change', function() {
164
+ return $(_this.livelist.listSelector).trigger(_this.livelist.eventName);
165
+ });
166
+ $(this.advancedOptionsToggleSelector).click(this.handleAdvancedOptionsClick);
167
+ }
168
+
169
+ Filters.prototype.initializeCookies = function() {
170
+ if (jQuery.cookie && this.useCookies && this.cookieName) {
171
+ return this.cookieName = 'livelist_filter_presets';
172
+ }
173
+ };
136
174
 
137
- Filters.prototype.initializeCookies = function() {
138
- if (jQuery.cookie && this.useCookies && this.cookieName) {
139
- return this.cookieName = 'livelist_filter_presets';
140
- }
141
- };
142
-
143
- Filters.prototype.getPresets = function() {
144
- var cookie;
145
- if (jQuery.cookie && this.useCookies) {
146
- cookie = jQuery.cookie(this.cookieName);
147
- }
148
- if (this.useCookies && cookie) {
149
- return JSON.parse(cookie);
150
- } else {
151
- return this.presets;
152
- }
153
- };
154
-
155
- Filters.prototype.setPresets = function(presets) {
156
- var filters;
157
- filters = {};
158
- if (jQuery.isEmptyObject(presets)) {
159
- filters = this.selections();
160
- if (jQuery.cookie) this.setCookie(filters);
161
- } else {
162
- filters = presets;
163
- }
164
- return filters;
165
- };
166
-
167
- Filters.prototype.setCookie = function(params_filters) {
168
- if (!jQuery.isEmptyObject(params_filters)) {
169
- return jQuery.cookie(this.cookieName, JSON.stringify(params_filters));
175
+ Filters.prototype.getPresets = function() {
176
+ var cookie;
177
+ if (jQuery.cookie && this.useCookies) {
178
+ cookie = jQuery.cookie(this.cookieName);
179
+ }
180
+ if (this.useCookies && cookie) {
181
+ return JSON.parse(cookie);
182
+ } else {
183
+ return this.presets;
184
+ }
185
+ };
186
+
187
+ Filters.prototype.setPresets = function(presets) {
188
+ var filters;
189
+ filters = {};
190
+ if (jQuery.isEmptyObject(presets)) {
191
+ filters = this.selections();
192
+ if (jQuery.cookie) {
193
+ this.setCookie(filters);
170
194
  }
171
- };
172
-
173
- Filters.prototype.template = '{{#filters}}\n<div class=\'filter\'>\n <h3>\n {{name}}\n </h3>\n <ul id=\'{{filter_slug}}_filter_options\'>\n {{#options}}\n <label>\n <li>\n <input {{#selected}}checked=\'checked\'{{/selected}}\n class=\'left filter_option\'\n id=\'filter_{{slug}}\'\n name=\'filters[]\'\n type=\'checkbox\'\n value=\'{{value}}\' />\n <div class=\'left filter_name\'>{{name}}</div>\n <div class=\'right filter_count\'>{{count}}</div>\n <div class=\'clear\'></div>\n </li>\n </label>\n {{/options}}\n </ul>\n</div>\n{{/filters}}';
174
-
175
- Filters.prototype.selections = function() {
176
- var filters,
177
- _this = this;
178
- filters = {};
179
- _.each(this.filters, function(filter) {
180
- return filters[filter] = _.pluck($("#" + filter + "_filter_options input.filter_option:checked"), 'value');
181
- });
182
- return filters;
183
- };
184
-
185
- Filters.prototype.noFiltersSelected = function(data) {
186
- return _.all(data.filters, function(filter) {
187
- return _.all(filter.options, function(option) {
188
- return !option.selected;
189
- });
190
- });
191
- };
195
+ } else {
196
+ filters = presets;
197
+ }
198
+ return filters;
199
+ };
192
200
 
193
- Filters.prototype.sortOptions = function(filters) {
194
- return _.map(filters, function(filter) {
195
- filter.options = _.sortBy(filter.options, function(option) {
196
- return option.name;
197
- });
198
- return filter;
201
+ Filters.prototype.setCookie = function(params_filters) {
202
+ if (!jQuery.isEmptyObject(params_filters)) {
203
+ return jQuery.cookie(this.cookieName, JSON.stringify(params_filters));
204
+ }
205
+ };
206
+
207
+ Filters.prototype.template = '{{#filters}}\n<div class=\'filter\'>\n <h3>\n {{name}}\n </h3>\n <ul id=\'{{filter_slug}}_filter_options\'>\n {{#options}}\n <label>\n <li>\n <input {{#selected}}checked=\'checked\'{{/selected}}\n class=\'left filter_option\'\n id=\'filter_{{slug}}\'\n name=\'filters[]\'\n type=\'checkbox\'\n value=\'{{value}}\' />\n <div class=\'left filter_name\'>{{name}}</div>\n <div class=\'right filter_count\'>{{count}}</div>\n <div class=\'clear\'></div>\n </li>\n </label>\n {{/options}}\n </ul>\n</div>\n{{/filters}}';
208
+
209
+ Filters.prototype.selections = function() {
210
+ var filters,
211
+ _this = this;
212
+ filters = {};
213
+ _.each(this.filters, function(filter) {
214
+ return filters[filter] = _.pluck($("#" + filter + "_filter_options input.filter_option:checked"), 'value');
215
+ });
216
+ return filters;
217
+ };
218
+
219
+ Filters.prototype.noFiltersSelected = function(data) {
220
+ return _.all(data.filters, function(filter) {
221
+ return _.all(filter.options, function(option) {
222
+ return !option.selected;
199
223
  });
200
- };
224
+ });
225
+ };
201
226
 
202
- Filters.prototype.sort = function(filters) {
203
- return _.sortBy(filters, function(filter) {
204
- return filter.name;
227
+ Filters.prototype.sortOptions = function(filters) {
228
+ return _.map(filters, function(filter) {
229
+ filter.options = _.sortBy(filter.options, function(option) {
230
+ return option.name;
205
231
  });
206
- };
207
-
208
- Filters.prototype.render = function(data) {
209
- var filtersHTML;
210
- this.filters = _.pluck(data.filters, 'filter_slug');
211
- this.sort(data.filters);
212
- this.sortOptions(data.filters);
213
- filtersHTML = Mustache.to_html(this.template, data);
214
- $(this.renderTo).html(filtersHTML);
215
- if (this.noFiltersSelected(data) && data[this.livelist.resourceName].length > 0) {
216
- return $('input[type="checkbox"]', this.renderTo).attr('checked', 'checked');
217
- }
218
- };
219
-
220
- Filters.prototype.handleAdvancedOptionsClick = function(event) {
221
- event.preventDefault();
222
- return $(this.renderTo).slideToggle();
223
- };
224
-
225
- return Filters;
226
-
227
- })(Utilities);
228
-
229
- window.Pagination = (function(_super) {
230
-
231
- __extends(Pagination, _super);
232
-
233
- function Pagination(options, livelist) {
234
- this.handlePaginationLinkClick = __bind(this.handlePaginationLinkClick, this); this.livelist = livelist;
235
- this.pagination = null;
236
- this.maxPages = 30;
237
- this.emptyListMessage = "<p>No " + this.livelist.resourceName + " matched your filter criteria</p>";
238
- this.setOptions(options);
239
- $("" + this.renderTo + " a").live('click', function(event) {
240
- return event.preventDefault();
241
- });
242
- $("" + this.renderTo + " li:not(.disabled) a").live('click', this.handlePaginationLinkClick);
232
+ return filter;
233
+ });
234
+ };
235
+
236
+ Filters.prototype.sort = function(filters) {
237
+ return _.sortBy(filters, function(filter) {
238
+ return filter.name;
239
+ });
240
+ };
241
+
242
+ Filters.prototype.render = function(data) {
243
+ var filtersHTML;
244
+ this.filters = _.pluck(data.filters, 'filter_slug');
245
+ this.sort(data.filters);
246
+ this.sortOptions(data.filters);
247
+ filtersHTML = Mustache.to_html(this.template, data);
248
+ $(this.renderTo).html(filtersHTML);
249
+ if (this.noFiltersSelected(data) && data[this.livelist.resourceName].length > 0) {
250
+ return $('input[type="checkbox"]', this.renderTo).attr('checked', 'checked');
243
251
  }
244
-
245
- Pagination.prototype.template = '{{#isEmpty}}\n {{{emptyListMessage}}}\n{{/isEmpty}}\n{{^isEmpty}}\n<div class="pagination">\n <ul>\n <li class="{{^previousPage}}disabled{{/previousPage}}">\n <a href=\'{{urlPrefix}}?page={{previousPage}}\' data-page=\'{{previousPage}}\'>← Previous</a>\n </li>\n\n {{#pages}}\n <li class="{{#currentPage}}active disabled{{/currentPage}}">\n <a href=\'{{urlPrefix}}?page={{page}}\' data-page=\'{{page}}\'>{{page}}</a>\n </li>\n {{/pages}}\n\n <li class="{{^nextPage}}disabled{{/nextPage}}">\n <a href=\'{{urlPrefix}}?page={{nextPage}}\' data-page=\'{{nextPage}}\'>Next →</a>\n </li>\n </ul>\n</div>\n{{/isEmpty}}';
246
-
247
- Pagination.prototype.pagesJSON = function(currentPage, totalPages) {
248
- var firstPage, groupSize, lastPage, previousPage, _i, _results;
249
- groupSize = Math.floor(this.maxPages / 2);
250
- firstPage = currentPage <= groupSize ? 1 : currentPage - groupSize;
251
- previousPage = firstPage + groupSize * 2 - 1;
252
- lastPage = previousPage >= totalPages ? totalPages : previousPage;
253
- return _.map((function() {
254
- _results = [];
255
- for (var _i = firstPage; firstPage <= lastPage ? _i <= lastPage : _i >= lastPage; firstPage <= lastPage ? _i++ : _i--){ _results.push(_i); }
256
- return _results;
257
- }).apply(this), function(page) {
258
- return {
259
- page: page,
260
- currentPage: currentPage === page
261
- };
262
- });
263
- };
264
-
265
- Pagination.prototype.paginationJSON = function(pagination) {
252
+ };
253
+
254
+ Filters.prototype.handleAdvancedOptionsClick = function(event) {
255
+ event.preventDefault();
256
+ return $(this.renderTo).slideToggle();
257
+ };
258
+
259
+ return Filters;
260
+
261
+ })(Utilities);
262
+
263
+ // ------ lib/pagination.js -------
264
+ // Generated by CoffeeScript 1.4.0
265
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
266
+ __hasProp = {}.hasOwnProperty,
267
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
268
+
269
+ window.Pagination = (function(_super) {
270
+
271
+ __extends(Pagination, _super);
272
+
273
+ function Pagination(options, livelist) {
274
+ this.handlePaginationLinkClick = __bind(this.handlePaginationLinkClick, this);
275
+ this.livelist = livelist;
276
+ this.pagination = null;
277
+ this.maxPages = 30;
278
+ this.emptyListMessage = "<p>No " + this.livelist.resourceName + " matched your filter criteria</p>";
279
+ this.setOptions(options);
280
+ $("" + this.renderTo + " a").live('click', function(event) {
281
+ return event.preventDefault();
282
+ });
283
+ $("" + this.renderTo + " li:not(.disabled) a").live('click', this.handlePaginationLinkClick);
284
+ }
285
+
286
+ Pagination.prototype.template = '{{#isEmpty}}\n {{{emptyListMessage}}}\n{{/isEmpty}}\n{{^isEmpty}}\n<div class="pagination">\n <ul>\n <li class="{{^previousPage}}disabled{{/previousPage}}">\n <a href=\'{{urlPrefix}}?page={{previousPage}}\' data-page=\'{{previousPage}}\'>← Previous</a>\n </li>\n\n {{#pages}}\n <li class="{{#currentPage}}active disabled{{/currentPage}}">\n <a href=\'{{urlPrefix}}?page={{page}}\' data-page=\'{{page}}\'>{{page}}</a>\n </li>\n {{/pages}}\n\n <li class="{{^nextPage}}disabled{{/nextPage}}">\n <a href=\'{{urlPrefix}}?page={{nextPage}}\' data-page=\'{{nextPage}}\'>Next →</a>\n </li>\n </ul>\n</div>\n{{/isEmpty}}';
287
+
288
+ Pagination.prototype.pagesJSON = function(currentPage, totalPages) {
289
+ var firstPage, groupSize, lastPage, previousPage, _i, _results;
290
+ groupSize = Math.floor(this.maxPages / 2);
291
+ firstPage = currentPage <= groupSize ? 1 : currentPage - groupSize;
292
+ previousPage = firstPage + groupSize * 2 - 1;
293
+ lastPage = previousPage >= totalPages ? totalPages : previousPage;
294
+ return _.map((function() {
295
+ _results = [];
296
+ for (var _i = firstPage; firstPage <= lastPage ? _i <= lastPage : _i >= lastPage; firstPage <= lastPage ? _i++ : _i--){ _results.push(_i); }
297
+ return _results;
298
+ }).apply(this), function(page) {
266
299
  return {
267
- isEmpty: pagination.total_pages === 0,
268
- emptyListMessage: this.emptyListMessage,
269
- currentPage: pagination.current_page,
270
- nextPage: pagination.next_page,
271
- previousPage: pagination.previous_page,
272
- urlPrefix: this.livelist.urlPrefix,
273
- pages: this.pagesJSON(pagination.current_page, pagination.total_pages)
300
+ page: page,
301
+ currentPage: currentPage === page
274
302
  };
303
+ });
304
+ };
305
+
306
+ Pagination.prototype.paginationJSON = function(pagination) {
307
+ return {
308
+ isEmpty: pagination.total_pages === 0,
309
+ emptyListMessage: this.emptyListMessage,
310
+ currentPage: pagination.current_page,
311
+ nextPage: pagination.next_page,
312
+ previousPage: pagination.previous_page,
313
+ urlPrefix: this.livelist.urlPrefix,
314
+ pages: this.pagesJSON(pagination.current_page, pagination.total_pages)
275
315
  };
276
-
277
- Pagination.prototype.render = function(data) {
278
- var paginationHTML;
279
- this.pagination = this.paginationJSON(data.pagination);
280
- paginationHTML = Mustache.to_html(this.template, this.pagination);
281
- return $(this.renderTo).html(paginationHTML);
282
- };
283
-
284
- Pagination.prototype.handlePaginationLinkClick = function(event) {
285
- event.preventDefault();
286
- return $(this.livelist.listSelector).trigger(this.livelist.eventName, {
287
- page: $(event.target).data('page')
288
- });
289
- };
290
-
291
- return Pagination;
292
-
293
- })(Utilities);
294
-
295
- window.Search = (function(_super) {
296
-
297
- __extends(Search, _super);
298
-
299
- function Search(options, livelist) {
300
- this.handleSearchFormSubmit = __bind(this.handleSearchFormSubmit, this);
301
- var _this = this;
302
- this.livelist = livelist;
303
- this.setOptions(options);
304
- $(this.formSelector).submit(function(event) {
305
- return _this.handleSearchFormSubmit(event);
306
- });
316
+ };
317
+
318
+ Pagination.prototype.render = function(data) {
319
+ var paginationHTML;
320
+ this.pagination = this.paginationJSON(data.pagination);
321
+ paginationHTML = Mustache.to_html(this.template, this.pagination);
322
+ return $(this.renderTo).html(paginationHTML);
323
+ };
324
+
325
+ Pagination.prototype.handlePaginationLinkClick = function(event) {
326
+ event.preventDefault();
327
+ return $(this.livelist.listSelector).trigger(this.livelist.eventName, {
328
+ page: $(event.target).data('page')
329
+ });
330
+ };
331
+
332
+ return Pagination;
333
+
334
+ })(Utilities);
335
+
336
+ // ------ lib/search.js -------
337
+ // Generated by CoffeeScript 1.4.0
338
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
339
+ __hasProp = {}.hasOwnProperty,
340
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
341
+
342
+ window.Search = (function(_super) {
343
+
344
+ __extends(Search, _super);
345
+
346
+ function Search(options, livelist) {
347
+ this.handleSearchFormSubmit = __bind(this.handleSearchFormSubmit, this);
348
+
349
+ var _this = this;
350
+ this.livelist = livelist;
351
+ this.setOptions(options);
352
+ $(this.formSelector).submit(function(event) {
353
+ return _this.handleSearchFormSubmit(event);
354
+ });
355
+ }
356
+
357
+ Search.prototype.searchTerm = function() {
358
+ var q;
359
+ q = $(this.searchTextInputSelector).val();
360
+ if (!q || (q === '')) {
361
+ return null;
362
+ } else {
363
+ return q;
307
364
  }
365
+ };
308
366
 
309
- Search.prototype.searchTerm = function() {
310
- var q;
311
- q = $(this.searchTextInputSelector).val();
312
- if (!q || (q === '')) {
313
- return null;
314
- } else {
315
- return q;
316
- }
317
- };
318
-
319
- Search.prototype.handleSearchFormSubmit = function(event) {
320
- event.preventDefault();
321
- return $(this.livelist.listSelector).trigger(this.livelist.eventName);
322
- };
367
+ Search.prototype.handleSearchFormSubmit = function(event) {
368
+ event.preventDefault();
369
+ return $(this.livelist.listSelector).trigger(this.livelist.eventName);
370
+ };
323
371
 
324
- return Search;
372
+ return Search;
325
373
 
326
- })(Utilities);
374
+ })(Utilities);
327
375
 
328
- }).call(this);