-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.js
1465 lines (1280 loc) · 39.3 KB
/
list.js
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;(function(){
/**
* Require the given path.
*
* @param {String} path
* @return {Object} exports
* @api public
*/
function require(path, parent, orig) {
var resolved = require.resolve(path);
// lookup failed
if (null == resolved) {
orig = orig || path;
parent = parent || 'root';
var err = new Error('Failed to require "' + orig + '" from "' + parent + '"');
err.path = orig;
err.parent = parent;
err.require = true;
throw err;
}
var module = require.modules[resolved];
// perform real require()
// by invoking the module's
// registered function
if (!module._resolving && !module.exports) {
var mod = {};
mod.exports = {};
mod.client = mod.component = true;
module._resolving = true;
module.call(this, mod.exports, require.relative(resolved), mod);
delete module._resolving;
module.exports = mod.exports;
}
return module.exports;
}
/**
* Registered modules.
*/
require.modules = {};
/**
* Registered aliases.
*/
require.aliases = {};
/**
* Resolve `path`.
*
* Lookup:
*
* - PATH/index.js
* - PATH.js
* - PATH
*
* @param {String} path
* @return {String} path or null
* @api private
*/
require.resolve = function(path) {
if (path.charAt(0) === '/') path = path.slice(1);
var paths = [
path,
path + '.js',
path + '.json',
path + '/index.js',
path + '/index.json'
];
for (var i = 0; i < paths.length; i++) {
var path = paths[i];
if (require.modules.hasOwnProperty(path)) return path;
if (require.aliases.hasOwnProperty(path)) return require.aliases[path];
}
};
/**
* Normalize `path` relative to the current path.
*
* @param {String} curr
* @param {String} path
* @return {String}
* @api private
*/
require.normalize = function(curr, path) {
var segs = [];
if ('.' != path.charAt(0)) return path;
curr = curr.split('/');
path = path.split('/');
for (var i = 0; i < path.length; ++i) {
if ('..' == path[i]) {
curr.pop();
} else if ('.' != path[i] && '' != path[i]) {
segs.push(path[i]);
}
}
return curr.concat(segs).join('/');
};
/**
* Register module at `path` with callback `definition`.
*
* @param {String} path
* @param {Function} definition
* @api private
*/
require.register = function(path, definition) {
require.modules[path] = definition;
};
/**
* Alias a module definition.
*
* @param {String} from
* @param {String} to
* @api private
*/
require.alias = function(from, to) {
if (!require.modules.hasOwnProperty(from)) {
throw new Error('Failed to alias "' + from + '", it does not exist');
}
require.aliases[to] = from;
};
/**
* Return a require function relative to the `parent` path.
*
* @param {String} parent
* @return {Function}
* @api private
*/
require.relative = function(parent) {
var p = require.normalize(parent, '..');
/**
* lastIndexOf helper.
*/
function lastIndexOf(arr, obj) {
var i = arr.length;
while (i--) {
if (arr[i] === obj) return i;
}
return -1;
}
/**
* The relative require() itself.
*/
function localRequire(path) {
var resolved = localRequire.resolve(path);
return require(resolved, parent, path);
}
/**
* Resolve relative to the parent.
*/
localRequire.resolve = function(path) {
var c = path.charAt(0);
if ('/' == c) return path.slice(1);
if ('.' == c) return require.normalize(p, path);
// resolve deps by returning
// the dep in the nearest "deps"
// directory
var segs = parent.split('/');
var i = lastIndexOf(segs, 'deps') + 1;
if (!i) i = 0;
path = segs.slice(0, i + 1).join('/') + '/deps/' + path;
return path;
};
/**
* Check if module is defined at `path`.
*/
localRequire.exists = function(path) {
return require.modules.hasOwnProperty(localRequire.resolve(path));
};
return localRequire;
};
require.register("component-classes/index.js", function(exports, require, module){
/**
* Module dependencies.
*/
var index = require('indexof');
/**
* Whitespace regexp.
*/
var re = /\s+/;
/**
* toString reference.
*/
var toString = Object.prototype.toString;
/**
* Wrap `el` in a `ClassList`.
*
* @param {Element} el
* @return {ClassList}
* @api public
*/
module.exports = function(el){
return new ClassList(el);
};
/**
* Initialize a new ClassList for `el`.
*
* @param {Element} el
* @api private
*/
function ClassList(el) {
if (!el) throw new Error('A DOM element reference is required');
this.el = el;
this.list = el.classList;
}
/**
* Add class `name` if not already present.
*
* @param {String} name
* @return {ClassList}
* @api public
*/
ClassList.prototype.add = function(name){
// classList
if (this.list) {
this.list.add(name);
return this;
}
// fallback
var arr = this.array();
var i = index(arr, name);
if (!~i) arr.push(name);
this.el.className = arr.join(' ');
return this;
};
/**
* Remove class `name` when present, or
* pass a regular expression to remove
* any which match.
*
* @param {String|RegExp} name
* @return {ClassList}
* @api public
*/
ClassList.prototype.remove = function(name){
if ('[object RegExp]' == toString.call(name)) {
return this.removeMatching(name);
}
// classList
if (this.list) {
this.list.remove(name);
return this;
}
// fallback
var arr = this.array();
var i = index(arr, name);
if (~i) arr.splice(i, 1);
this.el.className = arr.join(' ');
return this;
};
/**
* Remove all classes matching `re`.
*
* @param {RegExp} re
* @return {ClassList}
* @api private
*/
ClassList.prototype.removeMatching = function(re){
var arr = this.array();
for (var i = 0; i < arr.length; i++) {
if (re.test(arr[i])) {
this.remove(arr[i]);
}
}
return this;
};
/**
* Toggle class `name`, can force state via `force`.
*
* For browsers that support classList, but do not support `force` yet,
* the mistake will be detected and corrected.
*
* @param {String} name
* @param {Boolean} force
* @return {ClassList}
* @api public
*/
ClassList.prototype.toggle = function(name, force){
// classList
if (this.list) {
if ("undefined" !== typeof force) {
if (force !== this.list.toggle(name, force)) {
this.list.toggle(name); // toggle again to correct
}
} else {
this.list.toggle(name);
}
return this;
}
// fallback
if ("undefined" !== typeof force) {
if (!force) {
this.remove(name);
} else {
this.add(name);
}
} else {
if (this.has(name)) {
this.remove(name);
} else {
this.add(name);
}
}
return this;
};
/**
* Return an array of classes.
*
* @return {Array}
* @api public
*/
ClassList.prototype.array = function(){
var str = this.el.className.replace(/^\s+|\s+$/g, '');
var arr = str.split(re);
if ('' === arr[0]) arr.shift();
return arr;
};
/**
* Check if class `name` is present.
*
* @param {String} name
* @return {ClassList}
* @api public
*/
ClassList.prototype.has =
ClassList.prototype.contains = function(name){
return this.list
? this.list.contains(name)
: !! ~index(this.array(), name);
};
});
require.register("segmentio-extend/index.js", function(exports, require, module){
module.exports = function extend (object) {
// Takes an unlimited number of extenders.
var args = Array.prototype.slice.call(arguments, 1);
// For each extender, copy their properties on our object.
for (var i = 0, source; source = args[i]; i++) {
if (!source) continue;
for (var property in source) {
object[property] = source[property];
}
}
return object;
};
});
require.register("component-indexof/index.js", function(exports, require, module){
module.exports = function(arr, obj){
if (arr.indexOf) return arr.indexOf(obj);
for (var i = 0; i < arr.length; ++i) {
if (arr[i] === obj) return i;
}
return -1;
};
});
require.register("component-event/index.js", function(exports, require, module){
var bind = window.addEventListener ? 'addEventListener' : 'attachEvent',
unbind = window.removeEventListener ? 'removeEventListener' : 'detachEvent',
prefix = bind !== 'addEventListener' ? 'on' : '';
/**
* Bind `el` event `type` to `fn`.
*
* @param {Element} el
* @param {String} type
* @param {Function} fn
* @param {Boolean} capture
* @return {Function}
* @api public
*/
exports.bind = function(el, type, fn, capture){
el[bind](prefix + type, fn, capture || false);
return fn;
};
/**
* Unbind `el` event `type`'s callback `fn`.
*
* @param {Element} el
* @param {String} type
* @param {Function} fn
* @param {Boolean} capture
* @return {Function}
* @api public
*/
exports.unbind = function(el, type, fn, capture){
el[unbind](prefix + type, fn, capture || false);
return fn;
};
});
require.register("javve-to-array/index.js", function(exports, require, module){
/**
* Convert an array-like object into an `Array`.
* If `collection` is already an `Array`, then will return a clone of `collection`.
*
* @param {Array | Mixed} collection An `Array` or array-like object to convert e.g. `arguments` or `NodeList`
* @return {Array} Naive conversion of `collection` to a new `Array`.
* @api public
*/
module.exports = function toArray(collection) {
if (typeof collection === 'undefined') return []
if (collection === null) return [null]
if (collection === window) return [window]
if (typeof collection === 'string') return [collection]
if (collection instanceof Array) return collection
if (typeof collection.length != 'number') return [collection]
if (typeof collection === 'function') return [collection]
var arr = []
for (var i = 0; i < collection.length; i++) {
if (Object.prototype.hasOwnProperty.call(collection, i) || i in collection) {
arr.push(collection[i])
}
}
if (!arr.length) return []
return arr
}
});
require.register("javve-events/index.js", function(exports, require, module){
var events = require('event'),
toArray = require('to-array');
/**
* Bind `el` event `type` to `fn`.
*
* @param {Element} el, NodeList, HTMLCollection or Array
* @param {String} type
* @param {Function} fn
* @param {Boolean} capture
* @api public
*/
exports.bind = function(el, type, fn, capture){
el = toArray(el);
for ( var i = 0; i < el.length; i++ ) {
events.bind(el[i], type, fn, capture);
}
};
/**
* Unbind `el` event `type`'s callback `fn`.
*
* @param {Element} el, NodeList, HTMLCollection or Array
* @param {String} type
* @param {Function} fn
* @param {Boolean} capture
* @api public
*/
exports.unbind = function(el, type, fn, capture){
el = toArray(el);
for ( var i = 0; i < el.length; i++ ) {
events.unbind(el[i], type, fn, capture);
}
};
});
require.register("javve-get-by-class/index.js", function(exports, require, module){
/**
* Find all elements with class `className` inside `container`.
* Use `single = true` to increase performance in older browsers
* when only one element is needed.
*
* @param {String} className
* @param {Element} container
* @param {Boolean} single
* @api public
*/
module.exports = (function() {
if (document.getElementsByClassName) {
return function(container, className, single) {
if (single) {
return container.getElementsByClassName(className)[0];
} else {
return container.getElementsByClassName(className);
}
};
} else if (document.querySelector) {
return function(container, className, single) {
className = '.' + className;
if (single) {
return container.querySelector(className);
} else {
return container.querySelectorAll(className);
}
};
} else {
return function(container, className, single) {
var classElements = [],
tag = '*';
if (container == null) {
container = document;
}
var els = container.getElementsByTagName(tag);
var elsLen = els.length;
var pattern = new RegExp("(^|\\s)"+className+"(\\s|$)");
for (var i = 0, j = 0; i < elsLen; i++) {
if ( pattern.test(els[i].className) ) {
if (single) {
return els[i];
} else {
classElements[j] = els[i];
j++;
}
}
}
return classElements;
};
}
})();
});
require.register("javve-get-attribute/index.js", function(exports, require, module){
/**
* Return the value for `attr` at `element`.
*
* @param {Element} el
* @param {String} attr
* @api public
*/
module.exports = function(el, attr) {
var result = (el.getAttribute && el.getAttribute(attr)) || null;
if( !result ) {
var attrs = el.attributes;
var length = attrs.length;
for(var i = 0; i < length; i++) {
if (attr[i] !== undefined) {
if(attr[i].nodeName === attr) {
result = attr[i].nodeValue;
}
}
}
}
return result;
}
});
require.register("javve-natural-sort/index.js", function(exports, require, module){
/*
* Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license
* Author: Jim Palmer (based on chunking idea from Dave Koelle)
*/
module.exports = function(a, b, options) {
var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi,
sre = /(^[ ]*|[ ]*$)/g,
dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,
hre = /^0x[0-9a-f]+$/i,
ore = /^0/,
options = options || {},
i = function(s) { return options.insensitive && (''+s).toLowerCase() || ''+s },
// convert all to strings strip whitespace
x = i(a).replace(sre, '') || '',
y = i(b).replace(sre, '') || '',
// chunk/tokenize
xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
// numeric, hex or date detection
xD = parseInt(x.match(hre)) || (xN.length != 1 && x.match(dre) && Date.parse(x)),
yD = parseInt(y.match(hre)) || xD && y.match(dre) && Date.parse(y) || null,
oFxNcL, oFyNcL,
mult = options.desc ? -1 : 1;
// first try and sort Hex codes or Dates
if (yD)
if ( xD < yD ) return -1 * mult;
else if ( xD > yD ) return 1 * mult;
// natural sorting through split numeric strings and default strings
for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) {
// find floats not starting with '0', string or 0 if not defined (Clint Priest)
oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0;
oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0;
// handle numeric vs string comparison - number < string - (Kyle Adams)
if (isNaN(oFxNcL) !== isNaN(oFyNcL)) { return (isNaN(oFxNcL)) ? 1 : -1; }
// rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
else if (typeof oFxNcL !== typeof oFyNcL) {
oFxNcL += '';
oFyNcL += '';
}
if (oFxNcL < oFyNcL) return -1 * mult;
if (oFxNcL > oFyNcL) return 1 * mult;
}
return 0;
};
/*
var defaultSort = getSortFunction();
module.exports = function(a, b, options) {
if (arguments.length == 1) {
options = a;
return getSortFunction(options);
} else {
return defaultSort(a,b);
}
}
*/
});
require.register("javve-to-string/index.js", function(exports, require, module){
module.exports = function(s) {
s = (s === undefined) ? "" : s;
s = (s === null) ? "" : s;
s = s.toString();
return s;
};
});
require.register("component-type/index.js", function(exports, require, module){
/**
* toString ref.
*/
var toString = Object.prototype.toString;
/**
* Return the type of `val`.
*
* @param {Mixed} val
* @return {String}
* @api public
*/
module.exports = function(val){
switch (toString.call(val)) {
case '[object Date]': return 'date';
case '[object RegExp]': return 'regexp';
case '[object Arguments]': return 'arguments';
case '[object Array]': return 'array';
case '[object Error]': return 'error';
}
if (val === null) return 'null';
if (val === undefined) return 'undefined';
if (val !== val) return 'nan';
if (val && val.nodeType === 1) return 'element';
return typeof val.valueOf();
};
});
require.register("list.js/index.js", function(exports, require, module){
/*
ListJS with beta 1.0.0
By Jonny Strömberg (www.jonnystromberg.com, www.listjs.com)
*/
(function( window, undefined ) {
"use strict";
var document = window.document,
getByClass = require('get-by-class'),
extend = require('extend'),
indexOf = require('indexof');
var List = function(id, options, values) {
var self = this,
init,
Item = require('./src/item')(self),
addAsync = require('./src/add-async')(self),
parse = require('./src/parse')(self);
init = {
start: function() {
self.listClass = "list";
self.searchClass = "search";
self.sortClass = "sort";
self.page = 200;
self.i = 1;
self.items = [];
self.visibleItems = [];
self.matchingItems = [];
self.searched = false;
self.filtered = false;
self.handlers = { 'updated': [] };
self.plugins = {};
self.helpers = {
getByClass: getByClass,
extend: extend,
indexOf: indexOf
};
extend(self, options);
self.listContainer = (typeof(id) === 'string') ? document.getElementById(id) : id;
if (!self.listContainer) { return; }
self.list = getByClass(self.listContainer, self.listClass, true);
self.templater = require('./src/templater')(self);
self.search = require('./src/search')(self);
self.filter = require('./src/filter')(self);
self.sort = require('./src/sort')(self);
this.items();
self.update();
this.plugins();
},
items: function() {
parse(self.list);
if (values !== undefined) {
self.add(values);
}
},
plugins: function() {
for (var i = 0; i < self.plugins.length; i++) {
var plugin = self.plugins[i];
self[plugin.name] = plugin;
plugin.init(self);
}
}
};
/*
* Add object to list
*/
this.add = function(values, callback) {
if (callback) {
addAsync(values, callback);
return;
}
var added = [],
notCreate = false;
if (values[0] === undefined){
values = [values];
}
for (var i = 0, il = values.length; i < il; i++) {
var item = null;
if (values[i] instanceof Item) {
item = values[i];
item.reload();
} else {
notCreate = (self.items.length > self.page) ? true : false;
item = new Item(values[i], undefined, notCreate);
}
self.items.push(item);
added.push(item);
}
self.update();
return added;
};
this.show = function(i, page) {
this.i = i;
this.page = page;
self.update();
return self;
};
/* Removes object from list.
* Loops through the list and removes objects where
* property "valuename" === value
*/
this.remove = function(valueName, value, options) {
var found = 0;
for (var i = 0, il = self.items.length; i < il; i++) {
if (self.items[i].values()[valueName] == value) {
self.templater.remove(self.items[i], options);
self.items.splice(i,1);
il--;
i--;
found++;
}
}
self.update();
return found;
};
/* Gets the objects in the list which
* property "valueName" === value
*/
this.get = function(valueName, value) {
var matchedItems = [];
for (var i = 0, il = self.items.length; i < il; i++) {
var item = self.items[i];
if (item.values()[valueName] == value) {
matchedItems.push(item);
}
}
return matchedItems;
};
/*
* Get size of the list
*/
this.size = function() {
return self.items.length;
};
/*
* Removes all items from the list
*/
this.clear = function() {
self.templater.clear();
self.items = [];
return self;
};
this.on = function(event, callback) {
self.handlers[event].push(callback);
return self;
};
this.off = function(event, callback) {
var e = self.handlers[event];
var index = indexOf(e, callback);
if (index > -1) {
e.splice(index, 1);
}
return self;
};
this.trigger = function(event) {
var i = self.handlers[event].length;
while(i--) {
self.handlers[event][i](self);
}
return self;
};
this.reset = {
filter: function() {
var is = self.items,
il = is.length;
while (il--) {
is[il].filtered = false;
}
return self;
},
search: function() {
var is = self.items,
il = is.length;
while (il--) {
is[il].found = false;
}
return self;
}
};
this.update = function() {
var is = self.items,
il = is.length;
self.visibleItems = [];
self.matchingItems = [];
self.templater.clear();
for (var i = 0; i < il; i++) {
if (is[i].matching() && ((self.matchingItems.length+1) >= self.i && self.visibleItems.length < self.page)) {
is[i].show();
self.visibleItems.push(is[i]);
self.matchingItems.push(is[i]);
} else if (is[i].matching()) {
self.matchingItems.push(is[i]);
is[i].hide();
} else {
is[i].hide();
}
}
self.trigger('updated');
return self;
};
init.start();
};
module.exports = List;
})(window);
});
require.register("list.js/src/search.js", function(exports, require, module){
var events = require('events'),
getByClass = require('get-by-class'),
toString = require('to-string');
module.exports = function(list) {
var item,
text,
columns,
searchString,
customSearch;
var prepare = {
resetList: function() {
list.i = 1;
list.templater.clear();
customSearch = undefined;
},
setOptions: function(args) {
if (args.length == 2 && args[1] instanceof Array) {
columns = args[1];
} else if (args.length == 2 && typeof(args[1]) == "function") {
customSearch = args[1];
} else if (args.length == 3) {
columns = args[1];
customSearch = args[2];
}
},
setColumns: function() {
columns = (columns === undefined) ? prepare.toArray(list.items[0].values()) : columns;
},
setSearchString: function(s) {
s = toString(s).toLowerCase();
s = s.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&"); // Escape regular expression characters
searchString = s;
},
toArray: function(values) {
var tmpColumn = [];
for (var name in values) {
tmpColumn.push(name);
}
return tmpColumn;
}
};
var search = {
list: function() {
for (var k = 0, kl = list.items.length; k < kl; k++) {
search.item(list.items[k]);
}
},
item: function(item) {
item.found = false;
for (var j = 0, jl = columns.length; j < jl; j++) {
if (search.values(item.values(), columns[j])) {
item.found = true;
return;
}
}
},
values: function(values, column) {
if (values.hasOwnProperty(column)) {
if(/^<[^>]+>/.test(values[column])){
remplace = $(values[column]).clone();
remplace.not(":visible").remove();
text = toString(remplace.html()).toLowerCase();
} else {
text = toString(values[column]).toLowerCase();