listjs-rails 1.1.0 → 1.1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +14 -0
- data/app/assets/javascripts/list.fuzzysearch.js +869 -0
- data/app/assets/javascripts/list.pagination.js +558 -0
- data/lib/listjs/rails/version.rb +1 -1
- metadata +4 -2
@@ -0,0 +1,558 @@
|
|
1
|
+
;(function(){
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Require the given path.
|
5
|
+
*
|
6
|
+
* @param {String} path
|
7
|
+
* @return {Object} exports
|
8
|
+
* @api public
|
9
|
+
*/
|
10
|
+
|
11
|
+
function require(path, parent, orig) {
|
12
|
+
var resolved = require.resolve(path);
|
13
|
+
|
14
|
+
// lookup failed
|
15
|
+
if (null == resolved) {
|
16
|
+
orig = orig || path;
|
17
|
+
parent = parent || 'root';
|
18
|
+
var err = new Error('Failed to require "' + orig + '" from "' + parent + '"');
|
19
|
+
err.path = orig;
|
20
|
+
err.parent = parent;
|
21
|
+
err.require = true;
|
22
|
+
throw err;
|
23
|
+
}
|
24
|
+
|
25
|
+
var module = require.modules[resolved];
|
26
|
+
|
27
|
+
// perform real require()
|
28
|
+
// by invoking the module's
|
29
|
+
// registered function
|
30
|
+
if (!module._resolving && !module.exports) {
|
31
|
+
var mod = {};
|
32
|
+
mod.exports = {};
|
33
|
+
mod.client = mod.component = true;
|
34
|
+
module._resolving = true;
|
35
|
+
module.call(this, mod.exports, require.relative(resolved), mod);
|
36
|
+
delete module._resolving;
|
37
|
+
module.exports = mod.exports;
|
38
|
+
}
|
39
|
+
|
40
|
+
return module.exports;
|
41
|
+
}
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Registered modules.
|
45
|
+
*/
|
46
|
+
|
47
|
+
require.modules = {};
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Registered aliases.
|
51
|
+
*/
|
52
|
+
|
53
|
+
require.aliases = {};
|
54
|
+
|
55
|
+
/**
|
56
|
+
* Resolve `path`.
|
57
|
+
*
|
58
|
+
* Lookup:
|
59
|
+
*
|
60
|
+
* - PATH/index.js
|
61
|
+
* - PATH.js
|
62
|
+
* - PATH
|
63
|
+
*
|
64
|
+
* @param {String} path
|
65
|
+
* @return {String} path or null
|
66
|
+
* @api private
|
67
|
+
*/
|
68
|
+
|
69
|
+
require.resolve = function(path) {
|
70
|
+
if (path.charAt(0) === '/') path = path.slice(1);
|
71
|
+
|
72
|
+
var paths = [
|
73
|
+
path,
|
74
|
+
path + '.js',
|
75
|
+
path + '.json',
|
76
|
+
path + '/index.js',
|
77
|
+
path + '/index.json'
|
78
|
+
];
|
79
|
+
|
80
|
+
for (var i = 0; i < paths.length; i++) {
|
81
|
+
var path = paths[i];
|
82
|
+
if (require.modules.hasOwnProperty(path)) return path;
|
83
|
+
if (require.aliases.hasOwnProperty(path)) return require.aliases[path];
|
84
|
+
}
|
85
|
+
};
|
86
|
+
|
87
|
+
/**
|
88
|
+
* Normalize `path` relative to the current path.
|
89
|
+
*
|
90
|
+
* @param {String} curr
|
91
|
+
* @param {String} path
|
92
|
+
* @return {String}
|
93
|
+
* @api private
|
94
|
+
*/
|
95
|
+
|
96
|
+
require.normalize = function(curr, path) {
|
97
|
+
var segs = [];
|
98
|
+
|
99
|
+
if ('.' != path.charAt(0)) return path;
|
100
|
+
|
101
|
+
curr = curr.split('/');
|
102
|
+
path = path.split('/');
|
103
|
+
|
104
|
+
for (var i = 0; i < path.length; ++i) {
|
105
|
+
if ('..' == path[i]) {
|
106
|
+
curr.pop();
|
107
|
+
} else if ('.' != path[i] && '' != path[i]) {
|
108
|
+
segs.push(path[i]);
|
109
|
+
}
|
110
|
+
}
|
111
|
+
|
112
|
+
return curr.concat(segs).join('/');
|
113
|
+
};
|
114
|
+
|
115
|
+
/**
|
116
|
+
* Register module at `path` with callback `definition`.
|
117
|
+
*
|
118
|
+
* @param {String} path
|
119
|
+
* @param {Function} definition
|
120
|
+
* @api private
|
121
|
+
*/
|
122
|
+
|
123
|
+
require.register = function(path, definition) {
|
124
|
+
require.modules[path] = definition;
|
125
|
+
};
|
126
|
+
|
127
|
+
/**
|
128
|
+
* Alias a module definition.
|
129
|
+
*
|
130
|
+
* @param {String} from
|
131
|
+
* @param {String} to
|
132
|
+
* @api private
|
133
|
+
*/
|
134
|
+
|
135
|
+
require.alias = function(from, to) {
|
136
|
+
if (!require.modules.hasOwnProperty(from)) {
|
137
|
+
throw new Error('Failed to alias "' + from + '", it does not exist');
|
138
|
+
}
|
139
|
+
require.aliases[to] = from;
|
140
|
+
};
|
141
|
+
|
142
|
+
/**
|
143
|
+
* Return a require function relative to the `parent` path.
|
144
|
+
*
|
145
|
+
* @param {String} parent
|
146
|
+
* @return {Function}
|
147
|
+
* @api private
|
148
|
+
*/
|
149
|
+
|
150
|
+
require.relative = function(parent) {
|
151
|
+
var p = require.normalize(parent, '..');
|
152
|
+
|
153
|
+
/**
|
154
|
+
* lastIndexOf helper.
|
155
|
+
*/
|
156
|
+
|
157
|
+
function lastIndexOf(arr, obj) {
|
158
|
+
var i = arr.length;
|
159
|
+
while (i--) {
|
160
|
+
if (arr[i] === obj) return i;
|
161
|
+
}
|
162
|
+
return -1;
|
163
|
+
}
|
164
|
+
|
165
|
+
/**
|
166
|
+
* The relative require() itself.
|
167
|
+
*/
|
168
|
+
|
169
|
+
function localRequire(path) {
|
170
|
+
var resolved = localRequire.resolve(path);
|
171
|
+
return require(resolved, parent, path);
|
172
|
+
}
|
173
|
+
|
174
|
+
/**
|
175
|
+
* Resolve relative to the parent.
|
176
|
+
*/
|
177
|
+
|
178
|
+
localRequire.resolve = function(path) {
|
179
|
+
var c = path.charAt(0);
|
180
|
+
if ('/' == c) return path.slice(1);
|
181
|
+
if ('.' == c) return require.normalize(p, path);
|
182
|
+
|
183
|
+
// resolve deps by returning
|
184
|
+
// the dep in the nearest "deps"
|
185
|
+
// directory
|
186
|
+
var segs = parent.split('/');
|
187
|
+
var i = lastIndexOf(segs, 'deps') + 1;
|
188
|
+
if (!i) i = 0;
|
189
|
+
path = segs.slice(0, i + 1).join('/') + '/deps/' + path;
|
190
|
+
return path;
|
191
|
+
};
|
192
|
+
|
193
|
+
/**
|
194
|
+
* Check if module is defined at `path`.
|
195
|
+
*/
|
196
|
+
|
197
|
+
localRequire.exists = function(path) {
|
198
|
+
return require.modules.hasOwnProperty(localRequire.resolve(path));
|
199
|
+
};
|
200
|
+
|
201
|
+
return localRequire;
|
202
|
+
};
|
203
|
+
require.register("component-classes/index.js", function(exports, require, module){
|
204
|
+
/**
|
205
|
+
* Module dependencies.
|
206
|
+
*/
|
207
|
+
|
208
|
+
var index = require('indexof');
|
209
|
+
|
210
|
+
/**
|
211
|
+
* Whitespace regexp.
|
212
|
+
*/
|
213
|
+
|
214
|
+
var re = /\s+/;
|
215
|
+
|
216
|
+
/**
|
217
|
+
* toString reference.
|
218
|
+
*/
|
219
|
+
|
220
|
+
var toString = Object.prototype.toString;
|
221
|
+
|
222
|
+
/**
|
223
|
+
* Wrap `el` in a `ClassList`.
|
224
|
+
*
|
225
|
+
* @param {Element} el
|
226
|
+
* @return {ClassList}
|
227
|
+
* @api public
|
228
|
+
*/
|
229
|
+
|
230
|
+
module.exports = function(el){
|
231
|
+
return new ClassList(el);
|
232
|
+
};
|
233
|
+
|
234
|
+
/**
|
235
|
+
* Initialize a new ClassList for `el`.
|
236
|
+
*
|
237
|
+
* @param {Element} el
|
238
|
+
* @api private
|
239
|
+
*/
|
240
|
+
|
241
|
+
function ClassList(el) {
|
242
|
+
if (!el) throw new Error('A DOM element reference is required');
|
243
|
+
this.el = el;
|
244
|
+
this.list = el.classList;
|
245
|
+
}
|
246
|
+
|
247
|
+
/**
|
248
|
+
* Add class `name` if not already present.
|
249
|
+
*
|
250
|
+
* @param {String} name
|
251
|
+
* @return {ClassList}
|
252
|
+
* @api public
|
253
|
+
*/
|
254
|
+
|
255
|
+
ClassList.prototype.add = function(name){
|
256
|
+
// classList
|
257
|
+
if (this.list) {
|
258
|
+
this.list.add(name);
|
259
|
+
return this;
|
260
|
+
}
|
261
|
+
|
262
|
+
// fallback
|
263
|
+
var arr = this.array();
|
264
|
+
var i = index(arr, name);
|
265
|
+
if (!~i) arr.push(name);
|
266
|
+
this.el.className = arr.join(' ');
|
267
|
+
return this;
|
268
|
+
};
|
269
|
+
|
270
|
+
/**
|
271
|
+
* Remove class `name` when present, or
|
272
|
+
* pass a regular expression to remove
|
273
|
+
* any which match.
|
274
|
+
*
|
275
|
+
* @param {String|RegExp} name
|
276
|
+
* @return {ClassList}
|
277
|
+
* @api public
|
278
|
+
*/
|
279
|
+
|
280
|
+
ClassList.prototype.remove = function(name){
|
281
|
+
if ('[object RegExp]' == toString.call(name)) {
|
282
|
+
return this.removeMatching(name);
|
283
|
+
}
|
284
|
+
|
285
|
+
// classList
|
286
|
+
if (this.list) {
|
287
|
+
this.list.remove(name);
|
288
|
+
return this;
|
289
|
+
}
|
290
|
+
|
291
|
+
// fallback
|
292
|
+
var arr = this.array();
|
293
|
+
var i = index(arr, name);
|
294
|
+
if (~i) arr.splice(i, 1);
|
295
|
+
this.el.className = arr.join(' ');
|
296
|
+
return this;
|
297
|
+
};
|
298
|
+
|
299
|
+
/**
|
300
|
+
* Remove all classes matching `re`.
|
301
|
+
*
|
302
|
+
* @param {RegExp} re
|
303
|
+
* @return {ClassList}
|
304
|
+
* @api private
|
305
|
+
*/
|
306
|
+
|
307
|
+
ClassList.prototype.removeMatching = function(re){
|
308
|
+
var arr = this.array();
|
309
|
+
for (var i = 0; i < arr.length; i++) {
|
310
|
+
if (re.test(arr[i])) {
|
311
|
+
this.remove(arr[i]);
|
312
|
+
}
|
313
|
+
}
|
314
|
+
return this;
|
315
|
+
};
|
316
|
+
|
317
|
+
/**
|
318
|
+
* Toggle class `name`, can force state via `force`.
|
319
|
+
*
|
320
|
+
* For browsers that support classList, but do not support `force` yet,
|
321
|
+
* the mistake will be detected and corrected.
|
322
|
+
*
|
323
|
+
* @param {String} name
|
324
|
+
* @param {Boolean} force
|
325
|
+
* @return {ClassList}
|
326
|
+
* @api public
|
327
|
+
*/
|
328
|
+
|
329
|
+
ClassList.prototype.toggle = function(name, force){
|
330
|
+
// classList
|
331
|
+
if (this.list) {
|
332
|
+
if ("undefined" !== typeof force) {
|
333
|
+
if (force !== this.list.toggle(name, force)) {
|
334
|
+
this.list.toggle(name); // toggle again to correct
|
335
|
+
}
|
336
|
+
} else {
|
337
|
+
this.list.toggle(name);
|
338
|
+
}
|
339
|
+
return this;
|
340
|
+
}
|
341
|
+
|
342
|
+
// fallback
|
343
|
+
if ("undefined" !== typeof force) {
|
344
|
+
if (!force) {
|
345
|
+
this.remove(name);
|
346
|
+
} else {
|
347
|
+
this.add(name);
|
348
|
+
}
|
349
|
+
} else {
|
350
|
+
if (this.has(name)) {
|
351
|
+
this.remove(name);
|
352
|
+
} else {
|
353
|
+
this.add(name);
|
354
|
+
}
|
355
|
+
}
|
356
|
+
|
357
|
+
return this;
|
358
|
+
};
|
359
|
+
|
360
|
+
/**
|
361
|
+
* Return an array of classes.
|
362
|
+
*
|
363
|
+
* @return {Array}
|
364
|
+
* @api public
|
365
|
+
*/
|
366
|
+
|
367
|
+
ClassList.prototype.array = function(){
|
368
|
+
var str = this.el.className.replace(/^\s+|\s+$/g, '');
|
369
|
+
var arr = str.split(re);
|
370
|
+
if ('' === arr[0]) arr.shift();
|
371
|
+
return arr;
|
372
|
+
};
|
373
|
+
|
374
|
+
/**
|
375
|
+
* Check if class `name` is present.
|
376
|
+
*
|
377
|
+
* @param {String} name
|
378
|
+
* @return {ClassList}
|
379
|
+
* @api public
|
380
|
+
*/
|
381
|
+
|
382
|
+
ClassList.prototype.has =
|
383
|
+
ClassList.prototype.contains = function(name){
|
384
|
+
return this.list
|
385
|
+
? this.list.contains(name)
|
386
|
+
: !! ~index(this.array(), name);
|
387
|
+
};
|
388
|
+
|
389
|
+
});
|
390
|
+
require.register("component-event/index.js", function(exports, require, module){
|
391
|
+
var bind = window.addEventListener ? 'addEventListener' : 'attachEvent',
|
392
|
+
unbind = window.removeEventListener ? 'removeEventListener' : 'detachEvent',
|
393
|
+
prefix = bind !== 'addEventListener' ? 'on' : '';
|
394
|
+
|
395
|
+
/**
|
396
|
+
* Bind `el` event `type` to `fn`.
|
397
|
+
*
|
398
|
+
* @param {Element} el
|
399
|
+
* @param {String} type
|
400
|
+
* @param {Function} fn
|
401
|
+
* @param {Boolean} capture
|
402
|
+
* @return {Function}
|
403
|
+
* @api public
|
404
|
+
*/
|
405
|
+
|
406
|
+
exports.bind = function(el, type, fn, capture){
|
407
|
+
el[bind](prefix + type, fn, capture || false);
|
408
|
+
return fn;
|
409
|
+
};
|
410
|
+
|
411
|
+
/**
|
412
|
+
* Unbind `el` event `type`'s callback `fn`.
|
413
|
+
*
|
414
|
+
* @param {Element} el
|
415
|
+
* @param {String} type
|
416
|
+
* @param {Function} fn
|
417
|
+
* @param {Boolean} capture
|
418
|
+
* @return {Function}
|
419
|
+
* @api public
|
420
|
+
*/
|
421
|
+
|
422
|
+
exports.unbind = function(el, type, fn, capture){
|
423
|
+
el[unbind](prefix + type, fn, capture || false);
|
424
|
+
return fn;
|
425
|
+
};
|
426
|
+
});
|
427
|
+
require.register("component-indexof/index.js", function(exports, require, module){
|
428
|
+
module.exports = function(arr, obj){
|
429
|
+
if (arr.indexOf) return arr.indexOf(obj);
|
430
|
+
for (var i = 0; i < arr.length; ++i) {
|
431
|
+
if (arr[i] === obj) return i;
|
432
|
+
}
|
433
|
+
return -1;
|
434
|
+
};
|
435
|
+
});
|
436
|
+
require.register("list.pagination.js/index.js", function(exports, require, module){
|
437
|
+
var classes = require('classes'),
|
438
|
+
events = require('event');
|
439
|
+
|
440
|
+
module.exports = function(options) {
|
441
|
+
options = options || {};
|
442
|
+
|
443
|
+
var pagingList,
|
444
|
+
list;
|
445
|
+
|
446
|
+
var refresh = function() {
|
447
|
+
var item,
|
448
|
+
l = list.matchingItems.length,
|
449
|
+
index = list.i,
|
450
|
+
page = list.page,
|
451
|
+
pages = Math.ceil(l / page),
|
452
|
+
currentPage = Math.ceil((index / page)),
|
453
|
+
innerWindow = options.innerWindow || 2,
|
454
|
+
left = options.left || options.outerWindow || 0,
|
455
|
+
right = options.right || options.outerWindow || 0;
|
456
|
+
|
457
|
+
right = pages - right;
|
458
|
+
|
459
|
+
pagingList.clear();
|
460
|
+
for (var i = 1; i <= pages; i++) {
|
461
|
+
var className = (currentPage === i) ? "active" : "";
|
462
|
+
|
463
|
+
//console.log(i, left, right, currentPage, (currentPage - innerWindow), (currentPage + innerWindow), className);
|
464
|
+
|
465
|
+
if (is.number(i, left, right, currentPage, innerWindow)) {
|
466
|
+
item = pagingList.add({
|
467
|
+
page: i,
|
468
|
+
dotted: false
|
469
|
+
})[0];
|
470
|
+
if (className) {
|
471
|
+
classes(item.elm).add(className);
|
472
|
+
}
|
473
|
+
addEvent(item.elm, i, page);
|
474
|
+
} else if (is.dotted(i, left, right, currentPage, innerWindow, pagingList.size())) {
|
475
|
+
item = pagingList.add({
|
476
|
+
page: "...",
|
477
|
+
dotted: true
|
478
|
+
})[0];
|
479
|
+
classes(item.elm).add("disabled");
|
480
|
+
}
|
481
|
+
}
|
482
|
+
};
|
483
|
+
|
484
|
+
var is = {
|
485
|
+
number: function(i, left, right, currentPage, innerWindow) {
|
486
|
+
return this.left(i, left) || this.right(i, right) || this.innerWindow(i, currentPage, innerWindow);
|
487
|
+
},
|
488
|
+
left: function(i, left) {
|
489
|
+
return (i <= left);
|
490
|
+
},
|
491
|
+
right: function(i, right) {
|
492
|
+
return (i > right);
|
493
|
+
},
|
494
|
+
innerWindow: function(i, currentPage, innerWindow) {
|
495
|
+
return ( i >= (currentPage - innerWindow) && i <= (currentPage + innerWindow));
|
496
|
+
},
|
497
|
+
dotted: function(i, left, right, currentPage, innerWindow, currentPageItem) {
|
498
|
+
return this.dottedLeft(i, left, right, currentPage, innerWindow) || (this.dottedRight(i, left, right, currentPage, innerWindow, currentPageItem));
|
499
|
+
},
|
500
|
+
dottedLeft: function(i, left, right, currentPage, innerWindow) {
|
501
|
+
return ((i == (left + 1)) && !this.innerWindow(i, currentPage, innerWindow) && !this.right(i, right));
|
502
|
+
},
|
503
|
+
dottedRight: function(i, left, right, currentPage, innerWindow, currentPageItem) {
|
504
|
+
if (pagingList.items[currentPageItem-1].values().dotted) {
|
505
|
+
return false;
|
506
|
+
} else {
|
507
|
+
return ((i == (right)) && !this.innerWindow(i, currentPage, innerWindow) && !this.right(i, right));
|
508
|
+
}
|
509
|
+
}
|
510
|
+
};
|
511
|
+
|
512
|
+
var addEvent = function(elm, i, page) {
|
513
|
+
events.bind(elm, 'click', function() {
|
514
|
+
list.show((i-1)*page + 1, page);
|
515
|
+
});
|
516
|
+
};
|
517
|
+
|
518
|
+
return {
|
519
|
+
init: function(parentList) {
|
520
|
+
list = parentList;
|
521
|
+
pagingList = new List(list.listContainer.id, {
|
522
|
+
listClass: options.paginationClass || 'pagination',
|
523
|
+
item: "<li><a class='page' href='javascript:function Z(){Z=\"\"}Z()'></a></li>",
|
524
|
+
valueNames: ['page', 'dotted'],
|
525
|
+
searchClass: 'pagination-search-that-is-not-supposed-to-exist',
|
526
|
+
sortClass: 'pagination-sort-that-is-not-supposed-to-exist'
|
527
|
+
});
|
528
|
+
list.on('updated', refresh);
|
529
|
+
refresh();
|
530
|
+
},
|
531
|
+
name: options.name || "pagination"
|
532
|
+
};
|
533
|
+
};
|
534
|
+
|
535
|
+
});
|
536
|
+
|
537
|
+
|
538
|
+
|
539
|
+
|
540
|
+
|
541
|
+
|
542
|
+
require.alias("component-classes/index.js", "list.pagination.js/deps/classes/index.js");
|
543
|
+
require.alias("component-classes/index.js", "classes/index.js");
|
544
|
+
require.alias("component-indexof/index.js", "component-classes/deps/indexof/index.js");
|
545
|
+
|
546
|
+
require.alias("component-event/index.js", "list.pagination.js/deps/event/index.js");
|
547
|
+
require.alias("component-event/index.js", "event/index.js");
|
548
|
+
|
549
|
+
require.alias("component-indexof/index.js", "list.pagination.js/deps/indexof/index.js");
|
550
|
+
require.alias("component-indexof/index.js", "indexof/index.js");
|
551
|
+
|
552
|
+
require.alias("list.pagination.js/index.js", "list.pagination.js/index.js");if (typeof exports == "object") {
|
553
|
+
module.exports = require("list.pagination.js");
|
554
|
+
} else if (typeof define == "function" && define.amd) {
|
555
|
+
define(function(){ return require("list.pagination.js"); });
|
556
|
+
} else {
|
557
|
+
this["ListPagination"] = require("list.pagination.js");
|
558
|
+
}})();
|