effective_bootstrap 0.5.18 → 0.5.19

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
  SHA256:
3
- metadata.gz: 8b2dc1d10a6a9d5ee3dfad575e5197b04e6eb64f866853ee50b2298a74cc18e7
4
- data.tar.gz: b809f04a6e3fbba1e8dacb4e1f16ef97c76d9751871c6994fdc8051523dfd938
3
+ metadata.gz: 4f7f93ac632e2060593e064b4e0b640a2c064787bb6a2f0569d38de2057a5a75
4
+ data.tar.gz: c4201bcf5c82f3ff3f7dcf7473c736a9cac8b855bd227400306eac1a9d77de85
5
5
  SHA512:
6
- metadata.gz: 0cef677c259ef1691d61139869947fd13c4dd067e411608caf2baa6e87d2e0e909b6c3b5137c6f8cf042e0074a12ff7963a6c0104e17b4191d5e75bd9853db91
7
- data.tar.gz: 77da14934b26860ec7fa29294487a9e628d471a61237acfa888decf7ad459903b36608e4b38b06dcfe28e4ac67cb5b47731f8a088729553777f28c9266989106
6
+ metadata.gz: d5d12260fe772a88223c8f13a31a69611c209a5961ff93c273363890df964c5498ecc41ae989e1b3eb418a02444d3c87c380009ca8892701fe510caafbd3941c
7
+ data.tar.gz: 15570606ec1fda4c61a3091f5caffe511986ec05a278de4ee500d2debe7152bce3a5bd82118a5994560dfc5da357d03198aa491f2b56234e62b4530a7233aad1
data/README.md CHANGED
@@ -510,7 +510,56 @@ $(document).on 'change', '.something', (event) ->
510
510
 
511
511
  ### AJAX Support
512
512
 
513
- There is currently no support for using AJAX to load remote data. This feature is supported by the underlying select2 library and will be implemented here at a future point.
513
+ Provide the `ajax_url: ` method to use AJAX remote data source.
514
+
515
+ In your form:
516
+
517
+ ```ruby
518
+ = f.input :user_id, User.all, ajax_url: users_select2_ajax_index_path
519
+ ```
520
+
521
+ In your `routes.rb`:
522
+
523
+ ```ruby
524
+ resources :select2_ajax, only: [] do
525
+ get :users, on: :collection
526
+ end
527
+ ```
528
+
529
+ In your controller:
530
+
531
+ ```ruby
532
+ class Select2AjaxController < ApplicationController
533
+ def users
534
+ # Collection
535
+ collection = User.all
536
+
537
+ # Search
538
+ if (term = params[:term]).present?
539
+ collection = collection.where('name ILIKE ?', "%#{term}%").or(collection.where('id::TEXT LIKE ?', "%#{term}%"))
540
+ end
541
+
542
+ # Paginate
543
+ per_page = 20
544
+ page = (params[:page] || 1).to_i
545
+ last = (collection.reselect(:id).count.to_f / per_page).ceil
546
+ more = page < last
547
+
548
+ offset = [(page - 1), 0].max * per_page
549
+ collection = collection.limit(per_page).offset(offset)
550
+
551
+ # Results
552
+ results = collection.map { |user| { id: user.to_param, text: user.to_s } }
553
+
554
+ respond_to do |format|
555
+ format.js do
556
+ render json: { results: results, pagination: { more: more } }
557
+ end
558
+ end
559
+ end
560
+
561
+ end
562
+ ```
514
563
 
515
564
  ## Custom select_or_text_field
516
565
 
@@ -4,7 +4,6 @@ this.EffectiveForm ||= new class
4
4
  remote_form_commit: '' # String containing the last params[:commit]
5
5
  remote_form_payload: '' # String containing html from server side render of this form
6
6
  remote_form_flash: '' # Array of Arrays
7
- remote_form_refresh_datatables: '' # Array of Strings. effective_datatables inline_crud.js uses this
8
7
 
9
8
  validate: (form) ->
10
9
  valid = form.checkValidity()
@@ -50,12 +50,4 @@ $(document).on 'change', "select.effective_select.polymorphic", (event) ->
50
50
  $select.siblings("input[type='hidden'][name$='_type]']").val(value.split('_')[0] || '')
51
51
  $select.siblings("input[type='hidden'][name$='_id]']").val(value.split('_')[1] || '')
52
52
 
53
- # Keep the order of selected tags
54
- # Fixes https://github.com/select2/select2/issues/3106
55
- $(document).on 'select2:select', 'select', (event) ->
56
- $el = $(event.params.data.element)
57
-
58
- if $el.closest('select').hasClass('tags-input')
59
- $(this).append($el.detach()).trigger('change')
60
- true
61
53
 
@@ -1,6 +1,17 @@
1
+ # Keep the order of selected tags
2
+ # Fixes https://github.com/select2/select2/issues/3106
3
+ $(document).on 'select2:select', 'select', (event) ->
4
+ $el = $(event.params.data.element)
5
+
6
+ if $el.closest('select').hasClass('tags-input')
7
+ $(this).append($el.detach()).trigger('change')
8
+
9
+ true
10
+
1
11
  # Disable dropdown opening when clicking the clear button
2
12
  # http://stackoverflow.com/questions/29618382/disable-dropdown-opening-on-select2-clear
3
13
  $(document).on 'select2:unselecting', (event) -> $(event.target).data('state', 'unselected')
14
+
4
15
  $(document).on 'select2:open', (event) ->
