romo 0.19.10 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,59 +1,28 @@
1
- $.fn.romoSelect = function() {
2
- return $.map(this, function(element) {
3
- return new RomoSelect(element);
4
- });
5
- }
6
-
7
- var RomoSelect = function(element) {
8
- this.elem = $(element);
1
+ var RomoSelect = RomoComponent(function(elem) {
2
+ this.elem = elem;
9
3
 
10
4
  this.defaultCaretClass = undefined;
11
5
  this.defaultCaretPaddingPx = 5;
6
+ this.defaultCaretWidthPx = 18;
12
7
  this.defaultCaretPosition = 'right'
13
8
 
14
9
  this.doInit();
15
10
  this._bindElem();
16
11
 
17
- this.doSetValue(this._elemValues());
18
-
19
- if (this.elem.attr('id') !== undefined) {
20
- $('label[for="'+this.elem.attr('id')+'"]').on('click', $.proxy(function(e) {
21
- this.romoSelectDropdown.doFocus();
22
- }, this));
23
- }
24
-
25
- $(window).on("pageshow", $.proxy(function(e) {
26
- this._refreshUI();
27
- }, this));
28
-
29
- this.elem.on('select:triggerSetValue', $.proxy(function(e, value) {
30
- this.doSetValue(value)
31
- }, this));
32
-
33
- this.elem.trigger('select:ready', [this]);
34
- }
35
-
36
- RomoSelect.prototype.doInit = function() {
37
- // override as needed
38
- }
12
+ Romo.trigger(this.elem, 'romoSelect:ready', [this]);
13
+ });
39
14
 
40
15
  RomoSelect.prototype.doSetValue = function(value) {
41
- var values = undefined;
42
- if (Array.isArray(value)) {
43
- values = value;
44
- } else {
45
- values = [value];
46
- }
47
- values = values.filter($.proxy(function(v) {
48
- return this.elem.find('OPTION[value="'+v+'"]')[0] !== undefined;
16
+ var values = Romo.array(value).filter(Romo.proxy(function(v) {
17
+ return Romo.find(this.elem, 'OPTION[value="'+v+'"]')[0] !== undefined;
49
18
  }, this));
50
19
 
51
20
  this._setValues(values);
52
21
  if (this.romoSelectedOptionsList !== undefined) {
53
- var items = values.map($.proxy(function(value) {
22
+ var items = values.map(Romo.proxy(function(value) {
54
23
  return {
55
24
  'value': value,
56
- 'displayText': this.elem.find('OPTION[value="'+value+'"]').text().trim()
25
+ 'displayText': Romo.find(this.elem, 'OPTION[value="'+value+'"]')[0].innerText.trim()
57
26
  };
58
27
  }, this));
59
28
  this.romoSelectedOptionsList.doSetItems(items);
@@ -63,35 +32,53 @@ RomoSelect.prototype.doSetValue = function(value) {
63
32
  this._refreshUI();
64
33
  }
65
34
 
66
- /* private */
35
+ // private
67
36
 
68
37
  RomoSelect.prototype._bindElem = function() {
69
38
  this._bindSelectDropdown();
70
39
  this._bindSelectedOptionsList();
71
40
 
72
- this.elem.on('select:triggerToggle', $.proxy(function(e) {
73
- this.romoSelectDropdown.elem.trigger('selectDropdown:triggerToggle', []);
41
+ Romo.on(this.elem, 'romoSelect:triggerToggle', Romo.proxy(function(e) {
42
+ Romo.trigger(this.romoSelectDropdown.elem, 'romoSelectDropdown:triggerToggle', []);
74
43
  }, this));
75
- this.elem.on('select:triggerPopupOpen', $.proxy(function(e) {
76
- this.romoSelectDropdown.elem.trigger('selectDropdown:triggerPopupOpen', []);
44
+ Romo.on(this.elem, 'romoSelect:triggerPopupOpen', Romo.proxy(function(e) {
45
+ Romo.trigger(this.romoSelectDropdown.elem, 'romoSelectDropdown:triggerPopupOpen', []);
77
46
  }, this));
78
- this.elem.on('select:triggerPopupClose', $.proxy(function(e) {
79
- this.romoSelectDropdown.elem.trigger('selectDropdown:triggerPopupClose', []);
47
+ Romo.on(this.elem, 'romoSelect:triggerPopupClose', Romo.proxy(function(e) {
48
+ Romo.trigger(this.romoSelectDropdown.elem, 'romoSelectDropdown:triggerPopupClose', []);
49
+ }, this));
50
+
51
+ this.doSetValue(this._elemValues());
52
+
53
+ if (Romo.attr(this.elem, 'id') !== undefined) {
54
+ var labelElem = Romo.f('label[for="'+Romo.attr(this.elem, 'id')+'"]');
55
+ Romo.on(labelElem, 'click', Romo.proxy(function(e) {
56
+ e.preventDefault();
57
+ this.romoSelectDropdown.doFocus();
58
+ }, this));
59
+ }
60
+
61
+ Romo.on(window, "pageshow", Romo.proxy(function(e) {
62
+ this._refreshUI();
63
+ }, this));
64
+
65
+ Romo.on(this.elem, 'romoSelect:triggerSetValue', Romo.proxy(function(e, value) {
66
+ this.doSetValue(value)
80
67
  }, this));
81
68
  }
82
69
 
83
70
  RomoSelect.prototype._bindSelectedOptionsList = function() {
84
71
  this.romoSelectedOptionsList = undefined;
85
- if (this.elem.prop('multiple') === true) {
86
- if (this.elem.data('romo-select-multiple-item-class') !== undefined) {
87
- this.romoSelectDropdown.elem.attr('data-romo-selected-options-list-item-class', this.elem.data('romo-select-multiple-item-class'));
72
+ if (this.elem.multiple === true) {
73
+ if (Romo.data(this.elem, 'romo-select-multiple-item-class') !== undefined) {
74
+ Romo.setData(this.romoSelectDropdown.elem, 'romo-selected-options-list-item-class', Romo.data(this.elem, 'romo-select-multiple-item-class'));
88
75
  }
89
- if (this.elem.data('romo-select-multiple-max-rows') !== undefined) {
90
- this.romoSelectDropdown.elem.attr('data-romo-selected-options-list-max-rows', this.elem.data('romo-select-multiple-max-rows'));
76
+ if (Romo.data(this.elem, 'romo-select-multiple-max-rows') !== undefined) {
77
+ Romo.setData(this.romoSelectDropdown.elem, 'romo-selected-options-list-max-rows', Romo.data(this.elem, 'romo-select-multiple-max-rows'));
91
78
  }
92
79
 
93
80
  this.romoSelectedOptionsList = new RomoSelectedOptionsList(this.romoSelectDropdown.elem);
94
- this.romoSelectedOptionsList.elem.on('romoSelectedOptionsList:itemClick', $.proxy(function(e, itemValue, romoSelectedOptionsList) {
81
+ Romo.on(this.romoSelectedOptionsList.elem, 'romoSelectedOptionsList:itemClick', Romo.proxy(function(e, itemValue, romoSelectedOptionsList) {
95
82
  var currentValues = this._elemValues();
96
83
  var index = currentValues.indexOf(itemValue);
97
84
  if (index > -1) {
@@ -101,34 +88,34 @@ RomoSelect.prototype._bindSelectedOptionsList = function() {
101
88
  this.romoSelectedOptionsList.doRemoveItem(itemValue);
102
89
  this._refreshUI();
103
90
  }, this));
104
- this.romoSelectedOptionsList.elem.on('romoSelectedOptionsList:listClick', $.proxy(function(e, romoSelectedOptionsList) {
105
- this.romoSelectDropdown.elem.trigger('dropdown:triggerPopupClose', []);
91
+ Romo.on(this.romoSelectedOptionsList.elem, 'romoSelectedOptionsList:listClick', Romo.proxy(function(e, romoSelectedOptionsList) {
92
+ Romo.trigger(this.romoSelectDropdown.elem, 'romoDropdown:triggerPopupClose', []);
106
93
  this.romoSelectDropdown.doFocus(false);
107
94
  }, this));
108
95
 
109
- this.elemWrapper.before(this.romoSelectedOptionsList.elem);
96
+ Romo.before(this.elemWrapper, this.romoSelectedOptionsList.elem);
110
97
  this.romoSelectedOptionsList.doRefreshUI();
111
98
  }
112
99
  }
113
100
 
114
101
  RomoSelect.prototype._bindSelectDropdown = function() {
115
- this.romoSelectDropdown = this._buildSelectDropdownElem().romoSelectDropdown(this.elem)[0];
102
+ this.romoSelectDropdown = new RomoSelectDropdown(this._buildSelectDropdownElem(), this.elem);
116
103
 
117
- this.romoSelectDropdown.elem.on('selectDropdown:dropdown:toggle', $.proxy(function(e, dropdown, selectDropdown) {
118
- this.elem.trigger('select:dropdown:toggle', [dropdown, this]);
104
+ Romo.on(this.romoSelectDropdown.elem, 'romoSelectDropdown:romoDropdown:toggle', Romo.proxy(function(e, romoDropdown, romoSelectDropdown) {
105
+ Romo.trigger(this.elem, 'romoSelect:romoDropdown:toggle', [romoDropdown, this]);
119
106
  }, this));
120
- this.romoSelectDropdown.elem.on('selectDropdown:dropdown:popupOpen', $.proxy(function(e, dropdown, selectDropdown) {
121
- this.elem.trigger('select:dropdown:popupOpen', [dropdown, this]);
107
+ Romo.on(this.romoSelectDropdown.elem, 'romoSelectDropdown:romoDropdown:popupOpen', Romo.proxy(function(e, romoDropdown, romoSelectDropdown) {
108
+ Romo.trigger(this.elem, 'romoSelect:romoDropdown:popupOpen', [romoDropdown, this]);
122
109
  }, this));
123
- this.romoSelectDropdown.elem.on('selectDropdown:dropdown:popupClose', $.proxy(function(e, dropdown, selectDropdown) {
124
- this.elem.trigger('select:dropdown:popupClose', [dropdown, this]);
110
+ Romo.on(this.romoSelectDropdown.elem, 'romoSelectDropdown:romoDropdown:popupClose', Romo.proxy(function(e, romoDropdown, romoSelectDropdown) {
111
+ Romo.trigger(this.elem, 'romoSelect:romoDropdown:popupClose', [romoDropdown, this]);
125
112
  }, this));
126
113
 
127
- this.romoSelectDropdown.elem.on('selectDropdown:itemSelected', $.proxy(function(e, itemValue, itemDisplayText, selectDropdown) {
114
+ Romo.on(this.romoSelectDropdown.elem, 'romoSelectDropdown:itemSelected', Romo.proxy(function(e, itemValue, itemDisplayText, romoSelectDropdown) {
128
115
  this.romoSelectDropdown.doFocus();
129
- this.elem.trigger('select:itemSelected', [itemValue, itemDisplayText, this]);
116
+ Romo.trigger(this.elem, 'romoSelect:itemSelected', [itemValue, itemDisplayText, this]);
130
117
  }, this));
131
- this.romoSelectDropdown.elem.on('selectDropdown:newItemSelected', $.proxy(function(e, itemValue, itemDisplayText, selectDropdown) {
118
+ Romo.on(this.romoSelectDropdown.elem, 'romoSelectDropdown:newItemSelected', Romo.proxy(function(e, itemValue, itemDisplayText, romoSelectDropdown) {
132
119
  if (this.romoSelectedOptionsList !== undefined) {
133
120
  var currentValues = this._elemValues();
134
121
  if (!currentValues.includes(itemValue)) {
@@ -142,100 +129,103 @@ RomoSelect.prototype._bindSelectDropdown = function() {
142
129
  this._setValues([itemValue]);
143
130
  }
144
131
  this._refreshUI();
145
- this.elem.trigger('select:newItemSelected', [itemValue, itemDisplayText, this]);
132
+ Romo.trigger(this.elem, 'romoSelect:newItemSelected', [itemValue, itemDisplayText, this]);
146
133
  }, this));
147
- this.romoSelectDropdown.elem.on('selectDropdown:change', $.proxy(function(e, newValue, prevValue, selectDropdown) {
148
- this.elem.trigger('change');
149
- this.elem.trigger('select:change', [newValue, prevValue, this]);
134
+ Romo.on(this.romoSelectDropdown.elem, 'romoSelectDropdown:change', Romo.proxy(function(e, newValue, prevValue, romoSelectDropdown) {
135
+ Romo.trigger(this.elem, 'change');
136
+ Romo.trigger(this.elem, 'romoSelect:change', [newValue, prevValue, this]);
150
137
  }, this));
151
138
  }
152
139
 
153
140
  RomoSelect.prototype._buildSelectDropdownElem = function() {
154
- var romoSelectDropdownElem = $('<div class="romo-select romo-btn" tabindex="0"><span class="romo-select-text"></span></div>');
155
-
156
- romoSelectDropdownElem.attr('data-romo-dropdown-position', this.elem.data('romo-select-dropdown-position'));
157
- romoSelectDropdownElem.attr('data-romo-dropdown-style-class', this.elem.data('romo-select-dropdown-style-class'));
158
- romoSelectDropdownElem.attr('data-romo-dropdown-min-height', this.elem.data('romo-select-dropdown-min-height'));
159
- romoSelectDropdownElem.attr('data-romo-dropdown-max-height', this.elem.data('romo-select-dropdown-max-height'));
160
- romoSelectDropdownElem.attr('data-romo-dropdown-height', this.elem.data('romo-select-dropdown-height'));
161
- romoSelectDropdownElem.attr('data-romo-dropdown-overflow-x', 'hidden');
162
- romoSelectDropdownElem.attr('data-romo-dropdown-width', 'elem');
163
- if (romoSelectDropdownElem.data('romo-dropdown-max-height') === undefined) {
164
- romoSelectDropdownElem.attr('data-romo-dropdown-max-height', 'detect');
141
+ var romoSelectDropdownElem = Romo.elems('<div class="romo-select romo-btn" tabindex="0"><span class="romo-select-text"></span></div>')[0];
142
+
143
+ Romo.setData(romoSelectDropdownElem, 'romo-dropdown-overflow-x', 'hidden');
144
+ Romo.setData(romoSelectDropdownElem, 'romo-dropdown-width', 'elem');
145
+
146
+ if (Romo.data(this.elem, 'romo-select-dropdown-position') !== undefined) {
147
+ Romo.setData(romoSelectDropdownElem, 'romo-dropdown-position', Romo.data(this.elem, 'romo-select-dropdown-position'));
148
+ }
149
+ if (Romo.data(this.elem, 'romo-select-dropdown-style-class') !== undefined) {
150
+ Romo.setData(romoSelectDropdownElem, 'romo-dropdown-style-class', Romo.data(this.elem, 'romo-select-dropdown-style-class'));
151
+ }
152
+ if (Romo.data(this.elem, 'romo-select-dropdown-min-height') !== undefined) {
153
+ Romo.setData(romoSelectDropdownElem, 'romo-dropdown-min-height', Romo.data(this.elem, 'romo-select-dropdown-min-height'));
154
+ }
155
+ if (Romo.data(this.elem, 'romo-select-dropdown-max-height') !== undefined) {
156
+ Romo.setData(romoSelectDropdownElem, 'romo-dropdown-max-height', Romo.data(this.elem, 'romo-select-dropdown-max-height'));
157
+ }
158
+ if (Romo.data(this.elem, 'romo-select-dropdown-height') !== undefined) {
159
+ Romo.setData(romoSelectDropdownElem, 'romo-dropdown-height', Romo.data(this.elem, 'romo-select-dropdown-height'));
165
160
  }
166
- if (this.elem.data('romo-select-filter-placeholder') !== undefined) {
167
- romoSelectDropdownElem.attr('data-romo-select-dropdown-filter-placeholder', this.elem.data('romo-select-filter-placeholder'));
161
+ if (Romo.data(this.elem, 'romo-select-filter-placeholder') !== undefined) {
162
+ Romo.setData(romoSelectDropdownElem, 'romo-select-dropdown-filter-placeholder', Romo.data(this.elem, 'romo-select-filter-placeholder'));
168
163
  }
169
- if (this.elem.data('romo-select-filter-indicator') !== undefined) {
170
- romoSelectDropdownElem.attr('data-romo-select-dropdown-filter-indicator', this.elem.data('romo-select-filter-indicator'));
164
+ if (Romo.data(this.elem, 'romo-select-filter-indicator') !== undefined) {
165
+ Romo.setData(romoSelectDropdownElem, 'romo-select-dropdown-filter-indicator', Romo.data(this.elem, 'romo-select-filter-indicator'));
171
166
  }
172
- if (this.elem.data('romo-select-filter-indicator-width-px') !== undefined) {
173
- romoSelectDropdownElem.attr('data-romo-select-dropdown-filter-indicator-width-px', this.elem.data('romo-select-filter-indicator-width-px'));
167
+ if (Romo.data(this.elem, 'romo-select-filter-indicator-width-px') !== undefined) {
168
+ Romo.setData(romoSelectDropdownElem, 'romo-select-dropdown-filter-indicator-width-px', Romo.data(this.elem, 'romo-select-filter-indicator-width-px'));
174
169
  }
175
- if (this.elem.data('romo-select-no-filter') !== undefined) {
176
- romoSelectDropdownElem.attr('data-romo-select-dropdown-no-filter', this.elem.data('romo-select-no-filter'));
170
+ if (Romo.data(this.elem, 'romo-select-no-filter') !== undefined) {
171
+ Romo.setData(romoSelectDropdownElem, 'romo-select-dropdown-no-filter', Romo.data(this.elem, 'romo-select-no-filter'));
177
172
  }
178
- if (this.elem.data('romo-select-custom-option') !== undefined) {
179
- romoSelectDropdownElem.attr('data-romo-select-dropdown-custom-option', this.elem.data('romo-select-custom-option'));
173
+ if (Romo.data(this.elem, 'romo-select-custom-option') !== undefined) {
174
+ Romo.setData(romoSelectDropdownElem, 'romo-select-dropdown-custom-option', Romo.data(this.elem, 'romo-select-custom-option'));
180
175
  }
181
- if (this.elem.data('romo-select-custom-option-prompt') !== undefined) {
182
- romoSelectDropdownElem.attr('data-romo-select-dropdown-custom-option-prompt', this.elem.data('romo-select-custom-option-prompt'));
176
+ if (Romo.data(this.elem, 'romo-select-custom-option-prompt') !== undefined) {
177
+ Romo.setData(romoSelectDropdownElem, 'romo-select-dropdown-custom-option-prompt', Romo.data(this.elem, 'romo-select-custom-option-prompt'));
183
178
  }
184
- if (this.elem.data('romo-select-open-on-focus') !== undefined) {
185
- romoSelectDropdownElem.attr('data-romo-select-dropdown-open-on-focus', this.elem.data('romo-select-open-on-focus'));
179
+ if (Romo.data(this.elem, 'romo-select-open-on-focus') !== undefined) {
180
+ Romo.setData(romoSelectDropdownElem, 'romo-select-dropdown-open-on-focus', Romo.data(this.elem, 'romo-select-open-on-focus'));
186
181
  }
187
182
 
188
- var classList = this.elem.attr('class') !== undefined ? this.elem.attr('class').split(/\s+/) : [];
189
- $.each(classList, function(idx, classItem) {
190
- romoSelectDropdownElem.addClass(classItem);
191
- });
192
- if (this.elem.attr('style') !== undefined) {
193
- romoSelectDropdownElem.attr('style', this.elem.attr('style'));
183
+ if (Romo.data(romoSelectDropdownElem, 'romo-dropdown-max-height') === undefined) {
184
+ Romo.setData(romoSelectDropdownElem, 'romo-dropdown-max-height', 'detect');
185
+ }
186
+
187
+ if (Romo.attr(this.elem, 'class') !== undefined) {
188
+ Romo.addClass(romoSelectDropdownElem, Romo.attr(this.elem, 'class'));
189
+ }
190
+ if (Romo.attr(this.elem, 'style') !== undefined) {
191
+ Romo.setAttr(romoSelectDropdownElem, 'style', Romo.attr(this.elem, 'style'));
194
192
  }
195
- romoSelectDropdownElem.css({'width': this.elem.css('width')});
196
- if (this.elem.attr('disabled') !== undefined) {
197
- this.romoSelectDropdown.elem.attr('disabled', this.elem.attr('disabled'));
193
+ Romo.setStyle(romoSelectDropdownElem, 'width', Romo.css(this.elem, 'width'));
194
+ if (Romo.attr(this.elem, 'disabled') !== undefined) {
195
+ Romo.setAttr(this.romoSelectDropdown.elem, 'disabled', Romo.attr(this.elem, 'disabled'));
198
196
  }
199
197
 
200
- this.elem.after(romoSelectDropdownElem);
201
- this.elem.hide();
198
+ Romo.after(this.elem, romoSelectDropdownElem);
199
+ Romo.hide(this.elem);
202
200
 
203
- this.elemWrapper = $('<div class="romo-select-wrapper"></div>');
204
- if (this.elem.data('romo-select-btn-group') === true) {
205
- this.elemWrapper.addClass('romo-btn-group');
201
+ this.elemWrapper = Romo.elems('<div class="romo-select-wrapper"></div>')[0];
202
+ if (Romo.data(this.elem, 'romo-select-btn-group') === true) {
203
+ Romo.addClass(this.elemWrapper, 'romo-btn-group');
206
204
  }
207
- romoSelectDropdownElem.before(this.elemWrapper);
208
- this.elemWrapper.append(romoSelectDropdownElem);
209
-
210
- // the elem wrapper should be treated like a child elem. add it to Romo's
211
- // parent-child elems so it will be removed when the elem (select) is removed.
212
- // delay adding it b/c other components may `append` generated selects
213
- // meaning the select is removed and then re-added. if added immediately
214
- // the "remove" part will incorrectly remove the wrapper.
215
- setTimeout($.proxy(function() {
216
- Romo.parentChildElems.add(this.elem, [this.elemWrapper]);
217
- }, this), 1);
218
-
219
- this.caretElem = $();
220
- var caretClass = this.elem.data('romo-select-caret') || this.defaultCaretClass;
205
+ Romo.before(romoSelectDropdownElem, this.elemWrapper);
206
+ Romo.append(this.elemWrapper, romoSelectDropdownElem);
207
+ Romo.parentChildElems.add(this.elem, [this.elemWrapper]);
208
+
209
+ this.caretElem = undefined;
210
+ var caretClass = Romo.data(this.elem, 'romo-select-caret') || this.defaultCaretClass;
221
211
  if (caretClass !== undefined && caretClass !== 'none') {
222
- this.caretElem = $('<i class="romo-select-caret '+caretClass+'"></i>');
223
- this.caretElem.css('line-height', parseInt(Romo.getComputedStyle(romoSelectDropdownElem[0], "line-height"), 10)+'px');
224
- this.caretElem.on('click', $.proxy(this._onCaretClick, this));
225
- romoSelectDropdownElem.append(this.caretElem);
212
+ this.caretElem = Romo.elems('<i class="romo-select-caret '+caretClass+'"></i>')[0];
213
+ Romo.setStyle(this.caretElem, 'line-height', parseInt(Romo.css(romoSelectDropdownElem, "line-height"), 10)+'px');
214
+ Romo.on(this.caretElem, 'click', Romo.proxy(this._onCaretClick, this));
215
+ Romo.append(romoSelectDropdownElem, this.caretElem);
226
216
 
227
217
  var caretPaddingPx = this._getCaretPaddingPx();
228
218
  var caretWidthPx = this._getCaretWidthPx();
229
219
  var caretPosition = this._getCaretPosition();
230
220
 
231
221
  // add a pixel to account for the default input border
232
- this.caretElem.css(caretPosition, caretPaddingPx+1);
222
+ Romo.setStyle(this.caretElem, caretPosition, caretPaddingPx+1+'px');
233
223
 
234
224
  // left-side padding
235
225
  // + caret width
236
226
  // + right-side padding
237
227
  var dropdownPaddingPx = caretPaddingPx + caretWidthPx + caretPaddingPx;
238
- romoSelectDropdownElem.css('padding-'+caretPosition, dropdownPaddingPx+'px');
228
+ Romo.setStyle(romoSelectDropdownElem, 'padding-'+caretPosition, dropdownPaddingPx+'px');
239
229
  }
240
230
 
241
231
  return romoSelectDropdownElem;
@@ -250,72 +240,94 @@ RomoSelect.prototype._setValues = function(newValues) {
250
240
  var setValues = newValues.filter(function(value) {
251
241
  return currentValues.indexOf(value) === -1;
252
242
  });
253
- var unsetElems = unsetValues.reduce($.proxy(function(elems, value) {
254
- return elems.add(this.elem.find('OPTION[value="'+value+'"]'));
255
- }, this), $());
256
- var setElems = setValues.reduce($.proxy(function(elems, value) {
257
- return elems.add(this.elem.find('OPTION[value="'+value+'"]'));
258
- }, this), $());
259
-
260
- unsetElems.removeAttr('selected');
261
- unsetElems.prop('selected', false);
262
- setElems.attr('selected', 'selected');
263
- setElems.prop('selected', true);
243
+ var unsetElems = unsetValues.map(Romo.proxy(function(value) {
244
+ return Romo.find(this.elem, 'OPTION[value="'+value+'"]')[0];
245
+ }, this));
246
+ var setElems = setValues.map(Romo.proxy(function(value) {
247
+ return Romo.find(this.elem, 'OPTION[value="'+value+'"]')[0];
248
+ }, this));
249
+
250
+ unsetElems.forEach(Romo.proxy(function(unsetElem) {
251
+ Romo.rmAttr(unsetElem, 'selected');
252
+ unsetElem.selected = false;
253
+ }, this));
254
+ setElems.forEach(Romo.proxy(function(setElem) {
255
+ Romo.setAttr(setElem, 'selected', 'selected');
256
+ setElem.selected = true;
257
+ }, this));
264
258
  }
265
259
 
266
260
  RomoSelect.prototype._elemValues = function() {
267
- var selectedNodes = this.elem.find('OPTION[selected]').get();
268
- if (selectedNodes.length === 0 && this.romoSelectedOptionsList === undefined) {
261
+ var selectedOptElems = Romo.find(this.elem, 'OPTION[selected]');
262
+ if (selectedOptElems.length === 0 && this.romoSelectedOptionsList === undefined) {
269
263
  // if a non-multi select has no selected options, treat the first option as selected
270
- selectedNodes = [this.elem.find('OPTION')[0]];
264
+ var firstOptElem = Romo.find(this.elem, 'OPTION')[0];
265
+ if (firstOptElem !== undefined) {
266
+ selectedOptElems = [firstOptElem];
267
+ }
271
268
  }
272
- return selectedNodes.map(function(node) {
273
- return ($(node).attr('value') || '');
269
+ return selectedOptElems.map(function(selectedOptElem) {
270
+ return (Romo.attr(selectedOptElem, 'value') || '');
274
271
  });
275
272
  }
276
273
 
277
274
  RomoSelect.prototype._refreshUI = function() {
278
- var text = undefined;
275
+ var text = '';
279
276
  if (this.romoSelectedOptionsList !== undefined) {
280
- text = '';
281
277
  this.romoSelectedOptionsList.doRefreshUI();
282
- } else {
283
- text = this.elem.find('OPTION[value="'+this._elemValues()[0]+'"]').text().trim();
284
- }
285
- if (text === '') {
286
- text = '&nbsp;'
278
+ } else if (this._elemValues().length !== 0) {
279
+ var optionElem = Romo.find(this.elem, 'OPTION[value="'+this._elemValues()[0]+'"]')[0];
280
+ if (optionElem !== undefined) {
281
+ text = optionElem.innerText.trim();
282
+ }
287
283
  }
288
- this.romoSelectDropdown.elem.find('.romo-select-text').html(text);
289
- }
290
284
 
291
- RomoSelect.prototype._onCaretClick = function(e) {
292
- if (this.elem.prop('disabled') === false) {
293
- this.romoSelectDropdown.doFocus();
294
- this.elem.trigger('select:triggerPopupOpen');
285
+ var textElem = Romo.find(this.romoSelectDropdown.elem, '.romo-select-text')[0];
286
+ if (text === '') {
287
+ Romo.updateHtml(textElem, '<span>&nbsp;</span>');
288
+ } else {
289
+ Romo.updateText(textElem, text);
295
290
  }
296
291
  }
297
292
 
298
293
  RomoSelect.prototype._getCaretPaddingPx = function() {
299
294
  return (
300
- this.elem.data('romo-select-caret-padding-px') ||
295
+ Romo.data(this.elem, 'romo-select-caret-padding-px') ||
301
296
  this.defaultCaretPaddingPx
302
297
  );
303
298
  }
304
299
 
305
300
  RomoSelect.prototype._getCaretWidthPx = function() {
306
301
  return (
307
- this.elem.data('romo-select-caret-width-px') ||
308
- parseInt(Romo.getComputedStyle(this.caretElem[0], "width"), 10)
302
+ Romo.data(this.elem, 'romo-select-caret-width-px') ||
303
+ this._parseCaretWidthPx()
309
304
  );
310
305
  }
311
306
 
312
307
  RomoSelect.prototype._getCaretPosition = function() {
313
308
  return (
314
- this.elem.data('romo-select-caret-position') ||
309
+ Romo.data(this.elem, 'romo-select-caret-position') ||
315
310
  this.defaultCaretPosition
316
311
  );
317
312
  }
318
313
 
319
- Romo.onInitUI(function(e) {
320
- Romo.initUIElems(e, '[data-romo-select-auto="true"]').romoSelect();
321
- });
314
+ RomoSelect.prototype._parseCaretWidthPx = function() {
315
+ var widthPx = parseInt(Romo.css(this.caretElem, "width"), 10);
316
+ if (isNaN(widthPx)) {
317
+ widthPx = this.defaultCaretWidthPx;
318
+ }
319
+ return widthPx;
320
+ }
321
+
322
+ // event functions
323
+
324
+ RomoSelect.prototype.romoEvFn._onCaretClick = function(e) {
325
+ if (this.elem.disabled === false) {
326
+ this.romoSelectDropdown.doFocus();
327
+ Romo.trigger(this.elem, 'romoSelect:triggerPopupOpen');
328
+ }
329
+ }
330
+
331
+ // init
332
+
333
+ Romo.addElemsInitSelector('[data-romo-select-auto="true"]', RomoSelect);