listjs 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b3de9a3ea0765094b6cef9b0503126af02a893c7
4
+ data.tar.gz: 2530f632a887eab01de8801d43dcdcbbae15b541
5
+ SHA512:
6
+ metadata.gz: 0f03f4847856cbbabcaede8d303e65eb23755a1173735eed87c37d6e5dc9957da339306267c0bfefe14b86b4b6b9d1a188c66304420ec09289b683e5af072d09
7
+ data.tar.gz: 33d9ea3bd75c6ce88d29cd02c1999ec1ff166365cc9924a6e6312c80a5b0b6cad3ae50da601b16e82d4f8caec5afa9b711cde47f20098de6536507405c0bee91
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at alexduval71@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in listjs.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Alex
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,55 @@
1
+ # Listjs
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/listjs`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ ###
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'listjs'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install listjs
22
+
23
+ After add this line to your `app/assets/application.js`
24
+
25
+ ```js
26
+ //= require listjs
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ I suggest to have a look on the website from [list.js](http://listjs.com/) to explore all feature / API.
32
+ - Search
33
+ - Sort
34
+ - Filters
35
+
36
+ for any lists, tables or HTML elements.
37
+
38
+ ## Development
39
+
40
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
+
42
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
43
+
44
+ ## Acknowledgements
45
+
46
+ Many thanks are due to [Jonny Strömberg](https://github.com/javve) and [List.js' contributors](https://github.com/javve/list.js#contributors)
47
+
48
+ ## Contributing
49
+
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/xlanex6/listjs. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
51
+
52
+
53
+ ## License
54
+
55
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "listjs"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ require "listjs/version"
2
+
3
+ module Listjs
4
+ class Engine < ::Rails::Engine; end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Listjs
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'listjs/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "listjs"
8
+ spec.version = Listjs::VERSION
9
+ spec.authors = ["Alex DUVAL"]
10
+ spec.email = ["alexduval71@gmail.com"]
11
+
12
+ spec.summary = %q{This gem is for adding easily ListJS to your rail application.}
13
+ spec.description = %q{It will be use for seach, sort, filter any Div element, li , table content.}
14
+ spec.homepage = "https://github.com/xlanex6/ListJS-gem"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "https://github.com/xlanex6/ListJS-gem/issues"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.12"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ end
@@ -0,0 +1,1758 @@
1
+ /*! List.js v1.5.0 (http://listjs.com) by Jonny Strömberg (http://javve.com) */
2
+ var List =
3
+ /******/ (function(modules) { // webpackBootstrap
4
+ /******/ // The module cache
5
+ /******/ var installedModules = {};
6
+
7
+ /******/ // The require function
8
+ /******/ function __webpack_require__(moduleId) {
9
+
10
+ /******/ // Check if module is in cache
11
+ /******/ if(installedModules[moduleId])
12
+ /******/ return installedModules[moduleId].exports;
13
+
14
+ /******/ // Create a new module (and put it into the cache)
15
+ /******/ var module = installedModules[moduleId] = {
16
+ /******/ i: moduleId,
17
+ /******/ l: false,
18
+ /******/ exports: {}
19
+ /******/ };
20
+
21
+ /******/ // Execute the module function
22
+ /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
23
+
24
+ /******/ // Flag the module as loaded
25
+ /******/ module.l = true;
26
+
27
+ /******/ // Return the exports of the module
28
+ /******/ return module.exports;
29
+ /******/ }
30
+
31
+
32
+ /******/ // expose the modules object (__webpack_modules__)
33
+ /******/ __webpack_require__.m = modules;
34
+
35
+ /******/ // expose the module cache
36
+ /******/ __webpack_require__.c = installedModules;
37
+
38
+ /******/ // identity function for calling harmony imports with the correct context
39
+ /******/ __webpack_require__.i = function(value) { return value; };
40
+
41
+ /******/ // define getter function for harmony exports
42
+ /******/ __webpack_require__.d = function(exports, name, getter) {
43
+ /******/ if(!__webpack_require__.o(exports, name)) {
44
+ /******/ Object.defineProperty(exports, name, {
45
+ /******/ configurable: false,
46
+ /******/ enumerable: true,
47
+ /******/ get: getter
48
+ /******/ });
49
+ /******/ }
50
+ /******/ };
51
+
52
+ /******/ // getDefaultExport function for compatibility with non-harmony modules
53
+ /******/ __webpack_require__.n = function(module) {
54
+ /******/ var getter = module && module.__esModule ?
55
+ /******/ function getDefault() { return module['default']; } :
56
+ /******/ function getModuleExports() { return module; };
57
+ /******/ __webpack_require__.d(getter, 'a', getter);
58
+ /******/ return getter;
59
+ /******/ };
60
+
61
+ /******/ // Object.prototype.hasOwnProperty.call
62
+ /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
63
+
64
+ /******/ // __webpack_public_path__
65
+ /******/ __webpack_require__.p = "";
66
+
67
+ /******/ // Load entry module and return exports
68
+ /******/ return __webpack_require__(__webpack_require__.s = 11);
69
+ /******/ })
70
+ /************************************************************************/
71
+ /******/ ([
72
+ /* 0 */
73
+ /***/ (function(module, exports, __webpack_require__) {
74
+
75
+ /**
76
+ * Module dependencies.
77
+ */
78
+
79
+ var index = __webpack_require__(4);
80
+
81
+ /**
82
+ * Whitespace regexp.
83
+ */
84
+
85
+ var re = /\s+/;
86
+
87
+ /**
88
+ * toString reference.
89
+ */
90
+
91
+ var toString = Object.prototype.toString;
92
+
93
+ /**
94
+ * Wrap `el` in a `ClassList`.
95
+ *
96
+ * @param {Element} el
97
+ * @return {ClassList}
98
+ * @api public
99
+ */
100
+
101
+ module.exports = function(el){
102
+ return new ClassList(el);
103
+ };
104
+
105
+ /**
106
+ * Initialize a new ClassList for `el`.
107
+ *
108
+ * @param {Element} el
109
+ * @api private
110
+ */
111
+
112
+ function ClassList(el) {
113
+ if (!el || !el.nodeType) {
114
+ throw new Error('A DOM element reference is required');
115
+ }
116
+ this.el = el;
117
+ this.list = el.classList;
118
+ }
119
+
120
+ /**
121
+ * Add class `name` if not already present.
122
+ *
123
+ * @param {String} name
124
+ * @return {ClassList}
125
+ * @api public
126
+ */
127
+
128
+ ClassList.prototype.add = function(name){
129
+ // classList
130
+ if (this.list) {
131
+ this.list.add(name);
132
+ return this;
133
+ }
134
+
135
+ // fallback
136
+ var arr = this.array();
137
+ var i = index(arr, name);
138
+ if (!~i) arr.push(name);
139
+ this.el.className = arr.join(' ');
140
+ return this;
141
+ };
142
+
143
+ /**
144
+ * Remove class `name` when present, or
145
+ * pass a regular expression to remove
146
+ * any which match.
147
+ *
148
+ * @param {String|RegExp} name
149
+ * @return {ClassList}
150
+ * @api public
151
+ */
152
+
153
+ ClassList.prototype.remove = function(name){
154
+ // classList
155
+ if (this.list) {
156
+ this.list.remove(name);
157
+ return this;
158
+ }
159
+
160
+ // fallback
161
+ var arr = this.array();
162
+ var i = index(arr, name);
163
+ if (~i) arr.splice(i, 1);
164
+ this.el.className = arr.join(' ');
165
+ return this;
166
+ };
167
+
168
+
169
+ /**
170
+ * Toggle class `name`, can force state via `force`.
171
+ *
172
+ * For browsers that support classList, but do not support `force` yet,
173
+ * the mistake will be detected and corrected.
174
+ *
175
+ * @param {String} name
176
+ * @param {Boolean} force
177
+ * @return {ClassList}
178
+ * @api public
179
+ */
180
+
181
+ ClassList.prototype.toggle = function(name, force){
182
+ // classList
183
+ if (this.list) {
184
+ if ("undefined" !== typeof force) {
185
+ if (force !== this.list.toggle(name, force)) {
186
+ this.list.toggle(name); // toggle again to correct
187
+ }
188
+ } else {
189
+ this.list.toggle(name);
190
+ }
191
+ return this;
192
+ }
193
+
194
+ // fallback
195
+ if ("undefined" !== typeof force) {
196
+ if (!force) {
197
+ this.remove(name);
198
+ } else {
199
+ this.add(name);
200
+ }
201
+ } else {
202
+ if (this.has(name)) {
203
+ this.remove(name);
204
+ } else {
205
+ this.add(name);
206
+ }
207
+ }
208
+
209
+ return this;
210
+ };
211
+
212
+ /**
213
+ * Return an array of classes.
214
+ *
215
+ * @return {Array}
216
+ * @api public
217
+ */
218
+
219
+ ClassList.prototype.array = function(){
220
+ var className = this.el.getAttribute('class') || '';
221
+ var str = className.replace(/^\s+|\s+$/g, '');
222
+ var arr = str.split(re);
223
+ if ('' === arr[0]) arr.shift();
224
+ return arr;
225
+ };
226
+
227
+ /**
228
+ * Check if class `name` is present.
229
+ *
230
+ * @param {String} name
231
+ * @return {ClassList}
232
+ * @api public
233
+ */
234
+
235
+ ClassList.prototype.has =
236
+ ClassList.prototype.contains = function(name){
237
+ return this.list ? this.list.contains(name) : !! ~index(this.array(), name);
238
+ };
239
+
240
+
241
+ /***/ }),
242
+ /* 1 */
243
+ /***/ (function(module, exports, __webpack_require__) {
244
+
245
+ var bind = window.addEventListener ? 'addEventListener' : 'attachEvent',
246
+ unbind = window.removeEventListener ? 'removeEventListener' : 'detachEvent',
247
+ prefix = bind !== 'addEventListener' ? 'on' : '',
248
+ toArray = __webpack_require__(5);
249
+
250
+ /**
251
+ * Bind `el` event `type` to `fn`.
252
+ *
253
+ * @param {Element} el, NodeList, HTMLCollection or Array
254
+ * @param {String} type
255
+ * @param {Function} fn
256
+ * @param {Boolean} capture
257
+ * @api public
258
+ */
259
+
260
+ exports.bind = function(el, type, fn, capture){
261
+ el = toArray(el);
262
+ for ( var i = 0; i < el.length; i++ ) {
263
+ el[i][bind](prefix + type, fn, capture || false);
264
+ }
265
+ };
266
+
267
+ /**
268
+ * Unbind `el` event `type`'s callback `fn`.
269
+ *
270
+ * @param {Element} el, NodeList, HTMLCollection or Array
271
+ * @param {String} type
272
+ * @param {Function} fn
273
+ * @param {Boolean} capture
274
+ * @api public
275
+ */
276
+
277
+ exports.unbind = function(el, type, fn, capture){
278
+ el = toArray(el);
279
+ for ( var i = 0; i < el.length; i++ ) {
280
+ el[i][unbind](prefix + type, fn, capture || false);
281
+ }
282
+ };
283
+
284
+
285
+ /***/ }),
286
+ /* 2 */
287
+ /***/ (function(module, exports) {
288
+
289
+ module.exports = function(list) {
290
+ return function(initValues, element, notCreate) {
291
+ var item = this;
292
+
293
+ this._values = {};
294
+
295
+ this.found = false; // Show if list.searched == true and this.found == true
296
+ this.filtered = false;// Show if list.filtered == true and this.filtered == true
297
+
298
+ var init = function(initValues, element, notCreate) {
299
+ if (element === undefined) {
300
+ if (notCreate) {
301
+ item.values(initValues, notCreate);
302
+ } else {
303
+ item.values(initValues);
304
+ }
305
+ } else {
306
+ item.elm = element;
307
+ var values = list.templater.get(item, initValues);
308
+ item.values(values);
309
+ }
310
+ };
311
+
312
+ this.values = function(newValues, notCreate) {
313
+ if (newValues !== undefined) {
314
+ for(var name in newValues) {
315
+ item._values[name] = newValues[name];
316
+ }
317
+ if (notCreate !== true) {
318
+ list.templater.set(item, item.values());
319
+ }
320
+ } else {
321
+ return item._values;
322
+ }
323
+ };
324
+
325
+ this.show = function() {
326
+ list.templater.show(item);
327
+ };
328
+
329
+ this.hide = function() {
330
+ list.templater.hide(item);
331
+ };
332
+
333
+ this.matching = function() {
334
+ return (
335
+ (list.filtered && list.searched && item.found && item.filtered) ||
336
+ (list.filtered && !list.searched && item.filtered) ||
337
+ (!list.filtered && list.searched && item.found) ||
338
+ (!list.filtered && !list.searched)
339
+ );
340
+ };
341
+
342
+ this.visible = function() {
343
+ return (item.elm && (item.elm.parentNode == list.list)) ? true : false;
344
+ };
345
+
346
+ init(initValues, element, notCreate);
347
+ };
348
+ };
349
+
350
+
351
+ /***/ }),
352
+ /* 3 */
353
+ /***/ (function(module, exports) {
354
+
355
+ /**
356
+ * A cross-browser implementation of getElementsByClass.
357
+ * Heavily based on Dustin Diaz's function: http://dustindiaz.com/getelementsbyclass.
358
+ *
359
+ * Find all elements with class `className` inside `container`.
360
+ * Use `single = true` to increase performance in older browsers
361
+ * when only one element is needed.
362
+ *
363
+ * @param {String} className
364
+ * @param {Element} container
365
+ * @param {Boolean} single
366
+ * @api public
367
+ */
368
+
369
+ var getElementsByClassName = function(container, className, single) {
370
+ if (single) {
371
+ return container.getElementsByClassName(className)[0];
372
+ } else {
373
+ return container.getElementsByClassName(className);
374
+ }
375
+ };
376
+
377
+ var querySelector = function(container, className, single) {
378
+ className = '.' + className;
379
+ if (single) {
380
+ return container.querySelector(className);
381
+ } else {
382
+ return container.querySelectorAll(className);
383
+ }
384
+ };
385
+
386
+ var polyfill = function(container, className, single) {
387
+ var classElements = [],
388
+ tag = '*';
389
+
390
+ var els = container.getElementsByTagName(tag);
391
+ var elsLen = els.length;
392
+ var pattern = new RegExp("(^|\\s)"+className+"(\\s|$)");
393
+ for (var i = 0, j = 0; i < elsLen; i++) {
394
+ if ( pattern.test(els[i].className) ) {
395
+ if (single) {
396
+ return els[i];
397
+ } else {
398
+ classElements[j] = els[i];
399
+ j++;
400
+ }
401
+ }
402
+ }
403
+ return classElements;
404
+ };
405
+
406
+ module.exports = (function() {
407
+ return function(container, className, single, options) {
408
+ options = options || {};
409
+ if ((options.test && options.getElementsByClassName) || (!options.test && document.getElementsByClassName)) {
410
+ return getElementsByClassName(container, className, single);
411
+ } else if ((options.test && options.querySelector) || (!options.test && document.querySelector)) {
412
+ return querySelector(container, className, single);
413
+ } else {
414
+ return polyfill(container, className, single);
415
+ }
416
+ };
417
+ })();
418
+
419
+
420
+ /***/ }),
421
+ /* 4 */
422
+ /***/ (function(module, exports) {
423
+
424
+ var indexOf = [].indexOf;
425
+
426
+ module.exports = function(arr, obj){
427
+ if (indexOf) return arr.indexOf(obj);
428
+ for (var i = 0; i < arr.length; ++i) {
429
+ if (arr[i] === obj) return i;
430
+ }
431
+ return -1;
432
+ };
433
+
434
+
435
+ /***/ }),
436
+ /* 5 */
437
+ /***/ (function(module, exports) {
438
+
439
+ /**
440
+ * Source: https://github.com/timoxley/to-array
441
+ *
442
+ * Convert an array-like object into an `Array`.
443
+ * If `collection` is already an `Array`, then will return a clone of `collection`.
444
+ *
445
+ * @param {Array | Mixed} collection An `Array` or array-like object to convert e.g. `arguments` or `NodeList`
446
+ * @return {Array} Naive conversion of `collection` to a new `Array`.
447
+ * @api public
448
+ */
449
+
450
+ module.exports = function toArray(collection) {
451
+ if (typeof collection === 'undefined') return [];
452
+ if (collection === null) return [null];
453
+ if (collection === window) return [window];
454
+ if (typeof collection === 'string') return [collection];
455
+ if (isArray(collection)) return collection;
456
+ if (typeof collection.length != 'number') return [collection];
457
+ if (typeof collection === 'function' && collection instanceof Function) return [collection];
458
+
459
+ var arr = [];
460
+ for (var i = 0; i < collection.length; i++) {
461
+ if (Object.prototype.hasOwnProperty.call(collection, i) || i in collection) {
462
+ arr.push(collection[i]);
463
+ }
464
+ }
465
+ if (!arr.length) return [];
466
+ return arr;
467
+ };
468
+
469
+ function isArray(arr) {
470
+ return Object.prototype.toString.call(arr) === "[object Array]";
471
+ }
472
+
473
+
474
+ /***/ }),
475
+ /* 6 */
476
+ /***/ (function(module, exports) {
477
+
478
+ module.exports = function(s) {
479
+ s = (s === undefined) ? "" : s;
480
+ s = (s === null) ? "" : s;
481
+ s = s.toString();
482
+ return s;
483
+ };
484
+
485
+
486
+ /***/ }),
487
+ /* 7 */
488
+ /***/ (function(module, exports) {
489
+
490
+ /*
491
+ * Source: https://github.com/segmentio/extend
492
+ */
493
+
494
+ module.exports = function extend (object) {
495
+ // Takes an unlimited number of extenders.
496
+ var args = Array.prototype.slice.call(arguments, 1);
497
+
498
+ // For each extender, copy their properties on our object.
499
+ for (var i = 0, source; source = args[i]; i++) {
500
+ if (!source) continue;
501
+ for (var property in source) {
502
+ object[property] = source[property];
503
+ }
504
+ }
505
+
506
+ return object;
507
+ };
508
+
509
+
510
+ /***/ }),
511
+ /* 8 */
512
+ /***/ (function(module, exports) {
513
+
514
+ module.exports = function(list) {
515
+ var addAsync = function(values, callback, items) {
516
+ var valuesToAdd = values.splice(0, 50);
517
+ items = items || [];
518
+ items = items.concat(list.add(valuesToAdd));
519
+ if (values.length > 0) {
520
+ setTimeout(function() {
521
+ addAsync(values, callback, items);
522
+ }, 1);
523
+ } else {
524
+ list.update();
525
+ callback(items);
526
+ }
527
+ };
528
+ return addAsync;
529
+ };
530
+
531
+
532
+ /***/ }),
533
+ /* 9 */
534
+ /***/ (function(module, exports) {
535
+
536
+ module.exports = function(list) {
537
+
538
+ // Add handlers
539
+ list.handlers.filterStart = list.handlers.filterStart || [];
540
+ list.handlers.filterComplete = list.handlers.filterComplete || [];
541
+
542
+ return function(filterFunction) {
543
+ list.trigger('filterStart');
544
+ list.i = 1; // Reset paging
545
+ list.reset.filter();
546
+ if (filterFunction === undefined) {
547
+ list.filtered = false;
548
+ } else {
549
+ list.filtered = true;
550
+ var is = list.items;
551
+ for (var i = 0, il = is.length; i < il; i++) {
552
+ var item = is[i];
553
+ if (filterFunction(item)) {
554
+ item.filtered = true;
555
+ } else {
556
+ item.filtered = false;
557
+ }
558
+ }
559
+ }
560
+ list.update();
561
+ list.trigger('filterComplete');
562
+ return list.visibleItems;
563
+ };
564
+ };
565
+
566
+
567
+ /***/ }),
568
+ /* 10 */
569
+ /***/ (function(module, exports, __webpack_require__) {
570
+
571
+
572
+ var classes = __webpack_require__(0),
573
+ events = __webpack_require__(1),
574
+ extend = __webpack_require__(7),
575
+ toString = __webpack_require__(6),
576
+ getByClass = __webpack_require__(3),
577
+ fuzzy = __webpack_require__(19);
578
+
579
+ module.exports = function(list, options) {
580
+ options = options || {};
581
+
582
+ options = extend({
583
+ location: 0,
584
+ distance: 100,
585
+ threshold: 0.4,
586
+ multiSearch: true,
587
+ searchClass: 'fuzzy-search'
588
+ }, options);
589
+
590
+
591
+
592
+ var fuzzySearch = {
593
+ search: function(searchString, columns) {
594
+ // Substract arguments from the searchString or put searchString as only argument
595
+ var searchArguments = options.multiSearch ? searchString.replace(/ +$/, '').split(/ +/) : [searchString];
596
+
597
+ for (var k = 0, kl = list.items.length; k < kl; k++) {
598
+ fuzzySearch.item(list.items[k], columns, searchArguments);
599
+ }
600
+ },
601
+ item: function(item, columns, searchArguments) {
602
+ var found = true;
603
+ for(var i = 0; i < searchArguments.length; i++) {
604
+ var foundArgument = false;
605
+ for (var j = 0, jl = columns.length; j < jl; j++) {
606
+ if (fuzzySearch.values(item.values(), columns[j], searchArguments[i])) {
607
+ foundArgument = true;
608
+ }
609
+ }
610
+ if(!foundArgument) {
611
+ found = false;
612
+ }
613
+ }
614
+ item.found = found;
615
+ },
616
+ values: function(values, value, searchArgument) {
617
+ if (values.hasOwnProperty(value)) {
618
+ var text = toString(values[value]).toLowerCase();
619
+
620
+ if (fuzzy(text, searchArgument, options)) {
621
+ return true;
622
+ }
623
+ }
624
+ return false;
625
+ }
626
+ };
627
+
628
+
629
+ events.bind(getByClass(list.listContainer, options.searchClass), 'keyup', function(e) {
630
+ var target = e.target || e.srcElement; // IE have srcElement
631
+ list.search(target.value, fuzzySearch.search);
632
+ });
633
+
634
+ return function(str, columns) {
635
+ list.search(str, columns, fuzzySearch.search);
636
+ };
637
+ };
638
+
639
+
640
+ /***/ }),
641
+ /* 11 */
642
+ /***/ (function(module, exports, __webpack_require__) {
643
+
644
+ var naturalSort = __webpack_require__(18),
645
+ getByClass = __webpack_require__(3),
646
+ extend = __webpack_require__(7),
647
+ indexOf = __webpack_require__(4),
648
+ events = __webpack_require__(1),
649
+ toString = __webpack_require__(6),
650
+ classes = __webpack_require__(0),
651
+ getAttribute = __webpack_require__(17),
652
+ toArray = __webpack_require__(5);
653
+
654
+ module.exports = function(id, options, values) {
655
+
656
+ var self = this,
657
+ init,
658
+ Item = __webpack_require__(2)(self),
659
+ addAsync = __webpack_require__(8)(self),
660
+ initPagination = __webpack_require__(12)(self);
661
+
662
+ init = {
663
+ start: function() {
664
+ self.listClass = "list";
665
+ self.searchClass = "search";
666
+ self.sortClass = "sort";
667
+ self.page = 10000;
668
+ self.i = 1;
669
+ self.items = [];
670
+ self.visibleItems = [];
671
+ self.matchingItems = [];
672
+ self.searched = false;
673
+ self.filtered = false;
674
+ self.searchColumns = undefined;
675
+ self.handlers = { 'updated': [] };
676
+ self.valueNames = [];
677
+ self.utils = {
678
+ getByClass: getByClass,
679
+ extend: extend,
680
+ indexOf: indexOf,
681
+ events: events,
682
+ toString: toString,
683
+ naturalSort: naturalSort,
684
+ classes: classes,
685
+ getAttribute: getAttribute,
686
+ toArray: toArray
687
+ };
688
+
689
+ self.utils.extend(self, options);
690
+
691
+ self.listContainer = (typeof(id) === 'string') ? document.getElementById(id) : id;
692
+ if (!self.listContainer) { return; }
693
+ self.list = getByClass(self.listContainer, self.listClass, true);
694
+
695
+ self.parse = __webpack_require__(13)(self);
696
+ self.templater = __webpack_require__(16)(self);
697
+ self.search = __webpack_require__(14)(self);
698
+ self.filter = __webpack_require__(9)(self);
699
+ self.sort = __webpack_require__(15)(self);
700
+ self.fuzzySearch = __webpack_require__(10)(self, options.fuzzySearch);
701
+
702
+ this.handlers();
703
+ this.items();
704
+ this.pagination();
705
+
706
+ self.update();
707
+ },
708
+ handlers: function() {
709
+ for (var handler in self.handlers) {
710
+ if (self[handler]) {
711
+ self.on(handler, self[handler]);
712
+ }
713
+ }
714
+ },
715
+ items: function() {
716
+ self.parse(self.list);
717
+ if (values !== undefined) {
718
+ self.add(values);
719
+ }
720
+ },
721
+ pagination: function() {
722
+ if (options.pagination !== undefined) {
723
+ if (options.pagination === true) {
724
+ options.pagination = [{}];
725
+ }
726
+ if (options.pagination[0] === undefined){
727
+ options.pagination = [options.pagination];
728
+ }
729
+ for (var i = 0, il = options.pagination.length; i < il; i++) {
730
+ initPagination(options.pagination[i]);
731
+ }
732
+ }
733
+ }
734
+ };
735
+
736
+ /*
737
+ * Re-parse the List, use if html have changed
738
+ */
739
+ this.reIndex = function() {
740
+ self.items = [];
741
+ self.visibleItems = [];
742
+ self.matchingItems = [];
743
+ self.searched = false;
744
+ self.filtered = false;
745
+ self.parse(self.list);
746
+ };
747
+
748
+ this.toJSON = function() {
749
+ var json = [];
750
+ for (var i = 0, il = self.items.length; i < il; i++) {
751
+ json.push(self.items[i].values());
752
+ }
753
+ return json;
754
+ };
755
+
756
+
757
+ /*
758
+ * Add object to list
759
+ */
760
+ this.add = function(values, callback) {
761
+ if (values.length === 0) {
762
+ return;
763
+ }
764
+ if (callback) {
765
+ addAsync(values, callback);
766
+ return;
767
+ }
768
+ var added = [],
769
+ notCreate = false;
770
+ if (values[0] === undefined){
771
+ values = [values];
772
+ }
773
+ for (var i = 0, il = values.length; i < il; i++) {
774
+ var item = null;
775
+ notCreate = (self.items.length > self.page) ? true : false;
776
+ item = new Item(values[i], undefined, notCreate);
777
+ self.items.push(item);
778
+ added.push(item);
779
+ }
780
+ self.update();
781
+ return added;
782
+ };
783
+
784
+ this.show = function(i, page) {
785
+ this.i = i;
786
+ this.page = page;
787
+ self.update();
788
+ return self;
789
+ };
790
+
791
+ /* Removes object from list.
792
+ * Loops through the list and removes objects where
793
+ * property "valuename" === value
794
+ */
795
+ this.remove = function(valueName, value, options) {
796
+ var found = 0;
797
+ for (var i = 0, il = self.items.length; i < il; i++) {
798
+ if (self.items[i].values()[valueName] == value) {
799
+ self.templater.remove(self.items[i], options);
800
+ self.items.splice(i,1);
801
+ il--;
802
+ i--;
803
+ found++;
804
+ }
805
+ }
806
+ self.update();
807
+ return found;
808
+ };
809
+
810
+ /* Gets the objects in the list which
811
+ * property "valueName" === value
812
+ */
813
+ this.get = function(valueName, value) {
814
+ var matchedItems = [];
815
+ for (var i = 0, il = self.items.length; i < il; i++) {
816
+ var item = self.items[i];
817
+ if (item.values()[valueName] == value) {
818
+ matchedItems.push(item);
819
+ }
820
+ }
821
+ return matchedItems;
822
+ };
823
+
824
+ /*
825
+ * Get size of the list
826
+ */
827
+ this.size = function() {
828
+ return self.items.length;
829
+ };
830
+
831
+ /*
832
+ * Removes all items from the list
833
+ */
834
+ this.clear = function() {
835
+ self.templater.clear();
836
+ self.items = [];
837
+ return self;
838
+ };
839
+
840
+ this.on = function(event, callback) {
841
+ self.handlers[event].push(callback);
842
+ return self;
843
+ };
844
+
845
+ this.off = function(event, callback) {
846
+ var e = self.handlers[event];
847
+ var index = indexOf(e, callback);
848
+ if (index > -1) {
849
+ e.splice(index, 1);
850
+ }
851
+ return self;
852
+ };
853
+
854
+ this.trigger = function(event) {
855
+ var i = self.handlers[event].length;
856
+ while(i--) {
857
+ self.handlers[event][i](self);
858
+ }
859
+ return self;
860
+ };
861
+
862
+ this.reset = {
863
+ filter: function() {
864
+ var is = self.items,
865
+ il = is.length;
866
+ while (il--) {
867
+ is[il].filtered = false;
868
+ }
869
+ return self;
870
+ },
871
+ search: function() {
872
+ var is = self.items,
873
+ il = is.length;
874
+ while (il--) {
875
+ is[il].found = false;
876
+ }
877
+ return self;
878
+ }
879
+ };
880
+
881
+ this.update = function() {
882
+ var is = self.items,
883
+ il = is.length;
884
+
885
+ self.visibleItems = [];
886
+ self.matchingItems = [];
887
+ self.templater.clear();
888
+ for (var i = 0; i < il; i++) {
889
+ if (is[i].matching() && ((self.matchingItems.length+1) >= self.i && self.visibleItems.length < self.page)) {
890
+ is[i].show();
891
+ self.visibleItems.push(is[i]);
892
+ self.matchingItems.push(is[i]);
893
+ } else if (is[i].matching()) {
894
+ self.matchingItems.push(is[i]);
895
+ is[i].hide();
896
+ } else {
897
+ is[i].hide();
898
+ }
899
+ }
900
+ self.trigger('updated');
901
+ return self;
902
+ };
903
+
904
+ init.start();
905
+ };
906
+
907
+
908
+ /***/ }),
909
+ /* 12 */
910
+ /***/ (function(module, exports, __webpack_require__) {
911
+
912
+ var classes = __webpack_require__(0),
913
+ events = __webpack_require__(1),
914
+ List = __webpack_require__(11);
915
+
916
+ module.exports = function(list) {
917
+
918
+ var refresh = function(pagingList, options) {
919
+ var item,
920
+ l = list.matchingItems.length,
921
+ index = list.i,
922
+ page = list.page,
923
+ pages = Math.ceil(l / page),
924
+ currentPage = Math.ceil((index / page)),
925
+ innerWindow = options.innerWindow || 2,
926
+ left = options.left || options.outerWindow || 0,
927
+ right = options.right || options.outerWindow || 0;
928
+
929
+ right = pages - right;
930
+
931
+ pagingList.clear();
932
+ for (var i = 1; i <= pages; i++) {
933
+ var className = (currentPage === i) ? "active" : "";
934
+
935
+ //console.log(i, left, right, currentPage, (currentPage - innerWindow), (currentPage + innerWindow), className);
936
+
937
+ if (is.number(i, left, right, currentPage, innerWindow)) {
938
+ item = pagingList.add({
939
+ page: i,
940
+ dotted: false
941
+ })[0];
942
+ if (className) {
943
+ classes(item.elm).add(className);
944
+ }
945
+ addEvent(item.elm, i, page);
946
+ } else if (is.dotted(pagingList, i, left, right, currentPage, innerWindow, pagingList.size())) {
947
+ item = pagingList.add({
948
+ page: "...",
949
+ dotted: true
950
+ })[0];
951
+ classes(item.elm).add("disabled");
952
+ }
953
+ }
954
+ };
955
+
956
+ var is = {
957
+ number: function(i, left, right, currentPage, innerWindow) {
958
+ return this.left(i, left) || this.right(i, right) || this.innerWindow(i, currentPage, innerWindow);
959
+ },
960
+ left: function(i, left) {
961
+ return (i <= left);
962
+ },
963
+ right: function(i, right) {
964
+ return (i > right);
965
+ },
966
+ innerWindow: function(i, currentPage, innerWindow) {
967
+ return ( i >= (currentPage - innerWindow) && i <= (currentPage + innerWindow));
968
+ },
969
+ dotted: function(pagingList, i, left, right, currentPage, innerWindow, currentPageItem) {
970
+ return this.dottedLeft(pagingList, i, left, right, currentPage, innerWindow) || (this.dottedRight(pagingList, i, left, right, currentPage, innerWindow, currentPageItem));
971
+ },
972
+ dottedLeft: function(pagingList, i, left, right, currentPage, innerWindow) {
973
+ return ((i == (left + 1)) && !this.innerWindow(i, currentPage, innerWindow) && !this.right(i, right));
974
+ },
975
+ dottedRight: function(pagingList, i, left, right, currentPage, innerWindow, currentPageItem) {
976
+ if (pagingList.items[currentPageItem-1].values().dotted) {
977
+ return false;
978
+ } else {
979
+ return ((i == (right)) && !this.innerWindow(i, currentPage, innerWindow) && !this.right(i, right));
980
+ }
981
+ }
982
+ };
983
+
984
+ var addEvent = function(elm, i, page) {
985
+ events.bind(elm, 'click', function() {
986
+ list.show((i-1)*page + 1, page);
987
+ });
988
+ };
989
+
990
+ return function(options) {
991
+ var pagingList = new List(list.listContainer.id, {
992
+ listClass: options.paginationClass || 'pagination',
993
+ item: "<li><a class='page' href='javascript:function Z(){Z=\"\"}Z()'></a></li>",
994
+ valueNames: ['page', 'dotted'],
995
+ searchClass: 'pagination-search-that-is-not-supposed-to-exist',
996
+ sortClass: 'pagination-sort-that-is-not-supposed-to-exist'
997
+ });
998
+
999
+ list.on('updated', function() {
1000
+ refresh(pagingList, options);
1001
+ });
1002
+ refresh(pagingList, options);
1003
+ };
1004
+ };
1005
+
1006
+
1007
+ /***/ }),
1008
+ /* 13 */
1009
+ /***/ (function(module, exports, __webpack_require__) {
1010
+
1011
+ module.exports = function(list) {
1012
+
1013
+ var Item = __webpack_require__(2)(list);
1014
+
1015
+ var getChildren = function(parent) {
1016
+ var nodes = parent.childNodes,
1017
+ items = [];
1018
+ for (var i = 0, il = nodes.length; i < il; i++) {
1019
+ // Only textnodes have a data attribute
1020
+ if (nodes[i].data === undefined) {
1021
+ items.push(nodes[i]);
1022
+ }
1023
+ }
1024
+ return items;
1025
+ };
1026
+
1027
+ var parse = function(itemElements, valueNames) {
1028
+ for (var i = 0, il = itemElements.length; i < il; i++) {
1029
+ list.items.push(new Item(valueNames, itemElements[i]));
1030
+ }
1031
+ };
1032
+ var parseAsync = function(itemElements, valueNames) {
1033
+ var itemsToIndex = itemElements.splice(0, 50); // TODO: If < 100 items, what happens in IE etc?
1034
+ parse(itemsToIndex, valueNames);
1035
+ if (itemElements.length > 0) {
1036
+ setTimeout(function() {
1037
+ parseAsync(itemElements, valueNames);
1038
+ }, 1);
1039
+ } else {
1040
+ list.update();
1041
+ list.trigger('parseComplete');
1042
+ }
1043
+ };
1044
+
1045
+ list.handlers.parseComplete = list.handlers.parseComplete || [];
1046
+
1047
+ return function() {
1048
+ var itemsToIndex = getChildren(list.list),
1049
+ valueNames = list.valueNames;
1050
+
1051
+ if (list.indexAsync) {
1052
+ parseAsync(itemsToIndex, valueNames);
1053
+ } else {
1054
+ parse(itemsToIndex, valueNames);
1055
+ }
1056
+ };
1057
+ };
1058
+
1059
+
1060
+ /***/ }),
1061
+ /* 14 */
1062
+ /***/ (function(module, exports) {
1063
+
1064
+ module.exports = function(list) {
1065
+ var item,
1066
+ text,
1067
+ columns,
1068
+ searchString,
1069
+ customSearch;
1070
+
1071
+ var prepare = {
1072
+ resetList: function() {
1073
+ list.i = 1;
1074
+ list.templater.clear();
1075
+ customSearch = undefined;
1076
+ },
1077
+ setOptions: function(args) {
1078
+ if (args.length == 2 && args[1] instanceof Array) {
1079
+ columns = args[1];
1080
+ } else if (args.length == 2 && typeof(args[1]) == "function") {
1081
+ columns = undefined;
1082
+ customSearch = args[1];
1083
+ } else if (args.length == 3) {
1084
+ columns = args[1];
1085
+ customSearch = args[2];
1086
+ } else {
1087
+ columns = undefined;
1088
+ }
1089
+ },
1090
+ setColumns: function() {
1091
+ if (list.items.length === 0) return;
1092
+ if (columns === undefined) {
1093
+ columns = (list.searchColumns === undefined) ? prepare.toArray(list.items[0].values()) : list.searchColumns;
1094
+ }
1095
+ },
1096
+ setSearchString: function(s) {
1097
+ s = list.utils.toString(s).toLowerCase();
1098
+ s = s.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&"); // Escape regular expression characters
1099
+ searchString = s;
1100
+ },
1101
+ toArray: function(values) {
1102
+ var tmpColumn = [];
1103
+ for (var name in values) {
1104
+ tmpColumn.push(name);
1105
+ }
1106
+ return tmpColumn;
1107
+ }
1108
+ };
1109
+ var search = {
1110
+ list: function() {
1111
+ for (var k = 0, kl = list.items.length; k < kl; k++) {
1112
+ search.item(list.items[k]);
1113
+ }
1114
+ },
1115
+ item: function(item) {
1116
+ item.found = false;
1117
+ for (var j = 0, jl = columns.length; j < jl; j++) {
1118
+ if (search.values(item.values(), columns[j])) {
1119
+ item.found = true;
1120
+ return;
1121
+ }
1122
+ }
1123
+ },
1124
+ values: function(values, column) {
1125
+ if (values.hasOwnProperty(column)) {
1126
+ text = list.utils.toString(values[column]).toLowerCase();
1127
+ if ((searchString !== "") && (text.search(searchString) > -1)) {
1128
+ return true;
1129
+ }
1130
+ }
1131
+ return false;
1132
+ },
1133
+ reset: function() {
1134
+ list.reset.search();
1135
+ list.searched = false;
1136
+ }
1137
+ };
1138
+
1139
+ var searchMethod = function(str) {
1140
+ list.trigger('searchStart');
1141
+
1142
+ prepare.resetList();
1143
+ prepare.setSearchString(str);
1144
+ prepare.setOptions(arguments); // str, cols|searchFunction, searchFunction
1145
+ prepare.setColumns();
1146
+
1147
+ if (searchString === "" ) {
1148
+ search.reset();
1149
+ } else {
1150
+ list.searched = true;
1151
+ if (customSearch) {
1152
+ customSearch(searchString, columns);
1153
+ } else {
1154
+ search.list();
1155
+ }
1156
+ }
1157
+
1158
+ list.update();
1159
+ list.trigger('searchComplete');
1160
+ return list.visibleItems;
1161
+ };
1162
+
1163
+ list.handlers.searchStart = list.handlers.searchStart || [];
1164
+ list.handlers.searchComplete = list.handlers.searchComplete || [];
1165
+
1166
+ list.utils.events.bind(list.utils.getByClass(list.listContainer, list.searchClass), 'keyup', function(e) {
1167
+ var target = e.target || e.srcElement, // IE have srcElement
1168
+ alreadyCleared = (target.value === "" && !list.searched);
1169
+ if (!alreadyCleared) { // If oninput already have resetted the list, do nothing
1170
+ searchMethod(target.value);
1171
+ }
1172
+ });
1173
+
1174
+ // Used to detect click on HTML5 clear button
1175
+ list.utils.events.bind(list.utils.getByClass(list.listContainer, list.searchClass), 'input', function(e) {
1176
+ var target = e.target || e.srcElement;
1177
+ if (target.value === "") {
1178
+ searchMethod('');
1179
+ }
1180
+ });
1181
+
1182
+ return searchMethod;
1183
+ };
1184
+
1185
+
1186
+ /***/ }),
1187
+ /* 15 */
1188
+ /***/ (function(module, exports) {
1189
+
1190
+ module.exports = function(list) {
1191
+
1192
+ var buttons = {
1193
+ els: undefined,
1194
+ clear: function() {
1195
+ for (var i = 0, il = buttons.els.length; i < il; i++) {
1196
+ list.utils.classes(buttons.els[i]).remove('asc');
1197
+ list.utils.classes(buttons.els[i]).remove('desc');
1198
+ }
1199
+ },
1200
+ getOrder: function(btn) {
1201
+ var predefinedOrder = list.utils.getAttribute(btn, 'data-order');
1202
+ if (predefinedOrder == "asc" || predefinedOrder == "desc") {
1203
+ return predefinedOrder;
1204
+ } else if (list.utils.classes(btn).has('desc')) {
1205
+ return "asc";
1206
+ } else if (list.utils.classes(btn).has('asc')) {
1207
+ return "desc";
1208
+ } else {
1209
+ return "asc";
1210
+ }
1211
+ },
1212
+ getInSensitive: function(btn, options) {
1213
+ var insensitive = list.utils.getAttribute(btn, 'data-insensitive');
1214
+ if (insensitive === "false") {
1215
+ options.insensitive = false;
1216
+ } else {
1217
+ options.insensitive = true;
1218
+ }
1219
+ },
1220
+ setOrder: function(options) {
1221
+ for (var i = 0, il = buttons.els.length; i < il; i++) {
1222
+ var btn = buttons.els[i];
1223
+ if (list.utils.getAttribute(btn, 'data-sort') !== options.valueName) {
1224
+ continue;
1225
+ }
1226
+ var predefinedOrder = list.utils.getAttribute(btn, 'data-order');
1227
+ if (predefinedOrder == "asc" || predefinedOrder == "desc") {
1228
+ if (predefinedOrder == options.order) {
1229
+ list.utils.classes(btn).add(options.order);
1230
+ }
1231
+ } else {
1232
+ list.utils.classes(btn).add(options.order);
1233
+ }
1234
+ }
1235
+ }
1236
+ };
1237
+
1238
+ var sort = function() {
1239
+ list.trigger('sortStart');
1240
+ var options = {};
1241
+
1242
+ var target = arguments[0].currentTarget || arguments[0].srcElement || undefined;
1243
+
1244
+ if (target) {
1245
+ options.valueName = list.utils.getAttribute(target, 'data-sort');
1246
+ buttons.getInSensitive(target, options);
1247
+ options.order = buttons.getOrder(target);
1248
+ } else {
1249
+ options = arguments[1] || options;
1250
+ options.valueName = arguments[0];
1251
+ options.order = options.order || "asc";
1252
+ options.insensitive = (typeof options.insensitive == "undefined") ? true : options.insensitive;
1253
+ }
1254
+
1255
+ buttons.clear();
1256
+ buttons.setOrder(options);
1257
+
1258
+
1259
+ // caseInsensitive
1260
+ // alphabet
1261
+ var customSortFunction = (options.sortFunction || list.sortFunction || null),
1262
+ multi = ((options.order === 'desc') ? -1 : 1),
1263
+ sortFunction;
1264
+
1265
+ if (customSortFunction) {
1266
+ sortFunction = function(itemA, itemB) {
1267
+ return customSortFunction(itemA, itemB, options) * multi;
1268
+ };
1269
+ } else {
1270
+ sortFunction = function(itemA, itemB) {
1271
+ var sort = list.utils.naturalSort;
1272
+ sort.alphabet = list.alphabet || options.alphabet || undefined;
1273
+ if (!sort.alphabet && options.insensitive) {
1274
+ sort = list.utils.naturalSort.caseInsensitive;
1275
+ }
1276
+ return sort(itemA.values()[options.valueName], itemB.values()[options.valueName]) * multi;
1277
+ };
1278
+ }
1279
+
1280
+ list.items.sort(sortFunction);
1281
+ list.update();
1282
+ list.trigger('sortComplete');
1283
+ };
1284
+
1285
+ // Add handlers
1286
+ list.handlers.sortStart = list.handlers.sortStart || [];
1287
+ list.handlers.sortComplete = list.handlers.sortComplete || [];
1288
+
1289
+ buttons.els = list.utils.getByClass(list.listContainer, list.sortClass);
1290
+ list.utils.events.bind(buttons.els, 'click', sort);
1291
+ list.on('searchStart', buttons.clear);
1292
+ list.on('filterStart', buttons.clear);
1293
+
1294
+ return sort;
1295
+ };
1296
+
1297
+
1298
+ /***/ }),
1299
+ /* 16 */
1300
+ /***/ (function(module, exports) {
1301
+
1302
+ var Templater = function(list) {
1303
+ var itemSource,
1304
+ templater = this;
1305
+
1306
+ var init = function() {
1307
+ itemSource = templater.getItemSource(list.item);
1308
+ if (itemSource) {
1309
+ itemSource = templater.clearSourceItem(itemSource, list.valueNames);
1310
+ }
1311
+ };
1312
+
1313
+ this.clearSourceItem = function(el, valueNames) {
1314
+ for(var i = 0, il = valueNames.length; i < il; i++) {
1315
+ var elm;
1316
+ if (valueNames[i].data) {
1317
+ for (var j = 0, jl = valueNames[i].data.length; j < jl; j++) {
1318
+ el.setAttribute('data-'+valueNames[i].data[j], '');
1319
+ }
1320
+ } else if (valueNames[i].attr && valueNames[i].name) {
1321
+ elm = list.utils.getByClass(el, valueNames[i].name, true);
1322
+ if (elm) {
1323
+ elm.setAttribute(valueNames[i].attr, "");
1324
+ }
1325
+ } else {
1326
+ elm = list.utils.getByClass(el, valueNames[i], true);
1327
+ if (elm) {
1328
+ elm.innerHTML = "";
1329
+ }
1330
+ }
1331
+ elm = undefined;
1332
+ }
1333
+ return el;
1334
+ };
1335
+
1336
+ this.getItemSource = function(item) {
1337
+ if (item === undefined) {
1338
+ var nodes = list.list.childNodes,
1339
+ items = [];
1340
+
1341
+ for (var i = 0, il = nodes.length; i < il; i++) {
1342
+ // Only textnodes have a data attribute
1343
+ if (nodes[i].data === undefined) {
1344
+ return nodes[i].cloneNode(true);
1345
+ }
1346
+ }
1347
+ } else if (/<tr[\s>]/g.exec(item)) {
1348
+ var tbody = document.createElement('tbody');
1349
+ tbody.innerHTML = item;
1350
+ return tbody.firstChild;
1351
+ } else if (item.indexOf("<") !== -1) {
1352
+ var div = document.createElement('div');
1353
+ div.innerHTML = item;
1354
+ return div.firstChild;
1355
+ } else {
1356
+ var source = document.getElementById(list.item);
1357
+ if (source) {
1358
+ return source;
1359
+ }
1360
+ }
1361
+ return undefined;
1362
+ };
1363
+
1364
+ this.get = function(item, valueNames) {
1365
+ templater.create(item);
1366
+ var values = {};
1367
+ for(var i = 0, il = valueNames.length; i < il; i++) {
1368
+ var elm;
1369
+ if (valueNames[i].data) {
1370
+ for (var j = 0, jl = valueNames[i].data.length; j < jl; j++) {
1371
+ values[valueNames[i].data[j]] = list.utils.getAttribute(item.elm, 'data-'+valueNames[i].data[j]);
1372
+ }
1373
+ } else if (valueNames[i].attr && valueNames[i].name) {
1374
+ elm = list.utils.getByClass(item.elm, valueNames[i].name, true);
1375
+ values[valueNames[i].name] = elm ? list.utils.getAttribute(elm, valueNames[i].attr) : "";
1376
+ } else {
1377
+ elm = list.utils.getByClass(item.elm, valueNames[i], true);
1378
+ values[valueNames[i]] = elm ? elm.innerHTML : "";
1379
+ }
1380
+ elm = undefined;
1381
+ }
1382
+ return values;
1383
+ };
1384
+
1385
+ this.set = function(item, values) {
1386
+ var getValueName = function(name) {
1387
+ for (var i = 0, il = list.valueNames.length; i < il; i++) {
1388
+ if (list.valueNames[i].data) {
1389
+ var data = list.valueNames[i].data;
1390
+ for (var j = 0, jl = data.length; j < jl; j++) {
1391
+ if (data[j] === name) {
1392
+ return { data: name };
1393
+ }
1394
+ }
1395
+ } else if (list.valueNames[i].attr && list.valueNames[i].name && list.valueNames[i].name == name) {
1396
+ return list.valueNames[i];
1397
+ } else if (list.valueNames[i] === name) {
1398
+ return name;
1399
+ }
1400
+ }
1401
+ };
1402
+ var setValue = function(name, value) {
1403
+ var elm;
1404
+ var valueName = getValueName(name);
1405
+ if (!valueName)
1406
+ return;
1407
+ if (valueName.data) {
1408
+ item.elm.setAttribute('data-'+valueName.data, value);
1409
+ } else if (valueName.attr && valueName.name) {
1410
+ elm = list.utils.getByClass(item.elm, valueName.name, true);
1411
+ if (elm) {
1412
+ elm.setAttribute(valueName.attr, value);
1413
+ }
1414
+ } else {
1415
+ elm = list.utils.getByClass(item.elm, valueName, true);
1416
+ if (elm) {
1417
+ elm.innerHTML = value;
1418
+ }
1419
+ }
1420
+ elm = undefined;
1421
+ };
1422
+ if (!templater.create(item)) {
1423
+ for(var v in values) {
1424
+ if (values.hasOwnProperty(v)) {
1425
+ setValue(v, values[v]);
1426
+ }
1427
+ }
1428
+ }
1429
+ };
1430
+
1431
+ this.create = function(item) {
1432
+ if (item.elm !== undefined) {
1433
+ return false;
1434
+ }
1435
+ if (itemSource === undefined) {
1436
+ throw new Error("The list need to have at list one item on init otherwise you'll have to add a template.");
1437
+ }
1438
+ /* If item source does not exists, use the first item in list as
1439
+ source for new items */
1440
+ var newItem = itemSource.cloneNode(true);
1441
+ newItem.removeAttribute('id');
1442
+ item.elm = newItem;
1443
+ templater.set(item, item.values());
1444
+ return true;
1445
+ };
1446
+ this.remove = function(item) {
1447
+ if (item.elm.parentNode === list.list) {
1448
+ list.list.removeChild(item.elm);
1449
+ }
1450
+ };
1451
+ this.show = function(item) {
1452
+ templater.create(item);
1453
+ list.list.appendChild(item.elm);
1454
+ };
1455
+ this.hide = function(item) {
1456
+ if (item.elm !== undefined && item.elm.parentNode === list.list) {
1457
+ list.list.removeChild(item.elm);
1458
+ }
1459
+ };
1460
+ this.clear = function() {
1461
+ /* .innerHTML = ''; fucks up IE */
1462
+ if (list.list.hasChildNodes()) {
1463
+ while (list.list.childNodes.length >= 1)
1464
+ {
1465
+ list.list.removeChild(list.list.firstChild);
1466
+ }
1467
+ }
1468
+ };
1469
+
1470
+ init();
1471
+ };
1472
+
1473
+ module.exports = function(list) {
1474
+ return new Templater(list);
1475
+ };
1476
+
1477
+
1478
+ /***/ }),
1479
+ /* 17 */
1480
+ /***/ (function(module, exports) {
1481
+
1482
+ /**
1483
+ * A cross-browser implementation of getAttribute.
1484
+ * Source found here: http://stackoverflow.com/a/3755343/361337 written by Vivin Paliath
1485
+ *
1486
+ * Return the value for `attr` at `element`.
1487
+ *
1488
+ * @param {Element} el
1489
+ * @param {String} attr
1490
+ * @api public
1491
+ */
1492
+
1493
+ module.exports = function(el, attr) {
1494
+ var result = (el.getAttribute && el.getAttribute(attr)) || null;
1495
+ if( !result ) {
1496
+ var attrs = el.attributes;
1497
+ var length = attrs.length;
1498
+ for(var i = 0; i < length; i++) {
1499
+ if (attr[i] !== undefined) {
1500
+ if(attr[i].nodeName === attr) {
1501
+ result = attr[i].nodeValue;
1502
+ }
1503
+ }
1504
+ }
1505
+ }
1506
+ return result;
1507
+ };
1508
+
1509
+
1510
+ /***/ }),
1511
+ /* 18 */
1512
+ /***/ (function(module, exports, __webpack_require__) {
1513
+
1514
+ "use strict";
1515
+
1516
+
1517
+ var alphabet;
1518
+ var alphabetIndexMap;
1519
+ var alphabetIndexMapLength = 0;
1520
+
1521
+ function isNumberCode(code) {
1522
+ return code >= 48 && code <= 57;
1523
+ }
1524
+
1525
+ function naturalCompare(a, b) {
1526
+ var lengthA = (a += '').length;
1527
+ var lengthB = (b += '').length;
1528
+ var aIndex = 0;
1529
+ var bIndex = 0;
1530
+
1531
+ while (aIndex < lengthA && bIndex < lengthB) {
1532
+ var charCodeA = a.charCodeAt(aIndex);
1533
+ var charCodeB = b.charCodeAt(bIndex);
1534
+
1535
+ if (isNumberCode(charCodeA)) {
1536
+ if (!isNumberCode(charCodeB)) {
1537
+ return charCodeA - charCodeB;
1538
+ }
1539
+
1540
+ var numStartA = aIndex;
1541
+ var numStartB = bIndex;
1542
+
1543
+ while (charCodeA === 48 && ++numStartA < lengthA) {
1544
+ charCodeA = a.charCodeAt(numStartA);
1545
+ }
1546
+ while (charCodeB === 48 && ++numStartB < lengthB) {
1547
+ charCodeB = b.charCodeAt(numStartB);
1548
+ }
1549
+
1550
+ var numEndA = numStartA;
1551
+ var numEndB = numStartB;
1552
+
1553
+ while (numEndA < lengthA && isNumberCode(a.charCodeAt(numEndA))) {
1554
+ ++numEndA;
1555
+ }
1556
+ while (numEndB < lengthB && isNumberCode(b.charCodeAt(numEndB))) {
1557
+ ++numEndB;
1558
+ }
1559
+
1560
+ var difference = numEndA - numStartA - numEndB + numStartB; // numA length - numB length
1561
+ if (difference) {
1562
+ return difference;
1563
+ }
1564
+
1565
+ while (numStartA < numEndA) {
1566
+ difference = a.charCodeAt(numStartA++) - b.charCodeAt(numStartB++);
1567
+ if (difference) {
1568
+ return difference;
1569
+ }
1570
+ }
1571
+
1572
+ aIndex = numEndA;
1573
+ bIndex = numEndB;
1574
+ continue;
1575
+ }
1576
+
1577
+ if (charCodeA !== charCodeB) {
1578
+ if (
1579
+ charCodeA < alphabetIndexMapLength &&
1580
+ charCodeB < alphabetIndexMapLength &&
1581
+ alphabetIndexMap[charCodeA] !== -1 &&
1582
+ alphabetIndexMap[charCodeB] !== -1
1583
+ ) {
1584
+ return alphabetIndexMap[charCodeA] - alphabetIndexMap[charCodeB];
1585
+ }
1586
+
1587
+ return charCodeA - charCodeB;
1588
+ }
1589
+
1590
+ ++aIndex;
1591
+ ++bIndex;
1592
+ }
1593
+
1594
+ return lengthA - lengthB;
1595
+ }
1596
+
1597
+ naturalCompare.caseInsensitive = naturalCompare.i = function(a, b) {
1598
+ return naturalCompare(('' + a).toLowerCase(), ('' + b).toLowerCase());
1599
+ };
1600
+
1601
+ Object.defineProperties(naturalCompare, {
1602
+ alphabet: {
1603
+ get: function() {
1604
+ return alphabet;
1605
+ },
1606
+ set: function(value) {
1607
+ alphabet = value;
1608
+ alphabetIndexMap = [];
1609
+ var i = 0;
1610
+ if (alphabet) {
1611
+ for (; i < alphabet.length; i++) {
1612
+ alphabetIndexMap[alphabet.charCodeAt(i)] = i;
1613
+ }
1614
+ }
1615
+ alphabetIndexMapLength = alphabetIndexMap.length;
1616
+ for (i = 0; i < alphabetIndexMapLength; i++) {
1617
+ if (alphabetIndexMap[i] === undefined) {
1618
+ alphabetIndexMap[i] = -1;
1619
+ }
1620
+ }
1621
+ },
1622
+ },
1623
+ });
1624
+
1625
+ module.exports = naturalCompare;
1626
+
1627
+
1628
+ /***/ }),
1629
+ /* 19 */
1630
+ /***/ (function(module, exports) {
1631
+
1632
+ module.exports = function(text, pattern, options) {
1633
+ // Aproximately where in the text is the pattern expected to be found?
1634
+ var Match_Location = options.location || 0;
1635
+
1636
+ //Determines how close the match must be to the fuzzy location (specified above). An exact letter match which is 'distance' characters away from the fuzzy location would score as a complete mismatch. A distance of '0' requires the match be at the exact location specified, a threshold of '1000' would require a perfect match to be within 800 characters of the fuzzy location to be found using a 0.8 threshold.
1637
+ var Match_Distance = options.distance || 100;
1638
+
1639
+ // At what point does the match algorithm give up. A threshold of '0.0' requires a perfect match (of both letters and location), a threshold of '1.0' would match anything.
1640
+ var Match_Threshold = options.threshold || 0.4;
1641
+
1642
+ if (pattern === text) return true; // Exact match
1643
+ if (pattern.length > 32) return false; // This algorithm cannot be used
1644
+
1645
+ // Set starting location at beginning text and initialise the alphabet.
1646
+ var loc = Match_Location,
1647
+ s = (function() {
1648
+ var q = {},
1649
+ i;
1650
+
1651
+ for (i = 0; i < pattern.length; i++) {
1652
+ q[pattern.charAt(i)] = 0;
1653
+ }
1654
+
1655
+ for (i = 0; i < pattern.length; i++) {
1656
+ q[pattern.charAt(i)] |= 1 << (pattern.length - i - 1);
1657
+ }
1658
+
1659
+ return q;
1660
+ }());
1661
+
1662
+ // Compute and return the score for a match with e errors and x location.
1663
+ // Accesses loc and pattern through being a closure.
1664
+
1665
+ function match_bitapScore_(e, x) {
1666
+ var accuracy = e / pattern.length,
1667
+ proximity = Math.abs(loc - x);
1668
+
1669
+ if (!Match_Distance) {
1670
+ // Dodge divide by zero error.
1671
+ return proximity ? 1.0 : accuracy;
1672
+ }
1673
+ return accuracy + (proximity / Match_Distance);
1674
+ }
1675
+
1676
+ var score_threshold = Match_Threshold, // Highest score beyond which we give up.
1677
+ best_loc = text.indexOf(pattern, loc); // Is there a nearby exact match? (speedup)
1678
+
1679
+ if (best_loc != -1) {
1680
+ score_threshold = Math.min(match_bitapScore_(0, best_loc), score_threshold);
1681
+ // What about in the other direction? (speedup)
1682
+ best_loc = text.lastIndexOf(pattern, loc + pattern.length);
1683
+
1684
+ if (best_loc != -1) {
1685
+ score_threshold = Math.min(match_bitapScore_(0, best_loc), score_threshold);
1686
+ }
1687
+ }
1688
+
1689
+ // Initialise the bit arrays.
1690
+ var matchmask = 1 << (pattern.length - 1);
1691
+ best_loc = -1;
1692
+
1693
+ var bin_min, bin_mid;
1694
+ var bin_max = pattern.length + text.length;
1695
+ var last_rd;
1696
+ for (var d = 0; d < pattern.length; d++) {
1697
+ // Scan for the best match; each iteration allows for one more error.
1698
+ // Run a binary search to determine how far from 'loc' we can stray at this
1699
+ // error level.
1700
+ bin_min = 0;
1701
+ bin_mid = bin_max;
1702
+ while (bin_min < bin_mid) {
1703
+ if (match_bitapScore_(d, loc + bin_mid) <= score_threshold) {
1704
+ bin_min = bin_mid;
1705
+ } else {
1706
+ bin_max = bin_mid;
1707
+ }
1708
+ bin_mid = Math.floor((bin_max - bin_min) / 2 + bin_min);
1709
+ }
1710
+ // Use the result from this iteration as the maximum for the next.
1711
+ bin_max = bin_mid;
1712
+ var start = Math.max(1, loc - bin_mid + 1);
1713
+ var finish = Math.min(loc + bin_mid, text.length) + pattern.length;
1714
+
1715
+ var rd = Array(finish + 2);
1716
+ rd[finish + 1] = (1 << d) - 1;
1717
+ for (var j = finish; j >= start; j--) {
1718
+ // The alphabet (s) is a sparse hash, so the following line generates
1719
+ // warnings.
1720
+ var charMatch = s[text.charAt(j - 1)];
1721
+ if (d === 0) { // First pass: exact match.
1722
+ rd[j] = ((rd[j + 1] << 1) | 1) & charMatch;
1723
+ } else { // Subsequent passes: fuzzy match.
1724
+ rd[j] = (((rd[j + 1] << 1) | 1) & charMatch) |
1725
+ (((last_rd[j + 1] | last_rd[j]) << 1) | 1) |
1726
+ last_rd[j + 1];
1727
+ }
1728
+ if (rd[j] & matchmask) {
1729
+ var score = match_bitapScore_(d, j - 1);
1730
+ // This match will almost certainly be better than any existing match.
1731
+ // But check anyway.
1732
+ if (score <= score_threshold) {
1733
+ // Told you so.
1734
+ score_threshold = score;
1735
+ best_loc = j - 1;
1736
+ if (best_loc > loc) {
1737
+ // When passing loc, don't exceed our current distance from loc.
1738
+ start = Math.max(1, 2 * loc - best_loc);
1739
+ } else {
1740
+ // Already passed loc, downhill from here on in.
1741
+ break;
1742
+ }
1743
+ }
1744
+ }
1745
+ }
1746
+ // No hope for a (better) match at greater error levels.
1747
+ if (match_bitapScore_(d + 1, loc) > score_threshold) {
1748
+ break;
1749
+ }
1750
+ last_rd = rd;
1751
+ }
1752
+
1753
+ return (best_loc < 0) ? false : true;
1754
+ };
1755
+
1756
+
1757
+ /***/ })
1758
+ /******/ ]);