5
16
  $select = $(event.target)
6
17
 
@@ -10,9 +21,11 @@ $(document).on 'select2:open', (event) ->
10
21
 
11
22
  # For tabbing through
12
23
  # https://stackoverflow.com/questions/20989458/select2-open-dropdown-on-focus
13
- $(document).on 'select2:focus', (event) ->
14
- $select = $(event.target)
15
- $select.select2('open') unless $select.prop('multiple') || $select.hasClass('disable-open-on-focus')
24
+ $(document).on 'focus', '.select2-selection.select2-selection--single', (event) ->
25
+ $(event.currentTarget).closest('.select2-container').siblings('select:enabled').select2('open')
26
+
27
+ $(document).on 'select2:closing', (event) ->
28
+ $(event.target).data('select2').$selection.one('focus focusin', (event) -> event.stopPropagation())
16
29
 
17
30
  # effective_select custom reinitialization functionality
18
31
  # This is a custom event intended to be manually triggered when the underlying options change
@@ -23,7 +36,6 @@ $(document).on 'select2:focus', (event) ->
23
36
  # $(document).on 'change', "select[name$='[something_id]']", (event) ->
24
37
  # ...add/remove/disable this select field's options...
25
38
  # $(event.target).select2().trigger('select2:reinitialize')
26
-
27
39
  $(document).on 'select2:reinitialize', (event) ->
28
40
  $select = $(event.target)
29
41
 
@@ -1,11 +1,11 @@
1
1
  /*!
2
- * Select2 4.0.5
2
+ * Select2 4.0.7
3
3
  * https://select2.github.io
4
4
  *
5
5
  * Released under the MIT license
6
6
  * https://github.com/select2/select2/blob/master/LICENSE.md
7
7
  */
8
- (function (factory) {
8
+ ;(function (factory) {
9
9
  if (typeof define === 'function' && define.amd) {
10
10
  // AMD. Register as an anonymous module.
11
11
  define(['jquery'], factory);
@@ -574,10 +574,10 @@ S2.define('select2/utils',[
574
574
  DecoratedClass.prototype = new ctr();
575
575
 
576
576
  for (var m = 0; m < superMethods.length; m++) {
577
- var superMethod = superMethods[m];
577
+ var superMethod = superMethods[m];
578
578
 
579
- DecoratedClass.prototype[superMethod] =
580
- SuperClass.prototype[superMethod];
579
+ DecoratedClass.prototype[superMethod] =
580
+ SuperClass.prototype[superMethod];
581
581
  }
582
582
 
583
583
  var calledMethod = function (methodName) {
@@ -772,6 +772,68 @@ S2.define('select2/utils',[
772
772
  $element.append($nodes);
773
773
  };
774
774
 
775
+ // Cache objects in Utils.__cache instead of $.data (see #4346)
776
+ Utils.__cache = {};
777
+
778
+ var id = 0;
779
+ Utils.GetUniqueElementId = function (element) {
780
+ // Get a unique element Id. If element has no id,
781
+ // creates a new unique number, stores it in the id
782
+ // attribute and returns the new id.
783
+ // If an id already exists, it simply returns it.
784
+
785
+ var select2Id = element.getAttribute('data-select2-id');
786
+ if (select2Id == null) {
787
+ // If element has id, use it.
788
+ if (element.id) {
789
+ select2Id = element.id;
790
+ element.setAttribute('data-select2-id', select2Id);
791
+ } else {
792
+ element.setAttribute('data-select2-id', ++id);
793
+ select2Id = id.toString();
794
+ }
795
+ }
796
+ return select2Id;
797
+ };
798
+
799
+ Utils.StoreData = function (element, name, value) {
800
+ // Stores an item in the cache for a specified element.
801
+ // name is the cache key.
802
+ var id = Utils.GetUniqueElementId(element);
803
+ if (!Utils.__cache[id]) {
804
+ Utils.__cache[id] = {};
805
+ }
806
+
807
+ Utils.__cache[id][name] = value;
808
+ };
809
+
810
+ Utils.GetData = function (element, name) {
811
+ // Retrieves a value from the cache by its key (name)
812
+ // name is optional. If no name specified, return
813
+ // all cache items for the specified element.
814
+ // and for a specified element.
815
+ var id = Utils.GetUniqueElementId(element);
816
+ if (name) {
817
+ if (Utils.__cache[id]) {
818
+ if (Utils.__cache[id][name] != null) {
819
+ return Utils.__cache[id][name];
820
+ }
821
+ return $(element).data(name); // Fallback to HTML5 data attribs.
822
+ }
823
+ return $(element).data(name); // Fallback to HTML5 data attribs.
824
+ } else {
825
+ return Utils.__cache[id];
826
+ }
827
+ };
828
+
829
+ Utils.RemoveData = function (element) {
830
+ // Removes all cached items for a specified element.
831
+ var id = Utils.GetUniqueElementId(element);
832
+ if (Utils.__cache[id] != null) {
833
+ delete Utils.__cache[id];
834
+ }
835
+ };
836
+
775
837
  return Utils;
776
838
  });
777
839
 
@@ -907,7 +969,7 @@ S2.define('select2/results',[
907
969
  $options.each(function () {
908
970
  var $option = $(this);
909
971
 
910
- var item = $.data(this, 'data');
972
+ var item = Utils.GetData(this, 'data');
911
973
 
912
974
  // id needs to be converted to a string when comparing
913
975
  var id = '' + item.id;
@@ -1012,7 +1074,7 @@ S2.define('select2/results',[
1012
1074
  this.template(data, option);
1013
1075
  }
1014
1076
 
1015
- $.data(option, 'data', data);
1077
+ Utils.StoreData(option, 'data', data);
1016
1078
 
1017
1079
  return option;
1018
1080
  };
@@ -1053,7 +1115,10 @@ S2.define('select2/results',[
1053
1115
  }
1054
1116
 
1055
1117
  self.setClasses();
1056
- self.highlightFirstItem();
1118
+
1119
+ if (self.options.get('scrollAfterSelect')) {
1120
+ self.highlightFirstItem();
1121
+ }
1057
1122
  });
1058
1123
 
1059
1124
  container.on('unselect', function () {
@@ -1062,7 +1127,10 @@ S2.define('select2/results',[
1062
1127
  }
1063
1128
 
1064
1129
  self.setClasses();
1065
- self.highlightFirstItem();
1130
+
1131
+ if (self.options.get('scrollAfterSelect')) {
1132
+ self.highlightFirstItem();
1133
+ }
1066
1134
  });
1067
1135
 
1068
1136
  container.on('open', function () {
@@ -1098,7 +1166,7 @@ S2.define('select2/results',[
1098
1166
  return;
1099
1167
  }
1100
1168
 
1101
- var data = $highlighted.data('data');
1169
+ var data = Utils.GetData($highlighted[0], 'data');
1102
1170
 
1103
1171
  if ($highlighted.attr('aria-selected') == 'true') {
1104
1172
  self.trigger('close', {});
@@ -1116,8 +1184,9 @@ S2.define('select2/results',[
1116
1184
 
1117
1185
  var currentIndex = $options.index($highlighted);
1118
1186
 
1119
- // If we are already at te top, don't move further
1120
- if (currentIndex === 0) {
1187
+ // If we are already at the top, don't move further
1188
+ // If no options, currentIndex will be -1
1189
+ if (currentIndex <= 0) {
1121
1190
  return;
1122
1191
  }
1123
1192
 
@@ -1210,7 +1279,7 @@ S2.define('select2/results',[
1210
1279
  function (evt) {
1211
1280
  var $this = $(this);
1212
1281
 
1213
- var data = $this.data('data');
1282
+ var data = Utils.GetData(this, 'data');
1214
1283
 
1215
1284
  if ($this.attr('aria-selected') === 'true') {
1216
1285
  if (self.options.get('multiple')) {
@@ -1233,7 +1302,7 @@ S2.define('select2/results',[
1233
1302
 
1234
1303
  this.$results.on('mouseenter', '.select2-results__option[aria-selected]',
1235
1304
  function (evt) {
1236
- var data = $(this).data('data');
1305
+ var data = Utils.GetData(this, 'data');
1237
1306
 
1238
1307
  self.getHighlightedResults()
1239
1308
  .removeClass('select2-results__option--highlighted');
@@ -1348,8 +1417,8 @@ S2.define('select2/selection/base',[
1348
1417
 
1349
1418
  this._tabindex = 0;
1350
1419
 
1351
- if (this.$element.data('old-tabindex') != null) {
1352
- this._tabindex = this.$element.data('old-tabindex');
1420
+ if (Utils.GetData(this.$element[0], 'old-tabindex') != null) {
1421
+ this._tabindex = Utils.GetData(this.$element[0], 'old-tabindex');
1353
1422
  } else if (this.$element.attr('tabindex') != null) {
1354
1423
  this._tabindex = this.$element.attr('tabindex');
1355
1424
  }
@@ -1408,8 +1477,10 @@ S2.define('select2/selection/base',[
1408
1477
  self.$selection.removeAttr('aria-activedescendant');
1409
1478
  self.$selection.removeAttr('aria-owns');
1410
1479
 
1411
- self.$selection.focus();
1412
-
1480
+ window.setTimeout(function () {
1481
+ self.$selection.focus();
1482
+ }, 0);
1483
+
1413
1484
  self._detachCloseHandler(container);
1414
1485
  });
1415
1486
 
@@ -1457,7 +1528,7 @@ S2.define('select2/selection/base',[
1457
1528
  return;
1458
1529
  }
1459
1530
 
1460
- var $element = $this.data('element');
1531
+ var $element = Utils.GetData(this, 'element');
1461
1532
 
1462
1533
  $element.select2('close');
1463
1534
  });
@@ -1518,7 +1589,10 @@ S2.define('select2/selection/single',[
1518
1589
 
1519
1590
  var id = container.id + '-container';
1520
1591
 
1521
- this.$selection.find('.select2-selection__rendered').attr('id', id);
1592
+ this.$selection.find('.select2-selection__rendered')
1593
+ .attr('id', id)
1594
+ .attr('role', 'textbox')
1595
+ .attr('aria-readonly', 'true');
1522
1596
  this.$selection.attr('aria-labelledby', id);
1523
1597
 
1524
1598
  this.$selection.on('mousedown', function (evt) {
@@ -1545,14 +1619,12 @@ S2.define('select2/selection/single',[
1545
1619
  self.$selection.focus();
1546
1620
  }
1547
1621
  });
1548
-
1549
- container.on('selection:update', function (params) {
1550
- self.update(params.data);
1551
- });
1552
1622
  };
1553
1623
 
1554
1624
  SingleSelection.prototype.clear = function () {
1555
- this.$selection.find('.select2-selection__rendered').empty();
1625
+ var $rendered = this.$selection.find('.select2-selection__rendered');
1626
+ $rendered.empty();
1627
+ $rendered.removeAttr('title'); // clear tooltip on empty
1556
1628
  };
1557
1629
 
1558
1630
  SingleSelection.prototype.display = function (data, container) {
@@ -1578,7 +1650,7 @@ S2.define('select2/selection/single',[
1578
1650
  var formatted = this.display(selection, $rendered);
1579
1651
 
1580
1652
  $rendered.empty().append(formatted);
1581
- $rendered.prop('title', selection.title || selection.text);
1653
+ $rendered.attr('title', selection.title || selection.text);
1582
1654
  };
1583
1655
 
1584
1656
  return SingleSelection;
@@ -1630,7 +1702,7 @@ S2.define('select2/selection/multiple',[
1630
1702
  var $remove = $(this);
1631
1703
  var $selection = $remove.parent();
1632
1704
 
1633
- var data = $selection.data('data');
1705
+ var data = Utils.GetData($selection[0], 'data');
1634
1706
 
1635
1707
  self.trigger('unselect', {
1636
1708
  originalEvent: evt,
@@ -1641,7 +1713,9 @@ S2.define('select2/selection/multiple',[
1641
1713
  };
1642
1714
 
1643
1715
  MultipleSelection.prototype.clear = function () {
1644
- this.$selection.find('.select2-selection__rendered').empty();
1716
+ var $rendered = this.$selection.find('.select2-selection__rendered');
1717
+ $rendered.empty();
1718
+ $rendered.removeAttr('title');
1645
1719
  };
1646
1720
 
1647
1721
  MultipleSelection.prototype.display = function (data, container) {
@@ -1679,9 +1753,9 @@ S2.define('select2/selection/multiple',[
1679
1753
  var formatted = this.display(selection, $selection);
1680
1754
 
1681
1755
  $selection.append(formatted);
1682
- $selection.prop('title', selection.title || selection.text);
1756
+ $selection.attr('title', selection.title || selection.text);
1683
1757
 
1684
- $selection.data('data', selection);
1758
+ Utils.StoreData($selection[0], 'data', selection);
1685
1759
 
1686
1760
  $selections.push($selection);
1687
1761
  }
@@ -1746,8 +1820,9 @@ S2.define('select2/selection/placeholder',[
1746
1820
 
1747
1821
  S2.define('select2/selection/allowClear',[
1748
1822
  'jquery',
1749
- '../keys'
1750
- ], function ($, KEYS) {
1823
+ '../keys',
1824
+ '../utils'
1825
+ ], function ($, KEYS, Utils) {
1751
1826
  function AllowClear () { }
1752
1827
 
1753
1828
  AllowClear.prototype.bind = function (decorated, container, $container) {
@@ -1789,10 +1864,22 @@ S2.define('select2/selection/allowClear',[
1789
1864
 
1790
1865
  evt.stopPropagation();
1791
1866
 
1792
- var data = $clear.data('data');
1867
+ var data = Utils.GetData($clear[0], 'data');
1868
+
1869
+ var previousVal = this.$element.val();
1870
+ this.$element.val(this.placeholder.id);
1871
+
1872
+ var unselectData = {
1873
+ data: data
1874
+ };
1875
+ this.trigger('clear', unselectData);
1876
+ if (unselectData.prevented) {
1877
+ this.$element.val(previousVal);
1878
+ return;
1879
+ }
1793
1880
 
1794
1881
  for (var d = 0; d < data.length; d++) {
1795
- var unselectData = {
1882
+ unselectData = {
1796
1883
  data: data[d]
1797
1884
  };
1798
1885
 
@@ -1802,11 +1889,12 @@ S2.define('select2/selection/allowClear',[
1802
1889
 
1803
1890
  // If the event was prevented, don't clear it out.
1804
1891
  if (unselectData.prevented) {
1892
+ this.$element.val(previousVal);
1805
1893
  return;
1806
1894
  }
1807
1895
  }
1808
1896
 
1809
- this.$element.val(this.placeholder.id).trigger('change');
1897
+ this.$element.trigger('change');
1810
1898
 
1811
1899
  this.trigger('toggle', {});
1812
1900
  };
@@ -1829,12 +1917,14 @@ S2.define('select2/selection/allowClear',[
1829
1917
  return;
1830
1918
  }
1831
1919
 
1920
+ var removeAll = this.options.get('translations').get('removeAllItems');
1921
+
1832
1922
  var $remove = $(
1833
- '<span class="select2-selection__clear">' +
1923
+ '<span class="select2-selection__clear" title="' + removeAll() +'">' +
1834
1924
  '&times;' +
1835
1925
  '</span>'
1836
1926
  );
1837
- $remove.data('data', data);
1927
+ Utils.StoreData($remove[0], 'data', data);
1838
1928
 
1839
1929
  this.$selection.find('.select2-selection__rendered').prepend($remove);
1840
1930
  };
@@ -1925,7 +2015,7 @@ S2.define('select2/selection/search',[
1925
2015
  .prev('.select2-selection__choice');
1926
2016
 
1927
2017
  if ($previousChoice.length > 0) {
1928
- var item = $previousChoice.data('data');
2018
+ var item = Utils.GetData($previousChoice[0], 'data');
1929
2019
 
1930
2020
  self.searchRemoveChoice(item);
1931
2021
 
@@ -2019,7 +2109,13 @@ S2.define('select2/selection/search',[
2019
2109
 
2020
2110
  this.resizeSearch();
2021
2111
  if (searchHadFocus) {
2022
- this.$search.focus();
2112
+ var isTagInput = this.$element.find('[data-select2-tag]').length;
2113
+ if (isTagInput) {
2114
+ // fix IE11 bug where tag input lost focus
2115
+ this.$element.focus();
2116
+ } else {
2117
+ this.$search.focus();
2118
+ }
2023
2119
  }
2024
2120
  };
2025
2121
 
@@ -2077,10 +2173,12 @@ S2.define('select2/selection/eventRelay',[
2077
2173
  'close', 'closing',
2078
2174
  'select', 'selecting',
2079
2175
  'unselect', 'unselecting',
2080
- 'focus'
2176
+ 'clear', 'clearing'
2081
2177
  ];
2082
2178
 
2083
- var preventableEvents = ['opening', 'closing', 'selecting', 'unselecting'];
2179
+ var preventableEvents = [
2180
+ 'opening', 'closing', 'selecting', 'unselecting', 'clearing'
2181
+ ];
2084
2182
 
2085
2183
  decorated.call(this, container, $container);
2086
2184
 
@@ -2413,6 +2511,7 @@ S2.define('select2/diacritics',[
2413
2511
  '\u019F': 'O',
2414
2512
  '\uA74A': 'O',
2415
2513
  '\uA74C': 'O',
2514
+ '\u0152': 'OE',
2416
2515
  '\u01A2': 'OI',
2417
2516
  '\uA74E': 'OO',
2418
2517
  '\u0222': 'OU',
@@ -2822,6 +2921,7 @@ S2.define('select2/diacritics',[
2822
2921
  '\uA74B': 'o',
2823
2922
  '\uA74D': 'o',
2824
2923
  '\u0275': 'o',
2924
+ '\u0153': 'oe',
2825
2925
  '\u01A3': 'oi',
2826
2926
  '\u0223': 'ou',
2827
2927
  '\uA74F': 'oo',
@@ -2990,8 +3090,9 @@ S2.define('select2/diacritics',[
2990
3090
  '\u03CD': '\u03C5',
2991
3091
  '\u03CB': '\u03C5',
2992
3092
  '\u03B0': '\u03C5',
2993
- '\u03C9': '\u03C9',
2994
- '\u03C2': '\u03C3'
3093
+ '\u03CE': '\u03C9',
3094
+ '\u03C2': '\u03C3',
3095
+ '\u2019': '\''
2995
3096
  };
2996
3097
 
2997
3098
  return diacritics;
@@ -3159,7 +3260,7 @@ S2.define('select2/data/select',[
3159
3260
  // Remove anything added to child elements
3160
3261
  this.$element.find('*').each(function () {
3161
3262
  // Remove any custom data set by Select2
3162
- $.removeData(this, 'data');
3263
+ Utils.RemoveData(this);
3163
3264
  });
3164
3265
  };
3165
3266
 
@@ -3232,7 +3333,7 @@ S2.define('select2/data/select',[
3232
3333
  normalizedData.element = option;
3233
3334
 
3234
3335
  // Override the option's data with the combined data
3235
- $.data(option, 'data', normalizedData);
3336
+ Utils.StoreData(option, 'data', normalizedData);
3236
3337
 
3237
3338
  return $option;
3238
3339
  };
@@ -3240,7 +3341,7 @@ S2.define('select2/data/select',[
3240
3341
  SelectAdapter.prototype.item = function ($option) {
3241
3342
  var data = {};
3242
3343
 
3243
- data = $.data($option[0], 'data');
3344
+ data = Utils.GetData($option[0], 'data');
3244
3345
 
3245
3346
  if (data != null) {
3246
3347
  return data;
@@ -3278,13 +3379,13 @@ S2.define('select2/data/select',[
3278
3379
  data = this._normalizeItem(data);
3279
3380
  data.element = $option[0];
3280
3381
 
3281
- $.data($option[0], 'data', data);
3382
+ Utils.StoreData($option[0], 'data', data);
3282
3383
 
3283
3384
  return data;
3284
3385
  };
3285
3386
 
3286
3387
  SelectAdapter.prototype._normalizeItem = function (item) {
3287
- if (!$.isPlainObject(item)) {
3388
+ if (item !== Object(item)) {
3288
3389
  item = {
3289
3390
  id: item,
3290
3391
  text: item
@@ -3488,7 +3589,8 @@ S2.define('select2/data/ajax',[
3488
3589
  }, function () {
3489
3590
  // Attempt to detect if a request was aborted
3490
3591
  // Only works if the transport exposes a status property
3491
- if ($request.status && $request.status === '0') {
3592
+ if ('status' in $request &&
3593
+ ($request.status === 0 || $request.status === '0')) {
3492
3594
  return;
3493
3595
  }
3494
3596
 
@@ -3887,7 +3989,7 @@ S2.define('select2/dropdown',[
3887
3989
  };
3888
3990
 
3889
3991
  Dropdown.prototype.position = function ($dropdown, $container) {
3890
- // Should be implmented in subclasses
3992
+ // Should be implemented in subclasses
3891
3993
  };
3892
3994
 
3893
3995
  Dropdown.prototype.destroy = function () {
@@ -3960,6 +4062,7 @@ S2.define('select2/dropdown/search',[
3960
4062
  self.$search.attr('tabindex', -1);
3961
4063
 
3962
4064
  self.$search.val('');
4065
+ self.$search.blur();
3963
4066
  });
3964
4067
 
3965
4068
  container.on('focus', function () {
@@ -4225,14 +4328,14 @@ S2.define('select2/dropdown/attachBody',[
4225
4328
 
4226
4329
  var $watchers = this.$container.parents().filter(Utils.hasScroll);
4227
4330
  $watchers.each(function () {
4228
- $(this).data('select2-scroll-position', {
4331
+ Utils.StoreData(this, 'select2-scroll-position', {
4229
4332
  x: $(this).scrollLeft(),
4230
4333
  y: $(this).scrollTop()
4231
4334
  });
4232
4335
  });
4233
4336
 
4234
4337
  $watchers.on(scrollEvent, function (ev) {
4235
- var position = $(this).data('select2-scroll-position');
4338
+ var position = Utils.GetData(this, 'select2-scroll-position');
4236
4339
  $(this).scrollTop(position.y);
4237
4340
  });
4238
4341
 
@@ -4291,10 +4394,10 @@ S2.define('select2/dropdown/attachBody',[
4291
4394
  top: container.bottom
4292
4395
  };
4293
4396
 
4294
- // Determine what the parent element is to use for calciulating the offset
4397
+ // Determine what the parent element is to use for calculating the offset
4295
4398
  var $offsetParent = this.$dropdownParent;
4296
4399
 
4297
- // For statically positoned elements, we need to get the element
4400
+ // For statically positioned elements, we need to get the element
4298
4401
  // that is determining the offset
4299
4402
  if ($offsetParent.css('position') === 'static') {
4300
4403
  $offsetParent = $offsetParent.offsetParent();
@@ -4397,8 +4500,8 @@ S2.define('select2/dropdown/minimumResultsForSearch',[
4397
4500
  });
4398
4501
 
4399
4502
  S2.define('select2/dropdown/selectOnClose',[
4400
-
4401
- ], function () {
4503
+ '../utils'
4504
+ ], function (Utils) {
4402
4505
  function SelectOnClose () { }
4403
4506
 
4404
4507
  SelectOnClose.prototype.bind = function (decorated, container, $container) {
@@ -4429,7 +4532,7 @@ S2.define('select2/dropdown/selectOnClose',[
4429
4532
  return;
4430
4533
  }
4431
4534
 
4432
- var data = $highlightedResults.data('data');
4535
+ var data = Utils.GetData($highlightedResults[0], 'data');
4433
4536
 
4434
4537
  // Don't re-select already selected resulte
4435
4538
  if (
@@ -4470,7 +4573,7 @@ S2.define('select2/dropdown/closeOnSelect',[
4470
4573
  var originalEvent = evt.originalEvent;
4471
4574
 
4472
4575
  // Don't close if the control key is being held
4473
- if (originalEvent && originalEvent.ctrlKey) {
4576
+ if (originalEvent && (originalEvent.ctrlKey || originalEvent.metaKey)) {
4474
4577
  return;
4475
4578
  }
4476
4579
 
@@ -4524,6 +4627,9 @@ S2.define('select2/i18n/en',[],function () {
4524
4627
  },
4525
4628
  searching: function () {
4526
4629
  return 'Searching…';
4630
+ },
4631
+ removeAllItems: function () {
4632
+ return 'Remove all items';
4527
4633
  }
4528
4634
  };
4529
4635
  });
@@ -4895,6 +5001,7 @@ S2.define('select2/defaults',[
4895
5001
  maximumSelectionLength: 0,
4896
5002
  minimumResultsForSearch: 0,
4897
5003
  selectOnClose: false,
5004
+ scrollAfterSelect: false,
4898
5005
  sorter: function (data) {
4899
5006
  return data;
4900
5007
  },
@@ -4917,7 +5024,7 @@ S2.define('select2/defaults',[
4917
5024
 
4918
5025
  var convertedData = Utils._convertData(data);
4919
5026
 
4920
- $.extend(this.defaults, convertedData);
5027
+ $.extend(true, this.defaults, convertedData);
4921
5028
  };
4922
5029
 
4923
5030
  var defaults = new Defaults();
@@ -4982,7 +5089,7 @@ S2.define('select2/options',[
4982
5089
  $e.prop('disabled', this.options.disabled);
4983
5090
  $e.prop('multiple', this.options.multiple);
4984
5091
 
4985
- if ($e.data('select2Tags')) {
5092
+ if (Utils.GetData($e[0], 'select2Tags')) {
4986
5093
  if (this.options.debug && window.console && console.warn) {
4987
5094
  console.warn(
4988
5095
  'Select2: The `data-select2-tags` attribute has been changed to ' +
@@ -4991,11 +5098,11 @@ S2.define('select2/options',[
4991
5098
  );
4992
5099
  }
4993
5100
 
4994
- $e.data('data', $e.data('select2Tags'));
4995
- $e.data('tags', true);
5101
+ Utils.StoreData($e[0], 'data', Utils.GetData($e[0], 'select2Tags'));
5102
+ Utils.StoreData($e[0], 'tags', true);
4996
5103
  }
4997
5104
 
4998
- if ($e.data('ajaxUrl')) {
5105
+ if (Utils.GetData($e[0], 'ajaxUrl')) {
4999
5106
  if (this.options.debug && window.console && console.warn) {
5000
5107
  console.warn(
5001
5108
  'Select2: The `data-ajax-url` attribute has been changed to ' +
@@ -5004,21 +5111,45 @@ S2.define('select2/options',[
5004
5111
  );
5005
5112
  }
5006
5113
 
5007
- $e.attr('ajax--url', $e.data('ajaxUrl'));
5008
- $e.data('ajax--url', $e.data('ajaxUrl'));
5114
+ $e.attr('ajax--url', Utils.GetData($e[0], 'ajaxUrl'));
5115
+ Utils.StoreData($e[0], 'ajax-Url', Utils.GetData($e[0], 'ajaxUrl'));
5009
5116
  }
5010
5117
 
5011
5118
  var dataset = {};
5012
5119
 
5120
+ function upperCaseLetter(_, letter) {
5121
+ return letter.toUpperCase();
5122
+ }
5123
+
5124
+ // Pre-load all of the attributes which are prefixed with `data-`
5125
+ for (var attr = 0; attr < $e[0].attributes.length; attr++) {
5126
+ var attributeName = $e[0].attributes[attr].name;
5127
+ var prefix = 'data-';
5128
+
5129
+ if (attributeName.substr(0, prefix.length) == prefix) {
5130
+ // Get the contents of the attribute after `data-`
5131
+ var dataName = attributeName.substring(prefix.length);
5132
+
5133
+ // Get the data contents from the consistent source
5134
+ // This is more than likely the jQuery data helper
5135
+ var dataValue = Utils.GetData($e[0], dataName);
5136
+
5137
+ // camelCase the attribute name to match the spec
5138
+ var camelDataName = dataName.replace(/-([a-z])/g, upperCaseLetter);
5139
+
5140
+ // Store the data attribute contents into the dataset since
5141
+ dataset[camelDataName] = dataValue;
5142
+ }
5143
+ }
5144
+
5013
5145
  // Prefer the element's `dataset` attribute if it exists
5014
5146
  // jQuery 1.x does not correctly handle data attributes with multiple dashes
5015
5147
  if ($.fn.jquery && $.fn.jquery.substr(0, 2) == '1.' && $e[0].dataset) {
5016
- dataset = $.extend(true, {}, $e[0].dataset, $e.data());
5017
- } else {
5018
- dataset = $e.data();
5148
+ dataset = $.extend(true, {}, $e[0].dataset, dataset);
5019
5149
  }
5020
5150
 
5021
- var data = $.extend(true, {}, dataset);
5151
+ // Prefer our internal data cache if it exists
5152
+ var data = $.extend(true, {}, Utils.GetData($e[0]), dataset);
5022
5153
 
5023
5154
  data = Utils._convertData(data);
5024
5155
 
@@ -5055,8 +5186,8 @@ S2.define('select2/core',[
5055
5186
  './keys'
5056
5187
  ], function ($, Options, Utils, KEYS) {
5057
5188
  var Select2 = function ($element, options) {
5058
- if ($element.data('select2') != null) {
5059
- $element.data('select2').destroy();
5189
+ if (Utils.GetData($element[0], 'select2') != null) {
5190
+ Utils.GetData($element[0], 'select2').destroy();
5060
5191
  }
5061
5192
 
5062
5193
  this.$element = $element;
@@ -5072,7 +5203,7 @@ S2.define('select2/core',[
5072
5203
  // Set up the tabindex
5073
5204
 
5074
5205
  var tabindex = $element.attr('tabindex') || 0;
5075
- $element.data('old-tabindex', tabindex);
5206
+ Utils.StoreData($element[0], 'old-tabindex', tabindex);
5076
5207
  $element.attr('tabindex', '-1');
5077
5208
 
5078
5209
  // Set up containers and adapters
@@ -5133,6 +5264,9 @@ S2.define('select2/core',[
5133
5264
  // Synchronize any monitored attributes
5134
5265
  this._syncAttributes();
5135
5266
 
5267
+ Utils.StoreData($element[0], 'select2', this);
5268
+
5269
+ // Ensure backwards compatibility with $element.data('select2').
5136
5270
  $element.data('select2', this);
5137
5271
  };
5138
5272
 
@@ -5370,12 +5504,11 @@ S2.define('select2/core',[
5370
5504
  var key = evt.which;
5371
5505
 
5372
5506
  if (self.isOpen()) {
5373
- if (key === KEYS.ESC || key === KEYS.TAB ||
5374
- (key === KEYS.UP && evt.altKey)) {
5507
+ if (key === KEYS.ESC || (key === KEYS.UP && evt.altKey)) {
5375
5508
  self.close();
5376
5509
 
5377
5510
  evt.preventDefault();
5378
- } else if (key === KEYS.ENTER) {
5511
+ } else if (key === KEYS.ENTER || key === KEYS.TAB) {
5379
5512
  self.trigger('results:select', {});
5380
5513
 
5381
5514
  evt.preventDefault();
@@ -5467,7 +5600,8 @@ S2.define('select2/core',[
5467
5600
  'open': 'opening',
5468
5601
  'close': 'closing',
5469
5602
  'select': 'selecting',
5470
- 'unselect': 'unselecting'
5603
+ 'unselect': 'unselecting',
5604
+ 'clear': 'clearing'
5471
5605
  };
5472
5606
 
5473
5607
  if (args === undefined) {
@@ -5622,10 +5756,12 @@ S2.define('select2/core',[
5622
5756
  this._syncS = null;
5623
5757
 
5624
5758
  this.$element.off('.select2');
5625
- this.$element.attr('tabindex', this.$element.data('old-tabindex'));
5759
+ this.$element.attr('tabindex',
5760
+ Utils.GetData(this.$element[0], 'old-tabindex'));
5626
5761
 
5627
5762
  this.$element.removeClass('select2-hidden-accessible');
5628
5763
  this.$element.attr('aria-hidden', 'false');
5764
+ Utils.RemoveData(this.$element[0]);
5629
5765
  this.$element.removeData('select2');
5630
5766
 
5631
5767
  this.dataAdapter.destroy();
@@ -5653,7 +5789,7 @@ S2.define('select2/core',[
5653
5789
 
5654
5790
  this.$container.addClass('select2-container--' + this.options.get('theme'));
5655
5791
 
5656
- $container.data('element', this.$element);
5792
+ Utils.StoreData($container[0], 'element', this.$element);
5657
5793
 
5658
5794
  return $container;
5659
5795
  };
@@ -5673,8 +5809,9 @@ S2.define('jquery.select2',[
5673
5809
  'jquery-mousewheel',
5674
5810
 
5675
5811
  './select2/core',
5676
- './select2/defaults'
5677
- ], function ($, _, Select2, Defaults) {
5812
+ './select2/defaults',
5813
+ './select2/utils'
5814
+ ], function ($, _, Select2, Defaults, Utils) {
5678
5815
  if ($.fn.select2 == null) {
5679
5816
  // All methods that should return the element
5680
5817
  var thisMethods = ['open', 'close', 'destroy'];
@@ -5695,7 +5832,7 @@ S2.define('jquery.select2',[
5695
5832
  var args = Array.prototype.slice.call(arguments, 1);
5696
5833
 
5697
5834
  this.each(function () {
5698
- var instance = $(this).data('select2');
5835
+ var instance = Utils.GetData(this, 'select2');
5699
5836
 
5700
5837
  if (instance == null && window.console && console.error) {
5701
5838
  console.error(
@@ -118,12 +118,14 @@
118
118
  .select2-hidden-accessible {
119
119
  border: 0 !important;
120
120
  clip: rect(0 0 0 0) !important;
121
+ -webkit-clip-path: inset(50%) !important;
122
+ clip-path: inset(50%) !important;
121
123
  height: 1px !important;
122
- margin: -1px !important;
123
124
  overflow: hidden !important;
124
125
  padding: 0 !important;
125
126
  position: absolute !important;
126
- width: 1px !important; }
127
+ width: 1px !important;
128
+ white-space: nowrap !important; }
127
129
 
128
130
  .select2-container--default .select2-selection--single {
129
131
  background-color: #fff;
@@ -420,9 +422,7 @@
420
422
  color: #555; }
421
423
 
422
424
  .select2-container--classic[dir="rtl"] .select2-selection--multiple .select2-selection__choice {
423
- float: right; }
424
-
425
- .select2-container--classic[dir="rtl"] .select2-selection--multiple .select2-selection__choice {
425
+ float: right;
426
426
  margin-left: 5px;
427
427
  margin-right: auto; }
428
428
 
@@ -103,13 +103,21 @@ module Effective
103
103
  # Apply ActsAsArchived behavior. That's all for now.
104
104
  def translate(collection)
105
105
  return collection unless object.respond_to?(:new_record?)
106
- return collection unless collection.respond_to?(:klass) && collection.klass.respond_to?(:acts_as_archived?)
106
+ return collection unless collection.respond_to?(:klass)
107
107
 
108
- if object.new_record?
109
- collection.unarchived
110
- else
111
- collection.unarchived.or(collection.archived.where(collection.klass.primary_key => value))
108
+ if collection.klass.respond_to?(:acts_as_archived?)
109
+ collection = if object.new_record?
110
+ collection.unarchived
111
+ else
112
+ collection.unarchived.or(collection.archived.where(collection.klass.primary_key => value))
113
+ end
112
114
  end
115
+
116
+ if respond_to?(:ajax?) && ajax? # effective_select
117
+ collection = collection.where(collection.klass.primary_key => value)
118
+ end
119
+
120
+ collection
113
121
  end
114
122
 
115
123
  def assign_options_collection_methods!
@@ -43,6 +43,7 @@ module Effective
43
43
  template: js_template,
44
44
  containerClass: ('hide-disabled' if hide_disabled?),
45
45
  dropdownClass: ('hide-disabled' if hide_disabled?),
46
+ ajax: ({ url: ajax_url, dataType: 'json', delay: 250 } if ajax?)
46
47
  }.compact
47
48
  end
48
49
 
@@ -82,6 +83,10 @@ module Effective
82
83
  options_collection
83
84
  end
84
85
 
86
+ def ajax?
87
+ ajax_url.present?
88
+ end
89
+
85
90
  private
86
91
 
87
92
  def include_null
@@ -103,7 +108,6 @@ module Effective
103
108
 
104
109
  def multiple?
105
110
  return @multiple unless @multiple.nil?
106
-
107
111
  @multiple = options.key?(:multiple) ? options.delete(:multiple) : (tags? || name.to_s.ends_with?('_ids'))
108
112
  end
109
113
 
@@ -132,6 +136,10 @@ module Effective
132
136
  @js_template = options.delete(:template)
133
137
  end
134
138
 
139
+ def ajax_url
140
+ @ajax_url ||= (options.delete(:ajax_url) || options.delete(:ajax) || options.delete(:url))
141
+ end
142
+
135
143
  end
136
144
  end
137
145
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveBootstrap
2
- VERSION = '0.5.18'.freeze
2
+ VERSION = '0.5.19'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.18
4
+ version: 0.5.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-14 00:00:00.000000000 Z
11
+ date: 2019-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails