active_frontend 14.0.79 → 14.0.80

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: de8a5f38c474a6680953620fc55a1ae331d04b94
4
- data.tar.gz: 9a59c2c42213cc8c132e1a7b084c7a1360aa9490
3
+ metadata.gz: 26f7d6c60198c236566908ce470752f07eafc567
4
+ data.tar.gz: 88ffb6f56d5f9cf115a007cbae049f983a670f74
5
5
  SHA512:
6
- metadata.gz: 24a65f0425927e9fb0c9adcbc3eabd44744a2c77ffe12e412ab9965ae89135887bb298b70952bf4d8900f2007ad9ba7753a96f4a30cfb6bc7240d328c646707e
7
- data.tar.gz: 272d7b5d4a2db8a836d67df7adf78dfa25fbe5165aff9c2e1ae96f12451456ac709a9902afaacfb62c60afbd150f959fedd03b05cab04666185c4876832c568d
6
+ metadata.gz: 89129309ff6370cd03149c63ee8c613544a6299369be28fe8f778867a4f5fa88b128af7bd13e2d556b4233eecee9361b1046b1c9c5d4a4f7945e3610e64392ab
7
+ data.tar.gz: 8749fc2fe027b08be732d735c84029be1fe2cf2bada74d39ff0e6143f294e9b6b89f8fb30586f498a0b9f6605e92d9adbeffe96e8f16220a184ce9938201d39c
@@ -1,3 +1,3 @@
1
1
  module ActiveFrontend
2
- VERSION = '14.0.79'.freeze
2
+ VERSION = '14.0.80'.freeze
3
3
  end
@@ -9,7 +9,8 @@
9
9
  this.settings = {
10
10
  fuzzySearch: this.$element.data('fuzzySearch'),
11
11
  includePrompt: this.$element.data('includePrompt'),
12
- optionClass: this.$element.data('optionClass'),
12
+ optionHoverClass: this.$element.data('optionHoverClass'),
13
+ optionSelectedClass: this.$element.data('optionSelectedClass'),
13
14
  text: {
14
15
  selectless: this.$element.data('text-selectless') || Selectpicker.DEFAULTS.text.selectless,
15
16
  placeholder: this.$element.data('text-placeholder') || Selectpicker.DEFAULTS.text.placeholder,
@@ -18,6 +19,8 @@
18
19
  };
19
20
  this.options = $.extend({}, Selectpicker.DEFAULTS, this.settings, options);
20
21
 
22
+ this.$options = this.getOptions();
23
+ this.$selected = this.getSelectedOptionVal();
21
24
  this.$fuzzyId = 'bsSelectpicker-fuzzy-' + this.randomNumber();
22
25
  this.$widget = $(this.initWidget()).on('click', $.proxy(this.clickWidget, this));
23
26
 
@@ -33,8 +36,10 @@
33
36
  includePrompt: true,
34
37
  item: '<li></li>',
35
38
  menu: '<ul class="selectpicker dropmenu caret"><span></span></ul>',
36
- onSetValCallback: function (select) {},
37
- optionClass: 'text-color-hover-blue',
39
+ onChangeCallback: function (old_value, new_value) {},
40
+ onSetValCallback: function (value) {},
41
+ optionHoverClass: 'text-color-hover-blue',
42
+ optionSelectedClass: 'text-color-blue',
38
43
  text: {
39
44
  selectless: 'No options available',
40
45
  placeholder: 'Filter options...',
@@ -66,7 +71,10 @@
66
71
 
67
72
  var value = $(e.target).data('val');
68
73
 
74
+ if (value === undefined) return;
75
+
69
76
  this.setVal(value);
77
+ this.hideWidget();
70
78
  };
71
79
 
72
80
  Selectpicker.prototype.initWidget = function () {
@@ -80,7 +88,7 @@
80
88
  .append(this.fuzzyTemplate());
81
89
  }
82
90
 
83
- $.each(this.getOptions(), function (index, hash) {
91
+ $.each(this.parseOptionsToHash(), function (index, hash) {
84
92
  var item = $(_self.options.item);
85
93
 
86
94
  item.append(_self.optionTemplate(hash));
@@ -110,6 +118,7 @@
110
118
  };
111
119
 
112
120
  Selectpicker.prototype.showWidget = function (e) {
121
+ this.$selected = this.getSelectedOptionVal();
113
122
  this.$container.addClass('open');
114
123
 
115
124
  var _self = this;
@@ -131,24 +140,35 @@
131
140
 
132
141
  this.$element.val(value);
133
142
  this.options.onSetValCallback(value);
143
+
144
+ if (this.$selected !== value.toString()) {
145
+ this.$container
146
+ .find('.' + this.options.optionSelectedClass)
147
+ .removeClass(this.options.optionSelectedClass);
148
+ this.$container
149
+ .find("a[data-val='" + value + "']")
150
+ .addClass(this.options.optionSelectedClass);
151
+ this.options.onChangeCallback(this.$selected, value);
152
+ }
134
153
  };
135
154
 
136
155
  Selectpicker.prototype.randomNumber = function () {
137
156
  return Math.floor((Math.random() * 100000) + 1);
138
157
  };
139
158
 
140
- Selectpicker.prototype.getOptions = function () {
159
+ Selectpicker.prototype.parseOptionsToHash = function () {
141
160
  var _self = this;
142
161
  var array = [];
143
162
 
144
- this.$element.find('option').each(function() {
163
+ this.$options.each(function() {
145
164
  var option = $(this);
146
165
 
147
166
  if (!_self.options.includePrompt && option.val() === '') return;
148
167
 
149
168
  var hash = {
150
169
  text: option.text(),
151
- value: option.val()
170
+ value: option.val(),
171
+ selected: (option.val() === _self.$selected)
152
172
  };
153
173
 
154
174
  if (option.val() === '') {
@@ -161,8 +181,20 @@
161
181
  return array;
162
182
  };
163
183
 
184
+ Selectpicker.prototype.getOptions = function () {
185
+ return this.$element.find('option');
186
+ };
187
+
188
+ Selectpicker.prototype.getSelectedOption = function () {
189
+ return this.$element.find('option:selected');
190
+ };
191
+
192
+ Selectpicker.prototype.getSelectedOptionVal = function () {
193
+ return this.getSelectedOption().val();
194
+ };
195
+
164
196
  Selectpicker.prototype.optionCount = function () {
165
- return this.getOptions().length;
197
+ return this.parseOptionsToHash().length;
166
198
  };
167
199
 
168
200
  Selectpicker.prototype.hasSelects = function () {
@@ -186,9 +218,14 @@
186
218
  return item;
187
219
  };
188
220
 
221
+ Selectpicker.prototype.optionClass = function (hash) {
222
+ return this.options.optionHoverClass +
223
+ (hash.selected ? (' ' + this.options.optionSelectedClass) : '');
224
+ };
225
+
189
226
  Selectpicker.prototype.optionTemplate = function (hash) {
190
227
  return '<a href="#" class="' +
191
- this.options.optionClass +
228
+ this.optionClass(hash) +
192
229
  '" data-val="' +
193
230
  hash.value +
194
231
  '">' +
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_frontend
3
3
  version: !ruby/object:Gem::Version
4
- version: 14.0.79
4
+ version: 14.0.80
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez