listjs-rails 1.0.2 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 087d23fbff7afa8239893b3f78d337af7499b357
4
- data.tar.gz: c44407750874ae87527f8fb8034df2532a506b2d
3
+ metadata.gz: 5b1aa4cc10a0b9a5783f561f7f485e76edef308b
4
+ data.tar.gz: b9a579e520c632916b8d3a01901c49480eb7ad7c
5
5
  SHA512:
6
- metadata.gz: 295bd6c59d5c1ae38dfc4dfa9cb423b0acb47090758d8a58ea6b95fa999552e83bbed7c5a6fbd4fadcb78a2599d8e11545bb974b4669e615af6070a80a70af6b
7
- data.tar.gz: 65615a75bcfeaaf888b9723f042b45ebd4d283c180665bdf62759df29b4ded41ef56d0ac1744507b563bca739c999e3e1dbf8213ec08f41a339a62bfa9130dae
6
+ metadata.gz: 581d62a49e8fa57eecb7b62e5eb1b4bd19019008753750f3e10589ca713476cac26baa729c0778cdf881a9e491ce9f89d2c14d72beaa926f952f3550420d7ffa
7
+ data.tar.gz: 84de0263e295e12a0919fc21f7fd358c73a813ef69c5b8f3f5eb7e79db3412ba72d880c9b5ce22617d02b94f0cda5e13f8c2b3af77f28d7ed4be5a6eb2b69ea4
@@ -315,26 +315,45 @@ ClassList.prototype.removeMatching = function(re){
315
315
  };
316
316
 
317
317
  /**
318
- * Toggle class `name`.
318
+ * Toggle class `name`, can force state via `force`.
319
+ *
320
+ * For browsers that support classList, but do not support `force` yet,
321
+ * the mistake will be detected and corrected.
319
322
  *
320
323
  * @param {String} name
324
+ * @param {Boolean} force
321
325
  * @return {ClassList}
322
326
  * @api public
323
327
  */
324
328
 
325
- ClassList.prototype.toggle = function(name){
329
+ ClassList.prototype.toggle = function(name, force){
326
330
  // classList
327
331
  if (this.list) {
328
- this.list.toggle(name);
332
+ if ("undefined" !== typeof force) {
333
+ if (force !== this.list.toggle(name, force)) {
334
+ this.list.toggle(name); // toggle again to correct
335
+ }
336
+ } else {
337
+ this.list.toggle(name);
338
+ }
329
339
  return this;
330
340
  }
331
341
 
332
342
  // fallback
333
- if (this.has(name)) {
334
- this.remove(name);
343
+ if ("undefined" !== typeof force) {
344
+ if (!force) {
345
+ this.remove(name);
346
+ } else {
347
+ this.add(name);
348
+ }
335
349
  } else {
336
- this.add(name);
350
+ if (this.has(name)) {
351
+ this.remove(name);
352
+ } else {
353
+ this.add(name);
354
+ }
337
355
  }
356
+
338
357
  return this;
339
358
  };
340
359
 
@@ -431,77 +450,39 @@ exports.unbind = function(el, type, fn, capture){
431
450
  return fn;
432
451
  };
433
452
  });
434
- require.register("javve-is-collection/index.js", function(exports, require, module){
435
- var typeOf = require('type')
436
-
453
+ require.register("javve-to-array/index.js", function(exports, require, module){
437
454
  /**
438
- * Evaluates _obj_ to determine if it's an array, an array-like collection, or
439
- * something else. This is useful when working with the function `arguments`
440
- * collection and `HTMLElement` collections.
441
- * Note: This implementation doesn't consider elements that are also
442
- *
455
+ * Convert an array-like object into an `Array`.
456
+ * If `collection` is already an `Array`, then will return a clone of `collection`.
443
457
  *
458
+ * @param {Array | Mixed} collection An `Array` or array-like object to convert e.g. `arguments` or `NodeList`
459
+ * @return {Array} Naive conversion of `collection` to a new `Array`.
460
+ * @api public
461
+ */
444
462
 
445
- collections, such as `<form>` and `<select>`, to be array-like.
446
-
447
- @method test
448
- @param {Object} obj Object to test.
449
- @return {Number} A number indicating the results of the test:
450
-
451
- * 0: Neither an array nor an array-like collection.
452
- * 1: Real array.
453
- * 2: Array-like collection.
454
-
455
- @api private
456
- **/
457
- module.exports = function isCollection(obj) {
458
- var type = typeOf(obj)
459
- if (type === 'array') return 1
460
- switch (type) {
461
- case 'arguments': return 2
462
- case 'object':
463
- if (isNodeList(obj)) return 2
464
- try {
465
- // indexed, but no tagName (element) or scrollTo/document (window. From DOM.isWindow test which we can't use here),
466
- // or functions without apply/call (Safari
467
- // HTMLElementCollection bug).
468
- if ('length' in obj
469
- && !obj.tagName
470
- && !(obj.scrollTo && obj.document)
471
- && !obj.apply) {
472
- return 2
473
- }
474
- } catch (ex) {}
475
- case 'function':
476
- if (isNodeList(obj)) return 2
477
- try {
478
- // indexed, but no tagName (element) or scrollTo/document (window. From DOM.isWindow test which we can't use here),
479
- // or functions without apply/call (Safari
480
- // HTMLElementCollection bug).
481
- if ('length' in obj
482
- && !obj.tagName
483
- && !(obj.scrollTo && obj.document)
484
- && !obj.apply) {
485
- return 2
486
- }
487
- } catch (ex) {}
488
- default:
489
- return 0
463
+ module.exports = function toArray(collection) {
464
+ if (typeof collection === 'undefined') return []
465
+ if (collection === null) return [null]
466
+ if (collection === window) return [window]
467
+ if (typeof collection === 'string') return [collection]
468
+ if (collection instanceof Array) return collection
469
+ if (typeof collection.length != 'number') return [collection]
470
+ if (typeof collection === 'function') return [collection]
471
+
472
+ var arr = []
473
+ for (var i = 0; i < collection.length; i++) {
474
+ if (Object.prototype.hasOwnProperty.call(collection, i) || i in collection) {
475
+ arr.push(collection[i])
490
476
  }
477
+ }
478
+ if (!arr.length) return []
479
+ return arr
491
480
  }
492
481
 
493
- function isNodeList(nodes) {
494
- return typeof nodes === 'object'
495
- && /^\[object (NodeList)\]$/.test(Object.prototype.toString.call(nodes))
496
- && nodes.hasOwnProperty('length')
497
- && (nodes.length == 0 || (typeof nodes[0] === "object" && nodes[0].nodeType > 0))
498
- }
499
-
500
-
501
482
  });
502
483
  require.register("javve-events/index.js", function(exports, require, module){
503
484
  var events = require('event'),
504
- isCollection = require('is-collection');
485
+ toArray = require('to-array');
505
486
 
506
487
  /**
507
488
  * Bind `el` event `type` to `fn`.
@@ -514,12 +495,9 @@ var events = require('event'),
514
495
  */
515
496
 
516
497
  exports.bind = function(el, type, fn, capture){
517
- if (!isCollection(el)) {
518
- events.bind(el, type, fn, capture);
519
- } else if ( el && el[0] !== undefined ) {
520
- for ( var i = 0; i < el.length; i++ ) {
521
- events.bind(el[i], type, fn, capture);
522
- }
498
+ el = toArray(el);
499
+ for ( var i = 0; i < el.length; i++ ) {
500
+ events.bind(el[i], type, fn, capture);
523
501
  }
524
502
  };
525
503
 
@@ -534,14 +512,12 @@ exports.bind = function(el, type, fn, capture){
534
512
  */
535
513
 
536
514
  exports.unbind = function(el, type, fn, capture){
537
- if (!isCollection(el)) {
538
- events.unbind(el, type, fn, capture);
539
- } else if ( el && el[0] !== undefined ) {
540
- for ( var i = 0; i < el.length; i++ ) {
541
- events.unbind(el[i], type, fn, capture);
542
- }
515
+ el = toArray(el);
516
+ for ( var i = 0; i < el.length; i++ ) {
517
+ events.unbind(el[i], type, fn, capture);
543
518
  }
544
519
  };
520
+
545
521
  });
546
522
  require.register("javve-get-by-class/index.js", function(exports, require, module){
547
523
  /**
@@ -714,10 +690,12 @@ module.exports = function(val){
714
690
  case '[object RegExp]': return 'regexp';
715
691
  case '[object Arguments]': return 'arguments';
716
692
  case '[object Array]': return 'array';
693
+ case '[object Error]': return 'error';
717
694
  }
718
695
 
719
696
  if (val === null) return 'null';
720
697
  if (val === undefined) return 'undefined';
698
+ if (val !== val) return 'nan';
721
699
  if (val && val.nodeType === 1) return 'element';
722
700
 
723
701
  return typeof val.valueOf();
@@ -733,7 +711,6 @@ By Jonny Strömberg (www.jonnystromberg.com, www.listjs.com)
733
711
  "use strict";
734
712
 
735
713
  var document = window.document,
736
- events = require('events'),
737
714
  getByClass = require('get-by-class'),
738
715
  extend = require('extend'),
739
716
  indexOf = require('indexof');
@@ -746,38 +723,46 @@ var List = function(id, options, values) {
746
723
  addAsync = require('./src/add-async')(self),
747
724
  parse = require('./src/parse')(self);
748
725
 
749
- this.listClass = "list";
750
- this.searchClass = "search";
751
- this.sortClass = "sort";
752
- this.page = 200;
753
- this.i = 1;
754
- this.items = [];
755
- this.visibleItems = [];
756
- this.matchingItems = [];
757
- this.searched = false;
758
- this.filtered = false;
759
- this.handlers = { 'updated': [] };
760
- this.plugins = {};
761
-
762
- extend(this, options);
763
-
764
- this.listContainer = (typeof(id) === 'string') ? document.getElementById(id) : id;
765
- if (!this.listContainer) { return; }
766
- this.list = getByClass(this.listContainer, this.listClass, true);
767
-
768
- this.templater = require('./src/templater')(self);
769
- this.sort = require('./src/sort')(self);
770
- this.search = require('./src/search')(self);
771
- this.filter = require('./src/filter')(self);
772
-
773
726
  init = {
774
- start: function(values) {
727
+ start: function() {
728
+ self.listClass = "list";
729
+ self.searchClass = "search";
730
+ self.sortClass = "sort";
731
+ self.page = 200;
732
+ self.i = 1;
733
+ self.items = [];
734
+ self.visibleItems = [];
735
+ self.matchingItems = [];
736
+ self.searched = false;
737
+ self.filtered = false;
738
+ self.handlers = { 'updated': [] };
739
+ self.plugins = {};
740
+ self.helpers = {
741
+ getByClass: getByClass,
742
+ extend: extend,
743
+ indexOf: indexOf
744
+ };
745
+
746
+ extend(self, options);
747
+
748
+ self.listContainer = (typeof(id) === 'string') ? document.getElementById(id) : id;
749
+ if (!self.listContainer) { return; }
750
+ self.list = getByClass(self.listContainer, self.listClass, true);
751
+
752
+ self.templater = require('./src/templater')(self);
753
+ self.search = require('./src/search')(self);
754
+ self.filter = require('./src/filter')(self);
755
+ self.sort = require('./src/sort')(self);
756
+
757
+ this.items();
758
+ self.update();
759
+ this.plugins();
760
+ },
761
+ items: function() {
775
762
  parse(self.list);
776
763
  if (values !== undefined) {
777
764
  self.add(values);
778
765
  }
779
- self.update();
780
- this.plugins();
781
766
  },
782
767
  plugins: function() {
783
768
  for (var i = 0; i < self.plugins.length; i++) {
@@ -938,7 +923,7 @@ var List = function(id, options, values) {
938
923
  return self;
939
924
  };
940
925
 
941
- init.start(values);
926
+ init.start();
942
927
  };
943
928
 
944
929
  module.exports = List;
@@ -1052,6 +1037,7 @@ module.exports = function(list) {
1052
1037
  searchMethod(target.value);
1053
1038
  });
1054
1039
 
1040
+ list.helpers.toString = toString;
1055
1041
  return searchMethod;
1056
1042
  };
1057
1043
 
@@ -1061,52 +1047,82 @@ var naturalSort = require('natural-sort'),
1061
1047
  classes = require('classes'),
1062
1048
  events = require('events'),
1063
1049
  getByClass = require('get-by-class'),
1064
- getAttribute = require('get-attribute'),
1065
- sortButtons;
1066
-
1067
- var clearPreviousSorting = function() {
1068
- for (var i = 0, il = sortButtons.length; i < il; i++) {
1069
- classes(sortButtons[i]).remove('asc');
1070
- classes(sortButtons[i]).remove('desc');
1071
- }
1072
- };
1050
+ getAttribute = require('get-attribute');
1073
1051
 
1074
1052
  module.exports = function(list) {
1075
- var sort = function() {
1076
- var options = {},
1077
- valueName;
1078
-
1079
- if (arguments[0].currentTarget || arguments[0].srcElement) {
1080
- var e = arguments[0],
1081
- target = e.currentTarget || e.srcElement,
1082
- newSortingOrder;
1083
-
1084
- valueName = getAttribute(target, 'data-sort');
1085
-
1086
- if (classes(target).has('desc')) {
1087
- options.desc = false;
1088
- newSortingOrder = 'asc';
1089
- } else if (classes(target).has('asc')) {
1090
- options.desc = true;
1091
- newSortingOrder = 'desc';
1053
+ list.sortFunction = list.sortFunction || function(itemA, itemB, options) {
1054
+ options.desc = options.order == "desc" ? true : false; // Natural sort uses this format
1055
+ return naturalSort(itemA.values()[options.valueName], itemB.values()[options.valueName], options);
1056
+ };
1057
+
1058
+ var buttons = {
1059
+ els: undefined,
1060
+ clear: function() {
1061
+ for (var i = 0, il = buttons.els.length; i < il; i++) {
1062
+ classes(buttons.els[i]).remove('asc');
1063
+ classes(buttons.els[i]).remove('desc');
1064
+ }
1065
+ },
1066
+ getOrder: function(btn) {
1067
+ var predefinedOrder = getAttribute(btn, 'data-order');
1068
+ if (predefinedOrder == "asc" || predefinedOrder == "desc") {
1069
+ return predefinedOrder;
1070
+ } else if (classes(btn).has('desc')) {
1071
+ return "asc";
1072
+ } else if (classes(btn).has('asc')) {
1073
+ return "desc";
1092
1074
  } else {
1093
- options.desc = false;
1094
- newSortingOrder = 'asc';
1075
+ return "asc";
1076
+ }
1077
+ },
1078
+ getInSensitive: function(btn, options) {
1079
+ var insensitive = getAttribute(btn, 'data-insensitive');
1080
+ if (insensitive === "true") {
1081
+ options.insensitive = true;
1082
+ } else {
1083
+ options.insensitive = false;
1084
+ }
1085
+ },
1086
+ setOrder: function(options) {
1087
+ for (var i = 0, il = buttons.els.length; i < il; i++) {
1088
+ var btn = buttons.els[i];
1089
+ if (getAttribute(btn, 'data-sort') !== options.valueName) {
1090
+ continue;
1091
+ }
1092
+ var predefinedOrder = getAttribute(btn, 'data-order');
1093
+ if (predefinedOrder == "asc" || predefinedOrder == "desc") {
1094
+ if (predefinedOrder == options.order) {
1095
+ classes(btn).add(options.order);
1096
+ }
1097
+ } else {
1098
+ classes(btn).add(options.order);
1099
+ }
1095
1100
  }
1096
- clearPreviousSorting();
1097
- classes(target).add(newSortingOrder);
1101
+ }
1102
+ };
1103
+ var sort = function() {
1104
+ list.trigger('sortStart');
1105
+ options = {};
1106
+
1107
+ var target = arguments[0].currentTarget || arguments[0].srcElement || undefined;
1108
+
1109
+ if (target) {
1110
+ options.valueName = getAttribute(target, 'data-sort');
1111
+ buttons.getInSensitive(target, options);
1112
+ options.order = buttons.getOrder(target);
1098
1113
  } else {
1099
- valueName = arguments[0];
1100
1114
  options = arguments[1] || options;
1115
+ options.valueName = arguments[0];
1116
+ options.order = options.order || "asc";
1117
+ options.insensitive = (typeof options.insensitive == "undefined") ? true : options.insensitive;
1101
1118
  }
1119
+ buttons.clear();
1120
+ buttons.setOrder(options);
1102
1121
 
1103
- options.insensitive = (typeof options.insensitive == "undefined") ? true : options.insensitive;
1104
- options.sortFunction = options.sortFunction || function(a, b) {
1105
- return naturalSort(a.values()[valueName], b.values()[valueName], options);
1106
- };
1107
-
1108
- list.trigger('sortStart');
1109
- list.items.sort(options.sortFunction);
1122
+ options.sortFunction = options.sortFunction || list.sortFunction;
1123
+ list.items.sort(function(a, b) {
1124
+ return options.sortFunction(a, b, options);
1125
+ });
1110
1126
  list.update();
1111
1127
  list.trigger('sortComplete');
1112
1128
  };
@@ -1115,8 +1131,16 @@ module.exports = function(list) {
1115
1131
  list.handlers.sortStart = list.handlers.sortStart || [];
1116
1132
  list.handlers.sortComplete = list.handlers.sortComplete || [];
1117
1133
 
1118
- sortButtons = getByClass(list.listContainer, list.sortClass);
1119
- events.bind(sortButtons, 'click', sort);
1134
+ buttons.els = getByClass(list.listContainer, list.sortClass);
1135
+ events.bind(buttons.els, 'click', sort);
1136
+ list.on('searchStart', buttons.clear);
1137
+ list.on('filterStart', buttons.clear);
1138
+
1139
+ // Helpers
1140
+ list.helpers.classes = classes;
1141
+ list.helpers.naturalSort = naturalSort;
1142
+ list.helpers.events = events;
1143
+ list.helpers.getAttribute = getAttribute;
1120
1144
 
1121
1145
  return sort;
1122
1146
  };
@@ -1409,8 +1433,7 @@ require.alias("javve-events/index.js", "list.js/deps/events/index.js");
1409
1433
  require.alias("javve-events/index.js", "events/index.js");
1410
1434
  require.alias("component-event/index.js", "javve-events/deps/event/index.js");
1411
1435
 
1412
- require.alias("javve-is-collection/index.js", "javve-events/deps/is-collection/index.js");
1413
- require.alias("component-type/index.js", "javve-is-collection/deps/type/index.js");
1436
+ require.alias("javve-to-array/index.js", "javve-events/deps/to-array/index.js");
1414
1437
 
1415
1438
  require.alias("javve-get-by-class/index.js", "list.js/deps/get-by-class/index.js");
1416
1439
  require.alias("javve-get-by-class/index.js", "get-by-class/index.js");
@@ -1,5 +1,5 @@
1
1
  module Listjs
2
2
  module Rails
3
- VERSION = '1.0.2'
3
+ VERSION = '1.1.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: listjs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artur Rodrigues
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-21 00:00:00.000000000 Z
11
+ date: 2014-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  version: '0'
105
105
  requirements: []
106
106
  rubyforge_project:
107
- rubygems_version: 2.2.1
107
+ rubygems_version: 2.2.2
108
108
  signing_key:
109
109
  specification_version: 4
110
110
  summary: Gem installation of javascript framework for list and table manipulation,