romo 0.19.5 → 0.19.6

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
- SHA1:
3
- metadata.gz: 4fc3f8ffd4150f3516e977cc2c65e3fd25862848
4
- data.tar.gz: 792b1f359b813c11cb40a595e23cd36aadd7f6e6
5
2
  SHA512:
6
- metadata.gz: 112164a4224eb8e7ac852de31606510b95ae4a52063ab9ccb40598e458955b72bcba9d991671f1d649adc770162059b74bc7a3cc25a0ea039a3e134cfb1e618d
7
- data.tar.gz: e513bd994b174937fb9c6c5d3aa15c6c03a78020447705ec54c145bfad17ea67b6e5cd2093b6b47e5a614ba05bd84a79558064b98b5dfd26816b239ddd0cd565
3
+ metadata.gz: 643c9c0e9600c876e1ec481fafc0488260c94f0c99d06a53fbc7abe791b23ff363f0922cf2ba92f605e886df4403bb8b368631f83e080a74949583dccf21675c
4
+ data.tar.gz: 1dd48f7b1d07b69f3b2e135048ba7565a6b53e1758c08e242e7074d5a2e44fcc8f32ad9f731a3a8bfdbe3b64a4f715460814bda4d43bb74400afd3fd966f0abd
5
+ SHA1:
6
+ metadata.gz: 86052336ce3a41a0592c123eb52ad0c8f0a61709
7
+ data.tar.gz: 8d5fda1c6c5172f7e59664624dffc2830bb70410
@@ -178,7 +178,11 @@ RomoDatepicker.prototype.doSelectHighlightedItem = function() {
178
178
  this.romoDropdown.doPopupClose();
179
179
  this.doSetDate(newValue);
180
180
  this.elem.focus();
181
- this.elem.trigger('datepicker:itemSelected', [newValue, this.prevValue, this]);
181
+ this.elem.trigger('datepicker:itemSelected', [newValue, this]);
182
+ if (newValue !== this.prevValue) {
183
+ this.elem.trigger('datepicker:newItemSelected', [newValue, this]);
184
+ }
185
+ // always publish the item selected events before publishing any change events
182
186
  this._triggerSetDateChangeEvent();
183
187
  }
184
188
 
@@ -63,24 +63,24 @@ RomoOptionListDropdown.prototype.doInit = function() {
63
63
  // override as needed
64
64
  }
65
65
 
66
- RomoOptionListDropdown.prototype.doSetNewValue = function(newValue) {
66
+ RomoOptionListDropdown.prototype.doSetSelectedItem = function(itemValue) {
67
67
  this.selectedItemElem().removeClass('selected');
68
68
  this.romoDropdown.bodyElem.find(
69
- 'LI[data-romo-option-list-dropdown-option-value="'+newValue+'"]'
69
+ 'LI[data-romo-option-list-dropdown-option-value="'+itemValue+'"]'
70
70
  ).addClass('selected');
71
71
  this.doSetSelectedValueAndText(
72
- newValue,
72
+ this.selectedItemElem().data('romo-option-list-dropdown-option-value'),
73
73
  this.selectedItemElem().data('romo-option-list-dropdown-option-display-text')
74
74
  );
75
75
  }
76
76
 
77
- RomoOptionListDropdown.prototype.doSetSelectedValueAndText = function(newValue, newText) {
77
+ RomoOptionListDropdown.prototype.doSetSelectedValueAndText = function(value, text) {
78
78
  // need to use `attr` to persist selected values to the DOM for back button logic
79
79
  // to work. using `data` won't persist changes to DOM and breaks back button logic.
80
- this.elem.attr('data-romo-option-list-dropdown-selected-value', newValue);
81
- this.elem.attr('data-romo-option-list-dropdown-selected-text', newText);
80
+ this.elem.attr('data-romo-option-list-dropdown-selected-value', value);
81
+ this.elem.attr('data-romo-option-list-dropdown-selected-text', text);
82
82
 
83
- this.prevValue = newValue;
83
+ this.prevValue = value;
84
84
  }
85
85
 
86
86
  /*
@@ -354,12 +354,15 @@ RomoOptionListDropdown.prototype._selectHighlightedItem = function() {
354
354
  if (curr.length !== 0) {
355
355
  var prevValue = this.prevValue;
356
356
  var newValue = curr.data('romo-option-list-dropdown-option-value');
357
+ var newText = curr.data('romo-option-list-dropdown-option-display-text');
357
358
 
358
359
  this.romoDropdown.doPopupClose();
359
- this.elem.trigger('romoOptionListDropdown:itemSelected', [newValue, prevValue, this]);
360
360
 
361
+ this.elem.trigger('romoOptionListDropdown:itemSelected', [newValue, newText, this]);
361
362
  if (newValue !== prevValue) {
362
- this.doSetNewValue(newValue);
363
+ this.doSetSelectedItem(newValue);
364
+ // always publish the item selected events before publishing any change events
365
+ this.elem.trigger('romoOptionListDropdown:newItemSelected', [newValue, newText, this]);
363
366
  this.elem.trigger('romoOptionListDropdown:change', [newValue, prevValue, this]);
364
367
  }
365
368
  }
@@ -16,7 +16,15 @@ var RomoPicker = function(element) {
16
16
 
17
17
  this.doInit();
18
18
  this._bindElem();
19
- this.doRefreshUI();
19
+
20
+ var presetVal = this.elem[0].value;
21
+ if (presetVal !== '') {
22
+ this.doSetValue(presetVal);
23
+ } else if (this.elem.data('romo-picker-empty-option') === true) {
24
+ this.doSetValueAndText('', this.elem.data('romo-picker-empty-option-display-text') || '');
25
+ } else {
26
+ this.doSetValueAndText('', '');
27
+ }
20
28
 
21
29
  if (this.elem.attr('id') !== undefined) {
22
30
  $('label[for="'+this.elem.attr('id')+'"]').on('click', $.proxy(function(e) {
@@ -25,11 +33,7 @@ var RomoPicker = function(element) {
25
33
  }
26
34
 
27
35
  $(window).on("pageshow", $.proxy(function(e) {
28
- var selectedVal = this.romoOptionListDropdown.selectedItemValue();
29
- if (selectedVal !== this.elem[0].value) {
30
- var selectedText = this.romoOptionListDropdown.selectedItemText();
31
- this.doSetSelectedValueAndText(selectedVal, selectedText);
32
- }
36
+ this._refreshUI();
33
37
  }, this));
34
38
 
35
39
  this.elem.on('romoPicker:triggerSetValue', $.proxy(function(e, value) {
@@ -43,14 +47,6 @@ RomoPicker.prototype.doInit = function() {
43
47
  // override as needed
44
48
  }
45
49
 
46
- RomoPicker.prototype.doRefreshUI = function() {
47
- var text = this.romoOptionListDropdown.selectedItemText();
48
- if (text === '') {
49
- text = ' '
50
- }
51
- this.romoOptionListDropdown.elem.find('.romo-picker-text').html(text);
52
- }
53
-
54
50
  RomoPicker.prototype.doSetValue = function(value) {
55
51
  $.ajax({
56
52
  type: 'GET',
@@ -58,17 +54,20 @@ RomoPicker.prototype.doSetValue = function(value) {
58
54
  data: { 'values': value },
59
55
  success: $.proxy(function(data, status, xhr) {
60
56
  if (data[0] !== undefined) {
61
- this.doSetSelectedValueAndText(data[0].value, data[0].displayText);
57
+ this.doSetValueAndText(data[0].value, data[0].displayText);
58
+ } else if (this.elem.data('romo-picker-empty-option') === true) {
59
+ this.doSetValueAndText('', this.elem.data('romo-picker-empty-option-display-text') || '');
62
60
  } else {
63
- this.doSetSelectedValueAndText('', '');
61
+ this.doSetValueAndText('', '');
64
62
  }
65
63
  }, this),
66
64
  });
67
65
  }
68
66
 
69
- RomoPicker.prototype.doSetSelectedValueAndText = function(value, text) {
67
+ RomoPicker.prototype.doSetValueAndText = function(value, text) {
70
68
  this.romoOptionListDropdown.doSetSelectedValueAndText(value, text);
71
- this._setNewValue(value);
69
+ this._setValueAndText(value, text);
70
+ this._refreshUI();
72
71
  }
73
72
 
74
73
  /* private */
@@ -88,11 +87,6 @@ RomoPicker.prototype._bindElem = function() {
88
87
  }, this));
89
88
 
90
89
  this.romoOptionListDropdown.doSetListItems(this.defaultOptionItems);
91
-
92
- var presetVal = this.elem[0].value;
93
- if (presetVal !== '') {
94
- this.doSetValue(presetVal);
95
- }
96
90
  }
97
91
 
98
92
  RomoPicker.prototype._bindOptionListDropdown = function() {
@@ -119,12 +113,16 @@ RomoPicker.prototype._bindOptionListDropdown = function() {
119
113
  this._setListItems(this.defaultOptionItems.concat(this._buildCustomOptionItems()));
120
114
  }
121
115
  }, this));
122
- this.romoOptionListDropdown.elem.on('romoOptionListDropdown:itemSelected', $.proxy(function(e, newValue, prevValue, optionListDropdown) {
116
+ this.romoOptionListDropdown.elem.on('romoOptionListDropdown:itemSelected', $.proxy(function(e, itemValue, itemDisplayText, optionListDropdown) {
123
117
  this.romoOptionListDropdown.elem.focus();
124
- this.elem.trigger('romoPicker:itemSelected', [newValue, prevValue, this]);
118
+ this.elem.trigger('romoPicker:itemSelected', [itemValue, itemDisplayText, this]);
119
+ }, this));
120
+ this.romoOptionListDropdown.elem.on('romoOptionListDropdown:newItemSelected', $.proxy(function(e, itemValue, itemDisplayText, optionListDropdown) {
121
+ this._setValueAndText(itemValue, itemDisplayText);
122
+ this._refreshUI();
123
+ this.elem.trigger('romoPicker:newItemSelected', [itemValue, itemDisplayText, this]);
125
124
  }, this));
126
125
  this.romoOptionListDropdown.elem.on('romoOptionListDropdown:change', $.proxy(function(e, newValue, prevValue, optionListDropdown) {
127
- this._setNewValue(newValue);
128
126
  this.elem.trigger('change');
129
127
  this.elem.trigger('romoPicker:change', [newValue, prevValue, this]);
130
128
  }, this));
@@ -250,7 +248,7 @@ RomoPicker.prototype._buildDefaultOptionItems = function() {
250
248
  items.push({
251
249
  'type': 'option',
252
250
  'value': '',
253
- 'displayText': '',
251
+ 'displayText': (this.elem.data('romo-picker-empty-option-display-text') || ''),
254
252
  'displayHtml': ' '
255
253
  });
256
254
  }
@@ -287,6 +285,27 @@ RomoPicker.prototype._buildCustomOptionItem = function(value) {
287
285
  };
288
286
  }
289
287
 
288
+ RomoPicker.prototype._setValueAndText = function(value, text) {
289
+ this.elem[0].value = value;
290
+
291
+ // store the display text on the DOM to compliment the value being stored on the
292
+ // DOM via the elem above. need to use `attr` to persist selected values to the
293
+ // DOM for back button logic to work. using `data` won't persist changes to DOM
294
+ // and breaks how the component deals with back-button behavior.
295
+ this.elem.attr('data-romo-picker-display-text', text);
296
+ }
297
+
298
+ RomoPicker.prototype._refreshUI = function() {
299
+ // need to use `attr` so it will always read from the DOM
300
+ // using `data` works the first time but does some elem caching or something
301
+ // so it won't work subsequent times.
302
+ var text = this.elem.attr('data-romo-picker-display-text');
303
+ if (text === '') {
304
+ text = ' '
305
+ }
306
+ this.romoOptionListDropdown.elem.find('.romo-picker-text').html(text);
307
+ }
308
+
290
309
  RomoPicker.prototype._onCaretClick = function(e) {
291
310
  if (this.elem.prop('disabled') === false) {
292
311
  this.romoOptionListDropdown.elem.focus();
@@ -294,11 +313,6 @@ RomoPicker.prototype._onCaretClick = function(e) {
294
313
  }
295
314
  }
296
315
 
297
- RomoPicker.prototype._setNewValue = function(newValue) {
298
- this.elem[0].value = newValue;
299
- this.doRefreshUI();
300
- }
301
-
302
316
  RomoPicker.prototype._getCaretPaddingPx = function() {
303
317
  return (
304
318
  this.elem.data('romo-picker-caret-padding-px') ||
@@ -13,7 +13,8 @@ var RomoSelect = function(element) {
13
13
 
14
14
  this.doInit();
15
15
  this._bindElem();
16
- this.doRefreshUI();
16
+
17
+ this.doSetValue(this.elem[0].value);
17
18
 
18
19
  if (this.elem.attr('id') !== undefined) {
19
20
  $('label[for="'+this.elem.attr('id')+'"]').on('click', $.proxy(function(e) {
@@ -22,10 +23,7 @@ var RomoSelect = function(element) {
22
23
  }
23
24
 
24
25
  $(window).on("pageshow", $.proxy(function(e) {
25
- var selectedVal = this.romoSelectDropdown.selectedItemValue();
26
- if (selectedVal !== this.elem[0].value) {
27
- this.doSetValue(selectedVal);
28
- }
26
+ this._refreshUI();
29
27
  }, this));
30
28
 
31
29
  this.elem.on('select:triggerSetValue', $.proxy(function(e, value) {
@@ -39,17 +37,10 @@ RomoSelect.prototype.doInit = function() {
39
37
  // override as needed
40
38
  }
41
39
 
42
- RomoSelect.prototype.doRefreshUI = function() {
43
- var text = this.romoSelectDropdown.selectedItemText();
44
- if (text === '') {
45
- text = ' '
46
- }
47
- this.romoSelectDropdown.elem.find('.romo-select-text').html(text);
48
- }
49
-
50
40
  RomoSelect.prototype.doSetValue = function(value) {
51
- this.romoSelectDropdown.doSetNewValue(value);
52
- this._setNewValue(value);
41
+ this.romoSelectDropdown.doSetSelectedItem(value);
42
+ this._setValue(value);
43
+ this._refreshUI();
53
44
  }
54
45
 
55
46
  /* private */
@@ -66,12 +57,6 @@ RomoSelect.prototype._bindElem = function() {
66
57
  this.elem.on('select:triggerPopupClose', $.proxy(function(e) {
67
58
  this.romoSelectDropdown.elem.trigger('selectDropdown:triggerPopupClose', []);
68
59
  }, this));
69
-
70
-
71
- var presetVal = this.elem[0].value;
72
- if (presetVal !== '') {
73
- this.doSetValue(presetVal);
74
- }
75
60
  }
76
61
 
77
62
  RomoSelect.prototype._bindSelectDropdown = function() {
@@ -87,12 +72,16 @@ RomoSelect.prototype._bindSelectDropdown = function() {
87
72
  this.elem.trigger('select:dropdown:popupClose', [dropdown, this]);
88
73
  }, this));
89
74
 
90
- this.romoSelectDropdown.elem.on('selectDropdown:itemSelected', $.proxy(function(e, newValue, prevValue, selectDropdown) {
75
+ this.romoSelectDropdown.elem.on('selectDropdown:itemSelected', $.proxy(function(e, itemValue, itemDisplayText, selectDropdown) {
91
76
  this.romoSelectDropdown.elem.focus();
92
- this.elem.trigger('select:itemSelected', [newValue, prevValue, this]);
77
+ this.elem.trigger('select:itemSelected', [itemValue, itemDisplayText, this]);
78
+ }, this));
79
+ this.romoSelectDropdown.elem.on('selectDropdown:newItemSelected', $.proxy(function(e, itemValue, itemDisplayText, selectDropdown) {
80
+ this._setValue(itemValue);
81
+ this._refreshUI();
82
+ this.elem.trigger('select:newItemSelected', [itemValue, itemDisplayText, this]);
93
83
  }, this));
94
84
  this.romoSelectDropdown.elem.on('selectDropdown:change', $.proxy(function(e, newValue, prevValue, selectDropdown) {
95
- this._setNewValue(newValue);
96
85
  this.elem.trigger('change');
97
86
  this.elem.trigger('select:change', [newValue, prevValue, this]);
98
87
  }, this));
@@ -189,6 +178,24 @@ RomoSelect.prototype._buildSelectDropdownElem = function() {
189
178
  return romoSelectDropdownElem;
190
179
  }
191
180
 
181
+ RomoSelect.prototype._setValue = function(value) {
182
+ var prevOptElem = this.elem.find('OPTION[value="'+this.elem[0].value+'"]');
183
+ var newOptElem = this.elem.find('OPTION[value="'+value+'"]');
184
+
185
+ prevOptElem.removeAttr('selected');
186
+ prevOptElem.prop('selected', false);
187
+ newOptElem.attr('selected', 'selected');
188
+ newOptElem.prop('selected', true);
189
+ }
190
+
191
+ RomoSelect.prototype._refreshUI = function() {
192
+ var text = this.elem.find('OPTION[selected="selected"]').text().trim();
193
+ if (text === '') {
194
+ text = ' '
195
+ }
196
+ this.romoSelectDropdown.elem.find('.romo-select-text').html(text);
197
+ }
198
+
192
199
  RomoSelect.prototype._onCaretClick = function(e) {
193
200
  if (this.elem.prop('disabled') === false) {
194
201
  this.romoSelectDropdown.elem.focus();
@@ -196,11 +203,6 @@ RomoSelect.prototype._onCaretClick = function(e) {
196
203
  }
197
204
  }
198
205
 
199
- RomoSelect.prototype._setNewValue = function(newValue) {
200
- this.elem[0].value = newValue;
201
- this.doRefreshUI();
202
- }
203
-
204
206
  RomoSelect.prototype._getCaretPaddingPx = function() {
205
207
  return (
206
208
  this.elem.data('romo-select-caret-padding-px') ||
@@ -59,8 +59,8 @@ RomoSelectDropdown.prototype.doInit = function() {
59
59
  // override as needed
60
60
  }
61
61
 
62
- RomoSelectDropdown.prototype.doSetNewValue = function(newValue) {
63
- this.romoOptionListDropdown.doSetNewValue(newValue);
62
+ RomoSelectDropdown.prototype.doSetSelectedItem = function(newValue) {
63
+ this.romoOptionListDropdown.doSetSelectedItem(newValue);
64
64
  }
65
65
 
66
66
  /* private */
@@ -93,8 +93,24 @@ RomoSelectDropdown.prototype._bindElem = function() {
93
93
  this.elem.on('romoOptionListDropdown:dropdown:popupClose', $.proxy(function(e, dropdown) {
94
94
  this.elem.trigger('selectDropdown:dropdown:popupClose', [dropdown, this]);
95
95
  }, this));
96
- this.elem.on('romoOptionListDropdown:itemSelected', $.proxy(function(e, newValue, prevValue, romoOptionListDropdown) {
97
- this.elem.trigger('selectDropdown:itemSelected', [newValue, prevValue, this]);
96
+ this.elem.on('romoOptionListDropdown:itemSelected', $.proxy(function(e, itemValue, itemDisplayText, romoOptionListDropdown) {
97
+ this.elem.trigger('selectDropdown:itemSelected', [itemValue, itemDisplayText, this]);
98
+ }, this));
99
+ this.elem.on('romoOptionListDropdown:newItemSelected', $.proxy(function(e, itemValue, itemDisplayText, romoOptionListDropdown) {
100
+ var custOptElem = this.optionElemsParent.find('OPTION[data-romo-select-dropdown-custom-option="true"]');
101
+ if (this.optionElemsParent.find('OPTION[value="'+itemValue+'"]').length === 0){
102
+ // a custom value is being selected. add a custom option elem and update its value/text
103
+ if (custOptElem.length === 0) {
104
+ this.optionElemsParent.append('<option data-romo-select-dropdown-custom-option="true"></option>');
105
+ custOptElem = this.optionElemsParent.find('OPTION[data-romo-select-dropdown-custom-option="true"]');
106
+ }
107
+ custOptElem.attr('value', itemValue);
108
+ custOptElem.text(itemDisplayText);
109
+ } else if (custOptElem.length !== 0) {
110
+ // a non custom value is being selected. remove any existing custom option
111
+ custOptElem.remove();
112
+ }
113
+ this.elem.trigger('selectDropdown:newItemSelected', [itemValue, itemDisplayText, this]);
98
114
  }, this));
99
115
  this.elem.on('romoOptionListDropdown:change', $.proxy(function(e, newValue, prevValue, romoOptionListDropdown) {
100
116
  this.elem.trigger('selectDropdown:change', [newValue, prevValue, this]);
@@ -114,7 +130,7 @@ RomoSelectDropdown.prototype._bindElem = function() {
114
130
  this.romoOptionListDropdown = this.elem.romoOptionListDropdown()[0];
115
131
 
116
132
  this.elem.on('romoOptionListDropdown:filterChange', $.proxy(function(e, filterValue, romoOptionListDropdown) {
117
- var elems = this.optionElemsParent.find('option');
133
+ var elems = this.optionElemsParent.find('OPTION');
118
134
  var wbFilter = new RomoWordBoundaryFilter(filterValue, elems, function(elem) {
119
135
  // The romo word boundary filter by default considers a space, "-" and "_"
120
136
  // as word boundaries. We want to also consider other non-word characters
@@ -133,10 +149,23 @@ RomoSelectDropdown.prototype._bindElem = function() {
133
149
  }
134
150
  }, this));
135
151
 
152
+ this._sanitizeOptions();
136
153
  this._setListItems();
137
154
  this.elem.trigger('romoOptionListDropdown:triggerListOptionsUpdate', [this.selectedItemElem()]);
138
155
  }
139
156
 
157
+ RomoSelectDropdown.prototype._sanitizeOptions = function() {
158
+ // set any options without a value to value=""
159
+ // all options are required to have a value for things to work
160
+ // this and the select component assume value attrs for all options
161
+ $.each(this.optionElemsParent.find('OPTION'), $.proxy(function(idx, optionNode) {
162
+ var optElem = $(optionNode);
163
+ if (optElem.attr('value') === undefined) {
164
+ optElem.attr('value', '');
165
+ }
166
+ }, this));
167
+ }
168
+
140
169
  RomoSelectDropdown.prototype._setListItems = function() {
141
170
  var optElems = this.optionElemsParent.children(this.optionElemSelector);
142
171
  var items = this._buildOptionListItems(optElems).concat(this._buildCustomOptionItems());
data/lib/romo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Romo
2
- VERSION = "0.19.5"
2
+ VERSION = "0.19.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: romo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.5
4
+ version: 0.19.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2017-08-23 00:00:00 Z
13
+ date: 2017-08-25 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: assert