forked from 18F/glossary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
3261 lines (2897 loc) · 102 KB
/
main.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 e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
//THIS FILE IS GENERATED FROM EXAMPLE/INIT.JS
'use strict';
var Glossary = require('../src/glossary');
var terms = require('./terms.json');
new Glossary(terms);
},{"../src/glossary":22,"./terms.json":2}],2:[function(require,module,exports){
module.exports=[
{
"term": "Status",
"definition": "Refers to whether the candidate is an incumbent, challenger or running unopposed."
},
{
"term": "Candidate ID",
"definition": "A unique identifier assigned to each candidate registered with the FEC. The initial character indicates the office sought. (H)ouse, (S)enate, (P)resident. If a person runs for several offices, they will have separate Candidate IDs for each office."
},
{
"term": "Party",
"definition": "Party affiliation as stated on a candidate’s \"Statement of Candidacy.\""
},
{
"term": "District",
"definition": "A U.S. House of Representatives District. Because Senators represent an entire state, Senate races do not have districts associated with them."
},
{
"term": "Organization type",
"definition": "Certain filers, like Separate Segregated Funds, certain types of PACs, and Communication Cost filers identify the types of organizations they are associated with. These entities can be associated with corporations, trade associations, labor organizations, cooperatives, membership organizations, or corporations without capital stock, or have no association."
},
{
"term": "Committee type",
"definition": "A definition that categorizes groups organized to raise and spend money in federal elections. The basic committee types are principal campaign committee, political party committee, and political action committee (PAC)."
},
{
"term": "Total receipts",
"definition": "The sum of all money received by a committee as reported to the FEC, including contributions, during a filing period."
},
{
"term": "Total disbursements",
"definition": "The sum of all money spent by a committee as reported to the FEC during a filing period."
},
{
"term": "Ending cash on hand",
"definition": "The ending cash balance on a report for a particular time period. Cash on hand includes funds held in checking and savings accounts, certificates of deposit, petty cash funds, traveler’s checks, treasury bills and other investments valued at cost."
},
{
"term": "Debt",
"definition": "The amount of money a committee owes to other entities at the end of the filing period."
},
{
"term": "Joint fundraising",
"definition": "Fundraising conducted jointly by a political committee and one or more other political committees or unregistered organizations. Joint fundraising is often conducted between a principal campaign committee and a political party committee."
},
{
"term": "Joint fundraising committee",
"definition": "A committee that has been set up for the purposes of fundraising for multiple committees at the same time, or an existing committee that has been authorized to serve that purpose."
},
{
"term": "Reports and statements",
"definition": "All committees registered with the FEC are required to file reports and statements regularly that disclose their financial activity. The contents of those reports and statements, as well as the filing schedule, depend on the type of committee or organization."
},
{
"term": "Filing",
"definition": "A report or statement submitted to the FEC by a candidate, committee, or other filing entity. Entities are required to file to declare their status as a candidate or committee and to report the money they raise and spend."
},
{
"term": "Authorized committee",
"definition": "A committee that has been authorized by a candidate to raise or spend money on his or her behalf."
},
{
"term": "Committee",
"definition": "An entity that meets one of the following conditions:<ul class='list--bulleted'><li>An authorized committee of a candidate (see definition of candidate)</li><li>A state party committee or nonparty committee, club, association or other group of persons that receives contributions or makes expenditures, either of which aggregate over $1,000 during a calendar year</li><li>A local unit of a political party (except a state party committee) that: (1) receives contributions aggregating over $5,000 during a calendar year; (2) makes contributions or expenditures either of which aggregate over $1,000 during a calendar year; or (3) makes payments aggregating over $5,000 during a calendar year for certain activities which are exempt from the definitions of contribution and expenditure (11 CFR 100.80, 100.87 and 100.89; 11 CFR 100.140, 100.147 and 100.149)</li><li>Any separate segregated fund upon its establishment. 11 CFR 100.5.</li><ul>"
},
{
"term": "Principal campaign committee",
"definition": "An authorized committee designated by a candidate as the principal committee to raise contributions and make expenditures for his or her campaign for a federal office."
},
{
"term": "Candidate",
"definition": "An individual seeking nomination for election, or election, to a federal office becomes a candidate when he or she (or agents working on his or her behalf) raises contributions or makes expenditures that exceed $5,000."
},
{
"term": "None",
"definition": "If data appears as \"None\", it is best to check the source document. Common reasons that the data appears as \"None\" are:<ul class='list--bulleted'><li>Data is not processed yet; often, paper filings cause delays and inconsistent upload times.</li><li>Data is from an amendment that did not properly identify the form it was amending.</li><li>The filer did not fill out the information on the form.</li></ul>If you think there is an error, you can report that via <a href='mailto:[email protected]'>email</a>."
},
{
"term": "Independent expenditure",
"definition": "An expenditure for a communication that expressly advocates the election or defeat of a clearly identified candidate and that is not made in cooperation, consultation or concert with, or at the request or suggestion of, any candidate, or his or her authorized committees or agents, or a political party committee or its agents. 11 CFR 100.16."
}
]
},{}],3:[function(require,module,exports){
'use strict';
var _ = require('underscore');
var defaultOpts = {
collapseOthers: false,
customHiding: false,
contentPrefix: 'accordion',
openFirst: false
};
var defaultSelectors = {
body: '.js-accordion',
trigger: 'button'
};
var Accordion = function(selectors, opts) {
this.selectors = _.extend({}, defaultSelectors, selectors);
this.opts = _.extend({}, defaultOpts, opts);
this.body = document.querySelector(this.selectors.body);
this.triggers = this.findTriggers();
this.listeners = [];
this.addEventListener(this.body, 'click', this.handleClickBody.bind(this));
if (this.opts.openFirst) {
this.expand(this.triggers[0]);
}
};
Accordion.prototype.handleClickBody = function(e) {
if (_.contains(this.triggers, e.target)) {
this.toggle(e.target);
}
};
Accordion.prototype.findTriggers = function() {
var self = this;
var triggers = this.body.querySelectorAll(this.selectors.trigger);
_.each(triggers, function(trigger, index) {
self.setAria(trigger, index);
});
return triggers;
};
Accordion.prototype.setAria = function(trigger, index) {
var content = trigger.nextElementSibling;
var contentID;
if (content.hasAttribute('id')) {
contentID = content.getAttribute('id');
} else {
contentID = this.opts.contentPrefix + '-' + 'content-' + index;
content.setAttribute('id', contentID);
}
trigger.setAttribute('aria-controls', contentID);
trigger.setAttribute('aria-expanded', 'false');
content.setAttribute('aria-hidden', 'true');
this.setStyles(content);
};
Accordion.prototype.toggle = function(elm) {
var f = elm.getAttribute('aria-expanded') === 'true' ? this.collapse : this.expand;
f.call(this, elm);
};
Accordion.prototype.expand = function(button) {
if (this.opts.collapseOthers) {
this.collapseAll();
}
var content = document.getElementById(button.getAttribute('aria-controls'));
button.setAttribute('aria-expanded', 'true');
content.setAttribute('aria-hidden', 'false');
this.setStyles(content);
};
Accordion.prototype.collapse = function(button) {
var content = document.getElementById(button.getAttribute('aria-controls'));
button.setAttribute('aria-expanded', 'false');
content.setAttribute('aria-hidden', 'true');
this.setStyles(content);
};
Accordion.prototype.collapseAll = function() {
var self = this;
_.each(this.triggers, function(trigger) {
self.collapse(trigger);
});
};
Accordion.prototype.expandAll = function() {
var self = this;
this.triggers.forEach(function(trigger) {
self.expand(trigger);
});
};
Accordion.prototype.setStyles = function(content) {
var prop = content.getAttribute('aria-hidden') === 'true' ? 'none' : 'block';
if (!this.opts.customHiding) {
content.style.display = prop;
};
};
Accordion.prototype.addEventListener = function(elm, event, callback) {
if (elm) {
elm.addEventListener(event, callback);
this.listeners.push({
elm: elm,
event: event,
callback: callback
});
}
};
Accordion.prototype.destroy = function() {
this.listeners.forEach(function(listener) {
listener.elm.removeEventListener(listener.event, listener.callback);
});
};
module.exports = { Accordion: Accordion };
},{"underscore":21}],4:[function(require,module,exports){
/*
List.js 1.1.1
By Jonny Strömberg (www.jonnystromberg.com, www.listjs.com)
*/
(function( window, undefined ) {
"use strict";
var document = window.document,
getByClass = require('./src/utils/get-by-class'),
extend = require('./src/utils/extend'),
indexOf = require('./src/utils/index-of'),
events = require('./src/utils/events'),
toString = require('./src/utils/to-string'),
naturalSort = require('./src/utils/natural-sort'),
classes = require('./src/utils/classes'),
getAttribute = require('./src/utils/get-attribute'),
toArray = require('./src/utils/to-array');
var List = function(id, options, values) {
var self = this,
init,
Item = require('./src/item')(self),
addAsync = require('./src/add-async')(self);
init = {
start: function() {
self.listClass = "list";
self.searchClass = "search";
self.sortClass = "sort";
self.page = 10000;
self.i = 1;
self.items = [];
self.visibleItems = [];
self.matchingItems = [];
self.searched = false;
self.filtered = false;
self.searchColumns = undefined;
self.handlers = { 'updated': [] };
self.plugins = {};
self.valueNames = [];
self.utils = {
getByClass: getByClass,
extend: extend,
indexOf: indexOf,
events: events,
toString: toString,
naturalSort: naturalSort,
classes: classes,
getAttribute: getAttribute,
toArray: toArray
};
self.utils.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.parse = require('./src/parse')(self);
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.handlers();
this.items();
self.update();
this.plugins();
},
handlers: function() {
for (var handler in self.handlers) {
if (self[handler]) {
self.on(handler, self[handler]);
}
}
},
items: function() {
self.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, List);
}
}
};
/*
* Re-parse the List, use if html have changed
*/
this.reIndex = function() {
self.items = [];
self.visibleItems = [];
self.matchingItems = [];
self.searched = false;
self.filtered = false;
self.parse(self.list);
};
this.toJSON = function() {
var json = [];
for (var i = 0, il = self.items.length; i < il; i++) {
json.push(self.items[i].values());
}
return json;
};
/*
* Add object to list
*/
this.add = function(values, callback) {
if (values.length === 0) {
return;
}
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;
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();
};
// AMD support
if (typeof define === 'function' && define.amd) {
define(function () { return List; });
}
module.exports = List;
window.List = List;
})(window);
},{"./src/add-async":5,"./src/filter":6,"./src/item":7,"./src/parse":8,"./src/search":9,"./src/sort":10,"./src/templater":11,"./src/utils/classes":12,"./src/utils/events":13,"./src/utils/extend":14,"./src/utils/get-attribute":15,"./src/utils/get-by-class":16,"./src/utils/index-of":17,"./src/utils/natural-sort":18,"./src/utils/to-array":19,"./src/utils/to-string":20}],5:[function(require,module,exports){
module.exports = function(list) {
var addAsync = function(values, callback, items) {
var valuesToAdd = values.splice(0, 50);
items = items || [];
items = items.concat(list.add(valuesToAdd));
if (values.length > 0) {
setTimeout(function() {
addAsync(values, callback, items);
}, 1);
} else {
list.update();
callback(items);
}
};
return addAsync;
};
},{}],6:[function(require,module,exports){
module.exports = function(list) {
// Add handlers
list.handlers.filterStart = list.handlers.filterStart || [];
list.handlers.filterComplete = list.handlers.filterComplete || [];
return function(filterFunction) {
list.trigger('filterStart');
list.i = 1; // Reset paging
list.reset.filter();
if (filterFunction === undefined) {
list.filtered = false;
} else {
list.filtered = true;
var is = list.items;
for (var i = 0, il = is.length; i < il; i++) {
var item = is[i];
if (filterFunction(item)) {
item.filtered = true;
} else {
item.filtered = false;
}
}
}
list.update();
list.trigger('filterComplete');
return list.visibleItems;
};
};
},{}],7:[function(require,module,exports){
module.exports = function(list) {
return function(initValues, element, notCreate) {
var item = this;
this._values = {};
this.found = false; // Show if list.searched == true and this.found == true
this.filtered = false;// Show if list.filtered == true and this.filtered == true
var init = function(initValues, element, notCreate) {
if (element === undefined) {
if (notCreate) {
item.values(initValues, notCreate);
} else {
item.values(initValues);
}
} else {
item.elm = element;
var values = list.templater.get(item, initValues);
item.values(values);
}
};
this.values = function(newValues, notCreate) {
if (newValues !== undefined) {
for(var name in newValues) {
item._values[name] = newValues[name];
}
if (notCreate !== true) {
list.templater.set(item, item.values());
}
} else {
return item._values;
}
};
this.show = function() {
list.templater.show(item);
};
this.hide = function() {
list.templater.hide(item);
};
this.matching = function() {
return (
(list.filtered && list.searched && item.found && item.filtered) ||
(list.filtered && !list.searched && item.filtered) ||
(!list.filtered && list.searched && item.found) ||
(!list.filtered && !list.searched)
);
};
this.visible = function() {
return (item.elm && (item.elm.parentNode == list.list)) ? true : false;
};
init(initValues, element, notCreate);
};
};
},{}],8:[function(require,module,exports){
module.exports = function(list) {
var Item = require('./item')(list);
var getChildren = function(parent) {
var nodes = parent.childNodes,
items = [];
for (var i = 0, il = nodes.length; i < il; i++) {
// Only textnodes have a data attribute
if (nodes[i].data === undefined) {
items.push(nodes[i]);
}
}
return items;
};
var parse = function(itemElements, valueNames) {
for (var i = 0, il = itemElements.length; i < il; i++) {
list.items.push(new Item(valueNames, itemElements[i]));
}
};
var parseAsync = function(itemElements, valueNames) {
var itemsToIndex = itemElements.splice(0, 50); // TODO: If < 100 items, what happens in IE etc?
parse(itemsToIndex, valueNames);
if (itemElements.length > 0) {
setTimeout(function() {
parseAsync(itemElements, valueNames);
}, 1);
} else {
list.update();
list.trigger('parseComplete');
}
};
list.handlers.parseComplete = list.handlers.parseComplete || [];
return function() {
var itemsToIndex = getChildren(list.list),
valueNames = list.valueNames;
if (list.indexAsync) {
parseAsync(itemsToIndex, valueNames);
} else {
parse(itemsToIndex, valueNames);
}
};
};
},{"./item":7}],9:[function(require,module,exports){
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() {
if (list.items.length === 0) return;
if (columns === undefined) {
columns = (list.searchColumns === undefined) ? prepare.toArray(list.items[0].values()) : list.searchColumns;
}
},
setSearchString: function(s) {
s = list.utils.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)) {
text = list.utils.toString(values[column]).toLowerCase();
if ((searchString !== "") && (text.search(searchString) > -1)) {
return true;
}
}
return false;
},
reset: function() {
list.reset.search();
list.searched = false;
}
};
var searchMethod = function(str) {
list.trigger('searchStart');
prepare.resetList();
prepare.setSearchString(str);
prepare.setOptions(arguments); // str, cols|searchFunction, searchFunction
prepare.setColumns();
if (searchString === "" ) {
search.reset();
} else {
list.searched = true;
if (customSearch) {
customSearch(searchString, columns);
} else {
search.list();
}
}
list.update();
list.trigger('searchComplete');
return list.visibleItems;
};
list.handlers.searchStart = list.handlers.searchStart || [];
list.handlers.searchComplete = list.handlers.searchComplete || [];
list.utils.events.bind(list.utils.getByClass(list.listContainer, list.searchClass), 'keyup', function(e) {
var target = e.target || e.srcElement, // IE have srcElement
alreadyCleared = (target.value === "" && !list.searched);
if (!alreadyCleared) { // If oninput already have resetted the list, do nothing
searchMethod(target.value);
}
});
// Used to detect click on HTML5 clear button
list.utils.events.bind(list.utils.getByClass(list.listContainer, list.searchClass), 'input', function(e) {
var target = e.target || e.srcElement;
if (target.value === "") {
searchMethod('');
}
});
return searchMethod;
};
},{}],10:[function(require,module,exports){
module.exports = function(list) {
list.sortFunction = list.sortFunction || function(itemA, itemB, options) {
options.desc = options.order == "desc" ? true : false; // Natural sort uses this format
return list.utils.naturalSort(itemA.values()[options.valueName], itemB.values()[options.valueName], options);
};
var buttons = {
els: undefined,
clear: function() {
for (var i = 0, il = buttons.els.length; i < il; i++) {
list.utils.classes(buttons.els[i]).remove('asc');
list.utils.classes(buttons.els[i]).remove('desc');
}
},
getOrder: function(btn) {
var predefinedOrder = list.utils.getAttribute(btn, 'data-order');
if (predefinedOrder == "asc" || predefinedOrder == "desc") {
return predefinedOrder;
} else if (list.utils.classes(btn).has('desc')) {
return "asc";
} else if (list.utils.classes(btn).has('asc')) {
return "desc";
} else {
return "asc";
}
},
getInSensitive: function(btn, options) {
var insensitive = list.utils.getAttribute(btn, 'data-insensitive');
if (insensitive === "false") {
options.insensitive = false;
} else {
options.insensitive = true;
}
},
setOrder: function(options) {
for (var i = 0, il = buttons.els.length; i < il; i++) {
var btn = buttons.els[i];
if (list.utils.getAttribute(btn, 'data-sort') !== options.valueName) {
continue;
}
var predefinedOrder = list.utils.getAttribute(btn, 'data-order');
if (predefinedOrder == "asc" || predefinedOrder == "desc") {
if (predefinedOrder == options.order) {
list.utils.classes(btn).add(options.order);
}
} else {
list.utils.classes(btn).add(options.order);
}
}
}
};
var sort = function() {
list.trigger('sortStart');
var options = {};
var target = arguments[0].currentTarget || arguments[0].srcElement || undefined;
if (target) {
options.valueName = list.utils.getAttribute(target, 'data-sort');
buttons.getInSensitive(target, options);
options.order = buttons.getOrder(target);
} else {
options = arguments[1] || options;
options.valueName = arguments[0];
options.order = options.order || "asc";
options.insensitive = (typeof options.insensitive == "undefined") ? true : options.insensitive;
}
buttons.clear();
buttons.setOrder(options);
options.sortFunction = options.sortFunction || list.sortFunction;
list.items.sort(function(a, b) {
var mult = (options.order === 'desc') ? -1 : 1;
return (options.sortFunction(a, b, options) * mult);
});
list.update();
list.trigger('sortComplete');
};
// Add handlers
list.handlers.sortStart = list.handlers.sortStart || [];
list.handlers.sortComplete = list.handlers.sortComplete || [];
buttons.els = list.utils.getByClass(list.listContainer, list.sortClass);
list.utils.events.bind(buttons.els, 'click', sort);
list.on('searchStart', buttons.clear);
list.on('filterStart', buttons.clear);
return sort;
};
},{}],11:[function(require,module,exports){
var Templater = function(list) {
var itemSource,
templater = this;
var init = function() {
itemSource = templater.getItemSource(list.item);
itemSource = templater.clearSourceItem(itemSource, list.valueNames);
};
this.clearSourceItem = function(el, valueNames) {
for(var i = 0, il = valueNames.length; i < il; i++) {
var elm;
if (valueNames[i].data) {
for (var j = 0, jl = valueNames[i].data.length; j < jl; j++) {
el.setAttribute('data-'+valueNames[i].data[j], '');
}
} else if (valueNames[i].attr && valueNames[i].name) {
elm = list.utils.getByClass(el, valueNames[i].name, true);
if (elm) {
elm.setAttribute(valueNames[i].attr, "");
}
} else {
elm = list.utils.getByClass(el, valueNames[i], true);
if (elm) {
elm.innerHTML = "";
}
}
elm = undefined;
}
return el;
};
this.getItemSource = function(item) {
if (item === undefined) {
var nodes = list.list.childNodes,
items = [];
for (var i = 0, il = nodes.length; i < il; i++) {
// Only textnodes have a data attribute
if (nodes[i].data === undefined) {
return nodes[i].cloneNode(true);
}
}
} else if (/^tr[\s>]/.exec(item)) {
var table = document.createElement('table');
table.innerHTML = item;
return table.firstChild;
} else if (item.indexOf("<") !== -1) {
var div = document.createElement('div');
div.innerHTML = item;
return div.firstChild;
} else {
var source = document.getElementById(list.item);
if (source) {
return source;
}
}
throw new Error("The list need to have at list one item on init otherwise you'll have to add a template.");
};
this.get = function(item, valueNames) {
templater.create(item);
var values = {};
for(var i = 0, il = valueNames.length; i < il; i++) {
var elm;
if (valueNames[i].data) {
for (var j = 0, jl = valueNames[i].data.length; j < jl; j++) {
values[valueNames[i].data[j]] = list.utils.getAttribute(item.elm, 'data-'+valueNames[i].data[j]);
}
} else if (valueNames[i].attr && valueNames[i].name) {
elm = list.utils.getByClass(item.elm, valueNames[i].name, true);
values[valueNames[i].name] = elm ? list.utils.getAttribute(elm, valueNames[i].attr) : "";
} else {
elm = list.utils.getByClass(item.elm, valueNames[i], true);
values[valueNames[i]] = elm ? elm.innerHTML : "";
}
elm = undefined;
}
return values;
};
this.set = function(item, values) {
var getValueName = function(name) {
for (var i = 0, il = list.valueNames.length; i < il; i++) {
if (list.valueNames[i].data) {
var data = list.valueNames[i].data;
for (var j = 0, jl = data.length; j < jl; j++) {
if (data[j] === name) {
return { data: name };
}
}
} else if (list.valueNames[i].attr && list.valueNames[i].name && list.valueNames[i].name == name) {
return list.valueNames[i];
} else if (list.valueNames[i] === name) {
return name;
}
}
};
var setValue = function(name, value) {
var elm;
var valueName = getValueName(name);
if (!valueName)
return;
if (valueName.data) {
item.elm.setAttribute('data-'+valueName.data, value);
} else if (valueName.attr && valueName.name) {
elm = list.utils.getByClass(item.elm, valueName.name, true);
if (elm) {
elm.setAttribute(valueName.attr, value);
}
} else {
elm = list.utils.getByClass(item.elm, valueName, true);
if (elm) {
elm.innerHTML = value;
}
}
elm = undefined;
};
if (!templater.create(item)) {
for(var v in values) {
if (values.hasOwnProperty(v)) {
setValue(v, values[v]);
}
}
}
};
this.create = function(item) {
if (item.elm !== undefined) {
return false;
}
/* If item source does not exists, use the first item in list as
source for new items */