selectr-rails 2.4.1 → 2.4.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad91379746104f2d422d58a35d1c25602defab25
4
- data.tar.gz: 83a5a3a11c62803254270fa56b94d667ec77a47e
3
+ metadata.gz: 2258cacca1a9ebcf44d2ada175c9f350bf941822
4
+ data.tar.gz: 87ac129a92230aeff537ebfafc75bc6078ac36bc
5
5
  SHA512:
6
- metadata.gz: 4b6780c44a204c486df0de925884371e361c1eca9f86faa5fac5fce82a5d30c6d2cdff5cbef85cd2826130303f1c71605c46674aa9cd6fe73d3e1f2ba0c84e79
7
- data.tar.gz: f33899acf509a75a3f0fcbe205c7fd9934deadd601d8c84c8addae239d869bad7d0e9f24315806091d709402834ca63474d7b7cafe73b0d2708fa48ff20f2d33
6
+ metadata.gz: 192f5529e3f8a70e9b0cb1b47f9f8f1d08d517774e389ca1a5d6cdfc9ca1b762a09efd9e6a18fbf20492637b534cc1a5c1b42f55ba026445547b921d5823d6f5
7
+ data.tar.gz: d3783b9f7da8276321a90d4b4b50768d5b04df40c0f430249e661b7cebd516030831e5d0718f016551d9f59ca1f88e6a1e1dc9bdeffa51dece4cd707a33ffac2
@@ -1,3 +1,3 @@
1
1
  module Selectr
2
- VERSION = '2.4.1'
2
+ VERSION = '2.4.8'
3
3
  end
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Selectr 2.4.0
2
+ * Selectr 2.4.8
3
3
  * http://mobius.ovh/docs/selectr
4
4
  *
5
5
  * Released under the MIT license
@@ -17,90 +17,6 @@
17
17
  }(this, function(plugin) {
18
18
  'use strict';
19
19
 
20
- /**
21
- * Default configuration options
22
- * @type {Object}
23
- */
24
- var defaultConfig = {
25
- /**
26
- * Emulates browser behaviour by selecting the first option by default
27
- * @type {Boolean}
28
- */
29
- defaultSelected: true,
30
-
31
- /**
32
- * Sets the width of the container
33
- * @type {String}
34
- */
35
- width: "auto",
36
-
37
- /**
38
- * Enables/ disables the container
39
- * @type {Boolean}
40
- */
41
- disabled: false,
42
-
43
- /**
44
- * Enables / disables the search function
45
- * @type {Boolean}
46
- */
47
- searchable: true,
48
-
49
- /**
50
- * Enable disable the clear button
51
- * @type {Boolean}
52
- */
53
- clearable: false,
54
-
55
- /**
56
- * Sort the tags / multiselect options
57
- * @type {Boolean}
58
- */
59
- sortSelected: false,
60
-
61
- /**
62
- * Allow deselecting of select-one options
63
- * @type {Boolean}
64
- */
65
- allowDeselect: false,
66
-
67
- /**
68
- * Close the dropdown when scrolling (@AlexanderReiswich, #11)
69
- * @type {Boolean}
70
- */
71
- closeOnScroll: false,
72
-
73
- /**
74
- * Allow the use of the native dropdown (@jonnyscholes, #14)
75
- * @type {Boolean}
76
- */
77
- nativeDropdown: false,
78
-
79
- /**
80
- * Allow the use of native typing behavior for toggling, searching, selecting
81
- * @type {boolean}
82
- */
83
- nativeKeyboard: false,
84
-
85
- /**
86
- * Set the main placeholder
87
- * @type {String}
88
- */
89
- placeholder: "Select an option...",
90
-
91
- /**
92
- * Allow the tagging feature
93
- * @type {Boolean}
94
- */
95
- taggable: false,
96
-
97
- /**
98
- * Set the tag input placeholder (@labikmartin, #21, #22)
99
- * @type {String}
100
- */
101
- tagPlaceholder: "Enter a tag..."
102
- };
103
-
104
20
  /**
105
21
  * Event Emitter
106
22
  */
@@ -172,16 +88,18 @@
172
88
  */
173
89
  var util = {
174
90
  extend: function(src, props) {
175
- props = props || {};
176
- var p;
177
- for (p in src) {
178
- if (src.hasOwnProperty(p)) {
179
- if (!props.hasOwnProperty(p)) {
180
- props[p] = src[p];
91
+ for (var prop in props) {
92
+ if (props.hasOwnProperty(prop)) {
93
+ var val = props[prop];
94
+ if (val && Object.prototype.toString.call(val) === "[object Object]") {
95
+ src[prop] = src[prop] || {};
96
+ util.extend(src[prop], val);
97
+ } else {
98
+ src[prop] = val;
99
+ }
100
+ }
181
101
  }
182
- }
183
- }
184
- return props;
102
+ return src;
185
103
  },
186
104
  each: function(a, b, c) {
187
105
  if ("[object Object]" === Object.prototype.toString.call(a)) {
@@ -441,7 +359,7 @@
441
359
  this.selected = util.createElement("div", {
442
360
  class: "selectr-selected",
443
361
  disabled: this.disabled,
444
- tabIndex: 1, // enable tabIndex (#9)
362
+ tabIndex: 0,
445
363
  "aria-expanded": false
446
364
  });
447
365
 
@@ -532,7 +450,8 @@
532
450
  autocapitalize: "off",
533
451
  spellcheck: "false",
534
452
  role: "textbox",
535
- type: "search"
453
+ type: "search",
454
+ placeholder: this.config.messages.searchPlaceholder
536
455
  });
537
456
  this.inputClear = util.createElement("button", {
538
457
  class: "selectr-input-clear",
@@ -627,6 +546,8 @@
627
546
 
628
547
  j++;
629
548
  }, this);
549
+
550
+ this.el.appendChild(optgroup);
630
551
  } else {
631
552
  option = new Option(opt.text, opt.value, false, opt.hasOwnProperty("selected") && opt.selected === true);
632
553
 
@@ -707,7 +628,7 @@
707
628
 
708
629
  if (e.which === 13) {
709
630
 
710
- if (this.config.taggable && this.input.value.length > 0) {
631
+ if ( this.noResults || (this.config.taggable && this.input.value.length > 0) ) {
711
632
  return false;
712
633
  }
713
634
 
@@ -969,8 +890,6 @@
969
890
  // Main Lib
970
891
  var Selectr = function(el, config) {
971
892
 
972
- config = config || {};
973
-
974
893
  if (!el) {
975
894
  throw new Error("You must supply either a HTMLSelectElement or a CSS3 selector string.");
976
895
  }
@@ -1002,6 +921,101 @@
1002
921
 
1003
922
  if (this.rendered) return;
1004
923
 
924
+ /**
925
+ * Default configuration options
926
+ * @type {Object}
927
+ */
928
+ var defaultConfig = {
929
+ /**
930
+ * Emulates browser behaviour by selecting the first option by default
931
+ * @type {Boolean}
932
+ */
933
+ defaultSelected: true,
934
+
935
+ /**
936
+ * Sets the width of the container
937
+ * @type {String}
938
+ */
939
+ width: "auto",
940
+
941
+ /**
942
+ * Enables/ disables the container
943
+ * @type {Boolean}
944
+ */
945
+ disabled: false,
946
+
947
+ /**
948
+ * Enables / disables the search function
949
+ * @type {Boolean}
950
+ */
951
+ searchable: true,
952
+
953
+ /**
954
+ * Enable disable the clear button
955
+ * @type {Boolean}
956
+ */
957
+ clearable: false,
958
+
959
+ /**
960
+ * Sort the tags / multiselect options
961
+ * @type {Boolean}
962
+ */
963
+ sortSelected: false,
964
+
965
+ /**
966
+ * Allow deselecting of select-one options
967
+ * @type {Boolean}
968
+ */
969
+ allowDeselect: false,
970
+
971
+ /**
972
+ * Close the dropdown when scrolling (@AlexanderReiswich, #11)
973
+ * @type {Boolean}
974
+ */
975
+ closeOnScroll: false,
976
+
977
+ /**
978
+ * Allow the use of the native dropdown (@jonnyscholes, #14)
979
+ * @type {Boolean}
980
+ */
981
+ nativeDropdown: false,
982
+
983
+ /**
984
+ * Allow the use of native typing behavior for toggling, searching, selecting
985
+ * @type {boolean}
986
+ */
987
+ nativeKeyboard: false,
988
+
989
+ /**
990
+ * Set the main placeholder
991
+ * @type {String}
992
+ */
993
+ placeholder: "Select an option...",
994
+
995
+ /**
996
+ * Allow the tagging feature
997
+ * @type {Boolean}
998
+ */
999
+ taggable: false,
1000
+
1001
+ /**
1002
+ * Set the tag input placeholder (@labikmartin, #21, #22)
1003
+ * @type {String}
1004
+ */
1005
+ tagPlaceholder: "Enter a tag...",
1006
+
1007
+ messages: {
1008
+ noResults: "No results.",
1009
+ noOptions: "No options available.",
1010
+ maxSelections: "A maximum of {max} items can be selected.",
1011
+ tagDuplicate: "That tag is already in use.",
1012
+ searchPlaceholder: "Search options..."
1013
+ }
1014
+ };
1015
+
1016
+ // add instance reference (#87)
1017
+ this.el.selectr = this;
1018
+
1005
1019
  // Merge defaults with user set config
1006
1020
  this.config = util.extend(defaultConfig, config);
1007
1021
 
@@ -1040,6 +1054,8 @@
1040
1054
  this.customOption = this.config.hasOwnProperty("renderOption") && typeof this.config.renderOption === "function";
1041
1055
  this.customSelected = this.config.hasOwnProperty("renderSelection") && typeof this.config.renderSelection === "function";
1042
1056
 
1057
+ this.supportsEventPassiveOption = this.detectEventPassiveOption();
1058
+
1043
1059
  // Enable event emitter
1044
1060
  Events.mixin(this);
1045
1061
 
@@ -1077,6 +1093,24 @@
1077
1093
  return values;
1078
1094
  };
1079
1095
 
1096
+ /**
1097
+ * Feature detection: addEventListener passive option
1098
+ * https://dom.spec.whatwg.org/#dom-addeventlisteneroptions-passive
1099
+ * https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
1100
+ */
1101
+ Selectr.prototype.detectEventPassiveOption = function () {
1102
+ var supportsPassiveOption = false;
1103
+ try {
1104
+ var opts = Object.defineProperty({}, 'passive', {
1105
+ get: function() {
1106
+ supportsPassiveOption = true;
1107
+ }
1108
+ });
1109
+ window.addEventListener('test', null, opts);
1110
+ } catch (e) {}
1111
+ return supportsPassiveOption;
1112
+ }
1113
+
1080
1114
  /**
1081
1115
  * Attach the required event listeners
1082
1116
  */
@@ -1096,7 +1130,7 @@
1096
1130
  if (e.changedTouches[0].target === that.el) {
1097
1131
  that.toggle();
1098
1132
  }
1099
- });
1133
+ }, this.supportsEventPassiveOption ? { passive: true } : false);
1100
1134
 
1101
1135
  this.container.addEventListener("click", function(e) {
1102
1136
  if (e.target === that.el) {
@@ -1141,20 +1175,30 @@
1141
1175
 
1142
1176
  }
1143
1177
 
1144
- // Open the dropdown with Enter key if focused
1145
- if (this.config.nativeDropdown) {
1146
- this.container.addEventListener("keydown", function(e) {
1147
- if (e.key === "Enter" && that.selected === document.activeElement) {
1148
- // Show the native
1178
+ // Keyboard Support
1179
+ this.container.addEventListener("keydown", function(e) {
1180
+ if (e.key === "Escape") {
1181
+ that.close();
1182
+ }
1183
+
1184
+ if (e.key === "Enter" && that.selected === document.activeElement) {
1185
+ if (typeof that.el.form.submit !== 'undefined') that.el.form.submit();
1186
+ }
1187
+
1188
+ if ((e.key === " " || e.key === "ArrowUp" || e.key === "ArrowDown") &&
1189
+ that.selected === document.activeElement) {
1190
+ setTimeout(function() {
1149
1191
  that.toggle();
1192
+ }, 200);
1150
1193
 
1194
+ if (that.config.nativeDropdown) {
1151
1195
  // Focus on the native multiselect
1152
1196
  setTimeout(function() {
1153
1197
  that.el.focus();
1154
1198
  }, 200);
1155
1199
  }
1156
- });
1157
- }
1200
+ }
1201
+ });
1158
1202
 
1159
1203
  // Non-native dropdown
1160
1204
  this.selected.addEventListener("click", function(e) {
@@ -1163,7 +1207,6 @@
1163
1207
  that.toggle();
1164
1208
  }
1165
1209
 
1166
- e.stopPropagation();
1167
1210
  e.preventDefault();
1168
1211
  });
1169
1212
 
@@ -1353,7 +1396,7 @@
1353
1396
 
1354
1397
  if (!option) {
1355
1398
  this.value = '';
1356
- that.setMessage('That tag is already in use.');
1399
+ that.setMessage(that.config.messages.tagDuplicate);
1357
1400
  } else {
1358
1401
  that.close();
1359
1402
  clearSearch.call(that);
@@ -1502,6 +1545,9 @@
1502
1545
  this.container.parentNode.replaceChild(this.el, this.container);
1503
1546
 
1504
1547
  this.rendered = false;
1548
+
1549
+ // remove reference
1550
+ delete this.el.selectr;
1505
1551
  };
1506
1552
 
1507
1553
  /**
@@ -1545,7 +1591,7 @@
1545
1591
  }
1546
1592
 
1547
1593
  if (this.config.maxSelections && this.tags.length === this.config.maxSelections) {
1548
- this.setMessage("A maximum of " + this.config.maxSelections + " items can be selected.", true);
1594
+ this.setMessage(this.config.messages.maxSelections.replace("{max}", this.config.maxSelections), true);
1549
1595
  return false;
1550
1596
  }
1551
1597
 
@@ -1588,6 +1634,15 @@
1588
1634
  this.emit("selectr.change", option);
1589
1635
 
1590
1636
  this.emit("selectr.select", option);
1637
+
1638
+ // fire native change event
1639
+ if ("createEvent" in document) {
1640
+ var evt = document.createEvent("HTMLEvents");
1641
+ evt.initEvent("change", true, true);
1642
+ this.el.dispatchEvent(evt);
1643
+ } else {
1644
+ this.el.fireEvent("onchange");
1645
+ }
1591
1646
  };
1592
1647
 
1593
1648
  /**
@@ -1637,6 +1692,15 @@
1637
1692
  this.emit("selectr.change", null);
1638
1693
 
1639
1694
  this.emit("selectr.deselect", option);
1695
+
1696
+ // fire native change event
1697
+ if ("createEvent" in document) {
1698
+ var evt = document.createEvent("HTMLEvents");
1699
+ evt.initEvent("change", true, true);
1700
+ this.el.dispatchEvent(evt);
1701
+ } else {
1702
+ this.el.fireEvent("onchange");
1703
+ }
1640
1704
  };
1641
1705
 
1642
1706
  /**
@@ -1656,7 +1720,7 @@
1656
1720
  }
1657
1721
 
1658
1722
  util.each(this.options, function(i, option) {
1659
- if (isArray && util.includes(value.toString(), option.value) || option.value === value) {
1723
+ if (isArray && (value.indexOf(option.value) > -1) || option.value === value) {
1660
1724
  this.change(option.idx);
1661
1725
  }
1662
1726
  }, this);
@@ -1712,7 +1776,6 @@
1712
1776
  */
1713
1777
  Selectr.prototype.add = function(data, checkDuplicate) {
1714
1778
  if (data) {
1715
-
1716
1779
  this.data = this.data || [];
1717
1780
  this.items = this.items || [];
1718
1781
  this.options = this.options || [];
@@ -1758,14 +1821,14 @@
1758
1821
  if (data.selected) {
1759
1822
  this.select(option.idx);
1760
1823
  }
1824
+
1825
+ // We may have had an empty select so update
1826
+ // the placeholder to reflect the changes.
1827
+ this.setPlaceholder();
1761
1828
 
1762
1829
  return option;
1763
1830
  }
1764
1831
 
1765
- // We may have had an empty select so update
1766
- // the placeholder to reflect the changes.
1767
- this.setPlaceholder();
1768
-
1769
1832
  // Recount the pages
1770
1833
  if (this.config.pagination) {
1771
1834
  this.paginate();
@@ -1786,7 +1849,7 @@
1786
1849
  util.each(o, function(i, opt) {
1787
1850
  if (util.isInt(opt)) {
1788
1851
  options.push(this.getOptionByIndex(opt));
1789
- } else if (typeof o === "string") {
1852
+ } else if (typeof opt === "string") {
1790
1853
  options.push(this.getOptionByValue(opt));
1791
1854
  }
1792
1855
  }, this);
@@ -1924,12 +1987,14 @@
1924
1987
  // Append results
1925
1988
  if ( !f.childElementCount ) {
1926
1989
  if ( !this.config.taggable ) {
1927
- this.setMessage( "no results." );
1990
+ this.noResults = true;
1991
+ this.setMessage( this.config.messages.noResults );
1928
1992
  }
1929
1993
  } else {
1930
1994
  // Highlight top result (@binary-koan #26)
1931
1995
  var prevEl = this.items[this.navIndex];
1932
1996
  var firstEl = f.querySelector(".selectr-option:not(.excluded)");
1997
+ this.noResults = false;
1933
1998
 
1934
1999
  util.removeClass( prevEl, "active" );
1935
2000
  this.navIndex = firstEl.idx;
@@ -2057,6 +2122,7 @@
2057
2122
 
2058
2123
  util.truncate(this.tree);
2059
2124
  clearSearch.call(this);
2125
+ this.selected.focus();
2060
2126
  };
2061
2127
 
2062
2128
 
@@ -2188,7 +2254,7 @@
2188
2254
  placeholder = placeholder || this.config.placeholder || this.el.getAttribute("placeholder");
2189
2255
 
2190
2256
  if (!this.options.length) {
2191
- placeholder = "No options available";
2257
+ placeholder = this.config.messages.noOptions;
2192
2258
  }
2193
2259
 
2194
2260
  this.placeEl.innerHTML = placeholder;
@@ -2282,3 +2348,4 @@
2282
2348
 
2283
2349
  return Selectr;
2284
2350
  }));
2351
+
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Selectr 2.4.0
2
+ * Selectr 2.4.8
3
3
  * http://mobius.ovh/docs/selectr
4
4
  *
5
5
  * Released under the MIT license
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selectr-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1
4
+ version: 2.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Chavez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-20 00:00:00.000000000 Z
11
+ date: 2019-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler