romo 0.19.10 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,9 @@
1
- $.fn.romoPicker = function() {
2
- return $.map(this, function(element) {
3
- return new RomoPicker(element);
4
- });
5
- }
6
-
7
- var RomoPicker = function(element) {
8
- this.elem = $(element);
1
+ var RomoPicker = 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
  this.defaultValuesDelim = ',';
14
9
 
@@ -18,51 +13,23 @@ var RomoPicker = function(element) {
18
13
  this.doInit();
19
14
  this._bindElem();
20
15
 
21
- this.doSetValue(this._elemValues());
22
-
23
- if (this.elem.attr('id') !== undefined) {
24
- $('label[for="'+this.elem.attr('id')+'"]').on('click', $.proxy(function(e) {
25
- this.romoOptionListDropdown.doFocus();
26
- }, this));
27
- }
28
-
29
- $(window).on("pageshow", $.proxy(function(e) {
30
- this._refreshUI();
31
- }, this));
32
-
33
- this.elem.on('romoPicker:triggerSetValue', $.proxy(function(e, value) {
34
- this.doSetValue(value)
35
- }, this));
36
-
37
- this.elem.trigger('romoPicker:ready', [this]);
38
- }
39
-
40
- RomoPicker.prototype.doInit = function() {
41
- // override as needed
42
- }
16
+ Romo.trigger(this.elem, 'romoPicker:ready', [this]);
17
+ });
43
18
 
44
19
  RomoPicker.prototype.doSetValue = function(values) {
45
- var value = undefined;
46
- if (Array.isArray(values)) {
47
- value = values.join(this._elemValuesDelim());
48
- } else {
49
- value = values;
50
- }
51
- $.ajax({
20
+ var value = Romo.array(values).join(this._elemValuesDelim());
21
+ Romo.ajax({
52
22
  type: 'GET',
53
- url: this.elem.data('romo-picker-url'),
23
+ url: Romo.data(this.elem, 'romo-picker-url'),
54
24
  data: { 'values': value },
55
- success: $.proxy(function(data, status, xhr) { this.doSetValueDatas(data); }, this),
25
+ success: Romo.proxy(function(data, status, xhr) {
26
+ this.doSetValueDatas(JSON.parse(data));
27
+ }, this),
56
28
  });
57
29
  }
58
30
 
59
31
  RomoPicker.prototype.doSetValueDatas = function(valueDatas) {
60
- var datas = undefined;
61
- if (Array.isArray(valueDatas)) {
62
- datas = valueDatas;
63
- } else {
64
- datas = [valueDatas];
65
- }
32
+ var datas = Romo.array(valueDatas);
66
33
  var values = datas.map(function(data) { return data.value; });
67
34
  var displayTexts = datas.map(function(data) { return data.displayText; });
68
35
 
@@ -71,7 +38,7 @@ RomoPicker.prototype.doSetValueDatas = function(valueDatas) {
71
38
  this.romoSelectedOptionsList.doSetItems(datas);
72
39
  } else {
73
40
  var displayText = displayTexts[0] ||
74
- this.elem.data('romo-picker-empty-option-display-text') ||
41
+ Romo.data(this.elem, 'romo-picker-empty-option-display-text') ||
75
42
  '';
76
43
  this._setValuesAndDisplayText(values, displayText);
77
44
  this.romoOptionListDropdown.doSetSelectedValueAndText(
@@ -82,38 +49,56 @@ RomoPicker.prototype.doSetValueDatas = function(valueDatas) {
82
49
  this._refreshUI();
83
50
  }
84
51
 
85
- /* private */
52
+ // private
86
53
 
87
54
  RomoPicker.prototype._bindElem = function() {
88
55
  this._bindOptionListDropdown();
89
56
  this._bindSelectedOptionsList();
90
57
  this._bindAjax();
91
58
 
92
- this.elem.on('romoPicker:triggerToggle', $.proxy(function(e) {
93
- this.romoOptionListDropdown.elem.trigger('romoOptionListDropdown:triggerToggle', []);
59
+ Romo.on(this.elem, 'romoPicker:triggerToggle', Romo.proxy(function(e) {
60
+ Romo.trigger(this.romoOptionListDropdown.elem, 'romoOptionListDropdown:triggerToggle', []);
94
61
  }, this));
95
- this.elem.on('romoPicker:triggerPopupOpen', $.proxy(function(e) {
96
- this.romoOptionListDropdown.elem.trigger('romoOptionListDropdown:triggerPopupOpen', []);
62
+ Romo.on(this.elem, 'romoPicker:triggerPopupOpen', Romo.proxy(function(e) {
63
+ Romo.trigger(this.romoOptionListDropdown.elem, 'romoOptionListDropdown:triggerPopupOpen', []);
97
64
  }, this));
98
- this.elem.on('romoPicker:triggerPopupClose', $.proxy(function(e) {
99
- this.romoOptionListDropdown.elem.trigger('romoOptionListDropdown:triggerPopupClose', []);
65
+ Romo.on(this.elem, 'romoPicker:triggerPopupClose', Romo.proxy(function(e) {
66
+ Romo.trigger(this.romoOptionListDropdown.elem, 'romoOptionListDropdown:triggerPopupClose', []);
100
67
  }, this));
101
68
 
102
69
  this.romoOptionListDropdown.doSetListItems(this.defaultOptionItems);
70
+
71
+ this.doSetValue(this._elemValues());
72
+
73
+ if (Romo.attr(this.elem, 'id') !== undefined) {
74
+ var labelElem = Romo.f('label[for="'+Romo.attr(this.elem, 'id')+'"]');
75
+ Romo.on(labelElem, 'click', Romo.proxy(function(e) {
76
+ e.preventDefault();
77
+ this.romoOptionListDropdown.doFocus();
78
+ }, this));
79
+ }
80
+
81
+ Romo.on(window, "pageshow", Romo.proxy(function(e) {
82
+ this._refreshUI();
83
+ }, this));
84
+
85
+ Romo.on(this.elem, 'romoPicker:triggerSetValue', Romo.proxy(function(e, value) {
86
+ this.doSetValue(value)
87
+ }, this));
103
88
  }
104
89
 
105
90
  RomoPicker.prototype._bindSelectedOptionsList = function() {
106
91
  this.romoSelectedOptionsList = undefined;
107
- if (this.elem.prop('multiple') === true) {
108
- if (this.elem.data('romo-picker-multiple-item-class') !== undefined) {
109
- this.romoOptionListDropdown.elem.attr('data-romo-selected-options-list-item-class', this.elem.data('romo-picker-multiple-item-class'));
92
+ if (this.elem.multiple === true) {
93
+ if (Romo.data(this.elem, 'romo-picker-multiple-item-class') !== undefined) {
94
+ Romo.setData(this.romoOptionListDropdown.elem, 'romo-selected-options-list-item-class', Romo.data(this.elem, 'romo-picker-multiple-item-class'));
110
95
  }
111
- if (this.elem.data('romo-picker-multiple-max-rows') !== undefined) {
112
- this.romoOptionListDropdown.elem.attr('data-romo-selected-options-list-max-rows', this.elem.data('romo-picker-multiple-max-rows'));
96
+ if (Romo.data(this.elem, 'romo-picker-multiple-max-rows') !== undefined) {
97
+ Romo.setData(this.romoOptionListDropdown.elem, 'romo-selected-options-list-max-rows', Romo.data(this.elem, 'romo-picker-multiple-max-rows'));
113
98
  }
114
99
 
115
100
  this.romoSelectedOptionsList = new RomoSelectedOptionsList(this.romoOptionListDropdown.elem);
116
- this.romoSelectedOptionsList.elem.on('romoSelectedOptionsList:itemClick', $.proxy(function(e, itemValue, romoSelectedOptionsList) {
101
+ Romo.on(this.romoSelectedOptionsList.elem, 'romoSelectedOptionsList:itemClick', Romo.proxy(function(e, itemValue, romoSelectedOptionsList) {
117
102
  var currentValues = this._elemValues();
118
103
  var index = currentValues.indexOf(itemValue);
119
104
  if (index > -1) {
@@ -123,45 +108,47 @@ RomoPicker.prototype._bindSelectedOptionsList = function() {
123
108
  this.romoSelectedOptionsList.doRemoveItem(itemValue);
124
109
  this._refreshUI();
125
110
  }, this));
126
- this.romoSelectedOptionsList.elem.on('romoSelectedOptionsList:listClick', $.proxy(function(e, romoSelectedOptionsList) {
127
- this.romoOptionListDropdown.elem.trigger('dropdown:triggerPopupClose', []);
111
+ Romo.on(this.romoSelectedOptionsList.elem, 'romoSelectedOptionsList:listClick', Romo.proxy(function(e, romoSelectedOptionsList) {
112
+ Romo.trigger(this.romoOptionListDropdown.elem, 'romoDropdown:triggerPopupClose', []);
128
113
  this.romoOptionListDropdown.doFocus(false);
129
114
  }, this));
130
115
 
131
- this.elemWrapper.before(this.romoSelectedOptionsList.elem);
116
+ Romo.before(this.elemWrapper, this.romoSelectedOptionsList.elem);
132
117
  this.romoSelectedOptionsList.doRefreshUI();
133
118
  }
134
119
  }
135
120
 
136
121
  RomoPicker.prototype._bindOptionListDropdown = function() {
137
- this.romoOptionListDropdown = this._buildOptionListDropdownElem().romoOptionListDropdown(this.elem)[0];
122
+ this.romoOptionListDropdown = new RomoOptionListDropdown(
123
+ this._buildOptionListDropdownElem()
124
+ );
138
125
 
139
- this.romoOptionListDropdown.elem.on('romoOptionListDropdown:dropdown:toggle', $.proxy(function(e, dropdown, optionListDropdown) {
140
- this.elem.trigger('romoPicker:dropdown:toggle', [dropdown, this]);
126
+ Romo.on(this.romoOptionListDropdown.elem, 'romoOptionListDropdown:romoDropdown:toggle', Romo.proxy(function(e, romoDropdown, optionListDropdown) {
127
+ Romo.trigger(this.elem, 'romoPicker:romoDropdown:toggle', [romoDropdown, this]);
141
128
  }, this));
142
- this.romoOptionListDropdown.elem.on('romoOptionListDropdown:dropdown:popupOpen', $.proxy(function(e, dropdown, optionListDropdown) {
143
- this.elem.trigger('romoPicker:dropdown:popupOpen', [dropdown, this]);
129
+ Romo.on(this.romoOptionListDropdown.elem, 'romoOptionListDropdown:romoDropdown:popupOpen', Romo.proxy(function(e, romoDropdown, optionListDropdown) {
130
+ Romo.trigger(this.elem, 'romoPicker:romoDropdown:popupOpen', [romoDropdown, this]);
144
131
  }, this));
145
- this.romoOptionListDropdown.elem.on('romoOptionListDropdown:dropdown:popupClose', $.proxy(function(e, dropdown, optionListDropdown) {
146
- this.elem.trigger('romoPicker:dropdown:popupClose', [dropdown, this]);
132
+ Romo.on(this.romoOptionListDropdown.elem, 'romoOptionListDropdown:romoDropdown:popupClose', Romo.proxy(function(e, romoDropdown, optionListDropdown) {
133
+ Romo.trigger(this.elem, 'romoPicker:romoDropdown:popupClose', [romoDropdown, this]);
147
134
  }, this));
148
135
 
149
- this.romoOptionListDropdown.elem.on('romoOptionListDropdown:filterChange', $.proxy(function(e, filterValue, romoOptionListDropdown) {
136
+ Romo.on(this.romoOptionListDropdown.elem, 'romoOptionListDropdown:filterChange', Romo.proxy(function(e, filterValue, romoOptionListDropdown) {
150
137
  if (filterValue !== '') {
151
138
  // immediately update the custom opt as the filter changes
152
139
  // but keep the current filtered option items
153
140
  this._setListItems(this.filteredOptionItems.concat(this._buildCustomOptionItems()));
154
141
  // this will update with the new filtered items plus the custom on ajax callback
155
- this.elem.trigger('romoAjax:triggerInvoke', [{ 'filter': filterValue }]);
142
+ Romo.trigger(this.elem, 'romoAjax:triggerInvoke', [{ 'filter': filterValue }]);
156
143
  } else {
157
144
  this._setListItems(this.defaultOptionItems.concat(this._buildCustomOptionItems()));
158
145
  }
159
146
  }, this));
160
- this.romoOptionListDropdown.elem.on('romoOptionListDropdown:itemSelected', $.proxy(function(e, itemValue, itemDisplayText, optionListDropdown) {
147
+ Romo.on(this.romoOptionListDropdown.elem, 'romoOptionListDropdown:itemSelected', Romo.proxy(function(e, itemValue, itemDisplayText, optionListDropdown) {
161
148
  this.romoOptionListDropdown.doFocus();
162
- this.elem.trigger('romoPicker:itemSelected', [itemValue, itemDisplayText, this]);
149
+ Romo.trigger(this.elem, 'romoPicker:itemSelected', [itemValue, itemDisplayText, this]);
163
150
  }, this));
164
- this.romoOptionListDropdown.elem.on('romoOptionListDropdown:newItemSelected', $.proxy(function(e, itemValue, itemDisplayText, optionListDropdown) {
151
+ Romo.on(this.romoOptionListDropdown.elem, 'romoOptionListDropdown:newItemSelected', Romo.proxy(function(e, itemValue, itemDisplayText, optionListDropdown) {
165
152
  if (this.romoSelectedOptionsList !== undefined) {
166
153
  var currentValues = this._elemValues();
167
154
  if (!currentValues.includes(itemValue)) {
@@ -175,139 +162,141 @@ RomoPicker.prototype._bindOptionListDropdown = function() {
175
162
  this._setValuesAndDisplayText([itemValue], itemDisplayText);
176
163
  }
177
164
  this._refreshUI();
178
- this.elem.trigger('romoPicker:newItemSelected', [itemValue, itemDisplayText, this]);
165
+ Romo.trigger(this.elem, 'romoPicker:newItemSelected', [itemValue, itemDisplayText, this]);
179
166
  }, this));
180
- this.romoOptionListDropdown.elem.on('romoOptionListDropdown:change', $.proxy(function(e, newValue, prevValue, optionListDropdown) {
181
- this.elem.trigger('change');
182
- this.elem.trigger('romoPicker:change', [newValue, prevValue, this]);
167
+ Romo.on(this.romoOptionListDropdown.elem, 'romoOptionListDropdown:change', Romo.proxy(function(e, newValue, prevValue, optionListDropdown) {
168
+ Romo.trigger(this.elem, 'change');
169
+ Romo.trigger(this.elem, 'romoPicker:change', [newValue, prevValue, this]);
183
170
  }, this));
184
171
  }
185
172
 
186
173
  RomoPicker.prototype._buildOptionListDropdownElem = function() {
187
- var romoOptionListDropdownElem = $('<div class="romo-picker romo-btn" tabindex="0"><span class="romo-picker-text"></span></div>');
188
-
189
- romoOptionListDropdownElem.attr('data-romo-option-list-focus-style-class', 'romo-picker-focus');
190
-
191
- romoOptionListDropdownElem.attr('data-romo-dropdown-position', this.elem.data('romo-picker-dropdown-position'));
192
- romoOptionListDropdownElem.attr('data-romo-dropdown-style-class', this.elem.data('romo-picker-dropdown-style-class'));
193
- romoOptionListDropdownElem.attr('data-romo-dropdown-min-height', this.elem.data('romo-picker-dropdown-min-height'));
194
- romoOptionListDropdownElem.attr('data-romo-dropdown-max-height', this.elem.data('romo-picker-dropdown-max-height'));
195
- romoOptionListDropdownElem.attr('data-romo-dropdown-height', this.elem.data('romo-picker-dropdown-height'));
196
- romoOptionListDropdownElem.attr('data-romo-dropdown-overflow-x', 'hidden');
197
- romoOptionListDropdownElem.attr('data-romo-dropdown-width', 'elem');
198
- if (romoOptionListDropdownElem.data('romo-dropdown-max-height') === undefined) {
199
- romoOptionListDropdownElem.attr('data-romo-dropdown-max-height', 'detect');
174
+ var romoOptionListDropdownElem = Romo.elems('<div class="romo-picker romo-btn" tabindex="0"><span class="romo-picker-text"></span></div>')[0];
175
+
176
+ Romo.setData(romoOptionListDropdownElem, 'romo-dropdown-overflow-x', 'hidden');
177
+ Romo.setData(romoOptionListDropdownElem, 'romo-dropdown-width', 'elem');
178
+ Romo.setData(romoOptionListDropdownElem, 'romo-option-list-focus-style-class', 'romo-picker-focus');
179
+
180
+ if (Romo.data(this.elem, 'romo-picker-dropdown-position') !== undefined) {
181
+ Romo.setData(romoOptionListDropdownElem, 'romo-dropdown-position', Romo.data(this.elem, 'romo-picker-dropdown-position'));
182
+ }
183
+ if (Romo.data(this.elem, 'romo-picker-dropdown-style-class') !== undefined) {
184
+ Romo.setData(romoOptionListDropdownElem, 'romo-dropdown-style-class', Romo.data(this.elem, 'romo-picker-dropdown-style-class'));
185
+ }
186
+ if (Romo.data(this.elem, 'romo-picker-dropdown-min-height') !== undefined) {
187
+ Romo.setData(romoOptionListDropdownElem, 'romo-dropdown-min-height', Romo.data(this.elem, 'romo-picker-dropdown-min-height'));
200
188
  }
201
- if (this.elem.data('romo-picker-filter-placeholder') !== undefined) {
202
- romoOptionListDropdownElem.attr('data-romo-option-list-dropdown-filter-placeholder', this.elem.data('romo-picker-filter-placeholder'));
189
+ if (Romo.data(this.elem, 'romo-picker-dropdown-max-height') !== undefined) {
190
+ Romo.setData(romoOptionListDropdownElem, 'romo-dropdown-max-height', Romo.data(this.elem, 'romo-picker-dropdown-max-height'));
203
191
  }
204
- if (this.elem.data('romo-picker-filter-indicator') !== undefined) {
205
- romoOptionListDropdownElem.attr('data-romo-option-list-dropdown-filter-indicator', this.elem.data('romo-picker-filter-indicator'));
192
+ if (Romo.data(this.elem, 'romo-picker-dropdown-height') !== undefined) {
193
+ Romo.setData(romoOptionListDropdownElem, 'romo-dropdown-height', Romo.data(this.elem, 'romo-picker-dropdown-height'));
206
194
  }
207
- if (this.elem.data('romo-picker-filter-indicator-width-px') !== undefined) {
208
- romoOptionListDropdownElem.attr('data-romo-option-list-filter-indicator-width-px', this.elem.data('romo-picker-filter-indicator-width-px'));
195
+ if (Romo.data(this.elem, 'romo-picker-filter-placeholder') !== undefined) {
196
+ Romo.setData(romoOptionListDropdownElem, 'romo-option-list-dropdown-filter-placeholder', Romo.data(this.elem, 'romo-picker-filter-placeholder'));
209
197
  }
210
- if (this.elem.data('romo-picker-no-filter') !== undefined) {
211
- romoOptionListDropdownElem.attr('data-romo-option-list-dropdown-no-filter', this.elem.data('romo-picker-no-filter'));
198
+ if (Romo.data(this.elem, 'romo-picker-filter-indicator') !== undefined) {
199
+ Romo.setData(romoOptionListDropdownElem, 'romo-option-list-dropdown-filter-indicator', Romo.data(this.elem, 'romo-picker-filter-indicator'));
212
200
  }
213
- if (this.elem.data('romo-picker-open-on-focus') !== undefined) {
214
- romoOptionListDropdownElem.attr('data-romo-option-list-dropdown-open-on-focus', this.elem.data('romo-picker-open-on-focus'));
201
+ if (Romo.data(this.elem, 'romo-picker-filter-indicator-width-px') !== undefined) {
202
+ Romo.setData(romoOptionListDropdownElem, 'romo-option-list-filter-indicator-width-px', Romo.data(this.elem, 'romo-picker-filter-indicator-width-px'));
203
+ }
204
+ if (Romo.data(this.elem, 'romo-picker-no-filter') !== undefined) {
205
+ Romo.setData(romoOptionListDropdownElem, 'romo-option-list-dropdown-no-filter', Romo.data(this.elem, 'romo-picker-no-filter'));
206
+ }
207
+ if (Romo.data(this.elem, 'romo-picker-open-on-focus') !== undefined) {
208
+ Romo.setData(romoOptionListDropdownElem, 'romo-option-list-dropdown-open-on-focus', Romo.data(this.elem, 'romo-picker-open-on-focus'));
215
209
  }
216
210
 
217
- var classList = this.elem.attr('class') !== undefined ? this.elem.attr('class').split(/\s+/) : [];
218
- $.each(classList, function(idx, classItem) {
219
- romoOptionListDropdownElem.addClass(classItem);
220
- });
221
- if (this.elem.attr('style') !== undefined) {
222
- romoOptionListDropdownElem.attr('style', this.elem.attr('style'));
211
+ if (Romo.data(romoOptionListDropdownElem, 'romo-dropdown-max-height') === undefined) {
212
+ Romo.setData(romoOptionListDropdownElem, 'romo-dropdown-max-height', 'detect');
213
+ }
214
+
215
+ if (Romo.attr(this.elem, 'class') !== undefined) {
216
+ Romo.addClass(romoOptionListDropdownElem, Romo.attr(this.elem, 'class'));
217
+ }
218
+ if (Romo.attr(this.elem, 'style') !== undefined) {
219
+ Romo.setAttr(romoOptionListDropdownElem, 'style', Romo.attr(this.elem, 'style'));
223
220
  }
224
- romoOptionListDropdownElem.css({'width': this.elem.css('width')});
225
- if (this.elem.attr('disabled') !== undefined) {
226
- this.romoOptionListDropdown.elem.attr('disabled', this.elem.attr('disabled'));
221
+ Romo.setStyle(romoOptionListDropdownElem, 'width', Romo.css(this.elem, 'width'));
222
+ if (Romo.attr(this.elem, 'disabled') !== undefined) {
223
+ Romo.setAttr(this.romoOptionListDropdown.elem, 'disabled', Romo.attr(this.elem, 'disabled'));
227
224
  }
228
225
 
229
- this.elem.after(romoOptionListDropdownElem);
230
- this.elem.hide();
226
+ Romo.after(this.elem, romoOptionListDropdownElem);
227
+ Romo.hide(this.elem);
231
228
 
232
- this.elemWrapper = $('<div class="romo-picker-wrapper"></div>');
233
- if (this.elem.data('romo-picker-btn-group') === true) {
234
- this.elemWrapper.addClass('romo-btn-group');
229
+ this.elemWrapper = Romo.elems('<div class="romo-picker-wrapper"></div>')[0];
230
+ if (Romo.data(this.elem, 'romo-picker-btn-group') === true) {
231
+ Romo.addClass(this.elemWrapper, 'romo-btn-group');
235
232
  }
236
- romoOptionListDropdownElem.before(this.elemWrapper);
237
- this.elemWrapper.append(romoOptionListDropdownElem);
238
-
239
- // the elem wrapper should be treated like a child elem. add it to Romo's
240
- // parent-child elems so it will be removed when the elem (picker input) is removed.
241
- // delay adding it b/c other components may `append` generated pickers
242
- // meaning the picker is removed and then re-added. if added immediately
243
- // the "remove" part will incorrectly remove the wrapper.
244
- setTimeout($.proxy(function() {
245
- Romo.parentChildElems.add(this.elem, [this.elemWrapper]);
246
- }, this), 1);
247
-
248
- this.caretElem = $();
249
- var caretClass = this.elem.data('romo-picker-caret') || this.defaultCaretClass;
233
+ Romo.before(romoOptionListDropdownElem, this.elemWrapper);
234
+ Romo.append(this.elemWrapper, romoOptionListDropdownElem);
235
+ Romo.parentChildElems.add(this.elem, [this.elemWrapper]);
236
+
237
+ this.caretElem = undefined;
238
+ var caretClass = Romo.data(this.elem, 'romo-picker-caret') || this.defaultCaretClass;
250
239
  if (caretClass !== undefined && caretClass !== 'none') {
251
- this.caretElem = $('<i class="romo-picker-caret '+caretClass+'"></i>');
252
- this.caretElem.css('line-height', parseInt(Romo.getComputedStyle(romoOptionListDropdownElem[0], "line-height"), 10)+'px');
253
- this.caretElem.on('click', $.proxy(this._onCaretClick, this));
254
- romoOptionListDropdownElem.append(this.caretElem);
240
+ this.caretElem = Romo.elems('<i class="romo-picker-caret '+caretClass+'"></i>')[0];
241
+ Romo.setStyle(this.caretElem, 'line-height', parseInt(Romo.css(romoOptionListDropdownElem, "line-height"), 10)+'px');
242
+ Romo.on(this.caretElem, 'click', Romo.proxy(this._onCaretClick, this));
243
+ Romo.append(romoOptionListDropdownElem, this.caretElem);
255
244
 
256
245
  var caretPaddingPx = this._getCaretPaddingPx();
257
246
  var caretWidthPx = this._getCaretWidthPx();
258
247
  var caretPosition = this._getCaretPosition();
259
248
 
260
249
  // add a pixel to account for the default input border
261
- this.caretElem.css(caretPosition, caretPaddingPx+1);
250
+ Romo.setStyle(this.caretElem, caretPosition, caretPaddingPx+1+'px');
262
251
 
263
252
  // left-side padding
264
253
  // + caret width
265
254
  // + right-side padding
266
255
  var dropdownPaddingPx = caretPaddingPx + caretWidthPx + caretPaddingPx;
267
- romoOptionListDropdownElem.css('padding-'+caretPosition, dropdownPaddingPx+'px');
256
+ Romo.setStyle(romoOptionListDropdownElem, 'padding-'+caretPosition, dropdownPaddingPx+'px');
268
257
  }
269
258
 
270
259
  return romoOptionListDropdownElem;
271
260
  }
272
261
 
273
262
  RomoPicker.prototype._bindAjax = function() {
274
- this.elem.attr('data-romo-ajax-disable-default-invoke-on', true);
275
- this.elem.attr('data-romo-ajax-url-attr', 'data-romo-picker-url');
276
- this.elem.attr('data-romo-ajax-auto', false);
263
+ Romo.setData(this.elem, 'romo-ajax-disable-default-invoke-on', true);
264
+ Romo.setData(this.elem, 'romo-ajax-url-attr', 'data-romo-picker-url');
265
+ Romo.setData(this.elem, 'romo-ajax-auto', false);
277
266
 
278
- this.elem.on('romoAjax:callStart', $.proxy(function(e, data, romoAjax) {
279
- this.romoOptionListDropdown.elem.trigger('romoOptionListDropdown:triggerFilterIndicatorStart', []);
267
+ Romo.on(this.elem, 'romoAjax:callStart', Romo.proxy(function(e, data, romoAjax) {
268
+ Romo.trigger(this.romoOptionListDropdown.elem, 'romoOptionListDropdown:triggerFilterSpinnerStart', []);
280
269
  return false;
281
270
  }, this));
282
- this.elem.on('romoAjax:callSuccess', $.proxy(function(e, data, romoAjax) {
283
- this.filteredOptionItems = data;
271
+ Romo.on(this.elem, 'romoAjax:callSuccess', Romo.proxy(function(e, data, romoAjax) {
272
+ this.filteredOptionItems = JSON.parse(data);
284
273
  this._setListItems(this.filteredOptionItems.concat(this._buildCustomOptionItems()));
285
- this.romoOptionListDropdown.elem.trigger('romoOptionListDropdown:triggerFilterIndicatorStop', []);
274
+ Romo.trigger(this.romoOptionListDropdown.elem, 'romoOptionListDropdown:triggerFilterSpinnerStop', []);
286
275
  return false;
287
276
  }, this));
288
- this.elem.on('romoAjax:callError', $.proxy(function(e, xhr, romoAjax) {
277
+ Romo.on(this.elem, 'romoAjax:callError', Romo.proxy(function(e, xhr, romoAjax) {
289
278
  this._setListItems(this.defaultOptionItems.concat(this._buildCustomOptionItems()));
290
- this.romoOptionListDropdown.elem.trigger('romoOptionListDropdown:triggerFilterIndicatorStop', []);
279
+ Romo.trigger(this.romoOptionListDropdown.elem, 'romoOptionListDropdown:triggerFilterSpinnerStop', []);
291
280
  return false;
292
281
  }, this));
293
282
 
294
- this.elem.romoAjax();
283
+ this.romoAjax = new RomoAjax(this.elem);
295
284
  }
296
285
 
297
286
  RomoPicker.prototype._setListItems = function(items) {
298
287
  this.romoOptionListDropdown.doSetListItems(items);
299
- this.romoOptionListDropdown.elem.trigger('romoOptionListDropdown:triggerListOptionsUpdate', [this.romoOptionListDropdown.optItemElems().first()]);
288
+ Romo.trigger(this.romoOptionListDropdown.elem, 'romoOptionListDropdown:triggerListOptionsUpdate', [this.romoOptionListDropdown.optItemElems()[0]]);
300
289
  }
301
290
 
302
291
  RomoPicker.prototype._buildDefaultOptionItems = function() {
303
292
  var items = []
304
293
 
305
- if (this.elem.data('romo-picker-empty-option') === true) {
294
+ if (Romo.data(this.elem, 'romo-picker-empty-option') === true) {
306
295
  items.push({
307
296
  'type': 'option',
308
297
  'value': '',
309
- 'displayText': (this.elem.data('romo-picker-empty-option-display-text') || ''),
310
- 'displayHtml': '&nbsp;'
298
+ 'displayText': (Romo.data(this.elem, 'romo-picker-empty-option-display-text') || ''),
299
+ 'displayHtml': '<span>&nbsp;</span>'
311
300
  });
312
301
  }
313
302
 
@@ -318,8 +307,8 @@ RomoPicker.prototype._buildCustomOptionItems = function() {
318
307
  var items = [];
319
308
 
320
309
  var value = this.romoOptionListDropdown.optionFilterValue();
321
- if (value !== '' && this.elem.data('romo-picker-custom-option') === true) {
322
- var prompt = this.elem.data('romo-picker-custom-option-prompt');
310
+ if (value !== '' && Romo.data(this.elem, 'romo-picker-custom-option') === true) {
311
+ var prompt = Romo.data(this.elem, 'romo-picker-custom-option-prompt');
323
312
  if (prompt !== undefined) {
324
313
  items.push({
325
314
  'type': 'optgroup',
@@ -344,65 +333,70 @@ RomoPicker.prototype._buildCustomOptionItem = function(value) {
344
333
  }
345
334
 
346
335
  RomoPicker.prototype._setValuesAndDisplayText = function(newValues, displayText) {
347
- this.elem[0].value = newValues.join(this._elemValuesDelim());
348
-
349
- // store the display text on the DOM to compliment the value being stored on the
350
- // DOM via the elem above. need to use `attr` to persist selected values to the
351
- // DOM for back button logic to work. using `data` won't persist changes to DOM
352
- // and breaks how the component deals with back-button behavior.
353
- this.elem.attr('data-romo-picker-display-text', displayText);
336
+ this.elem.value = newValues.join(this._elemValuesDelim());
337
+ Romo.setData(this.elem, 'romo-picker-display-text', displayText);
354
338
  }
355
339
 
356
340
  RomoPicker.prototype._elemValues = function() {
357
- return this.elem[0].value.split(this._elemValuesDelim()).filter(function(v){ return v !== ''; });
341
+ return this.elem.value.split(this._elemValuesDelim()).filter(function(v){ return v !== ''; });
358
342
  }
359
343
 
360
344
  RomoPicker.prototype._elemValuesDelim = function() {
361
- return this.elem.data('romo-picker-values-delim') || this.defaultValuesDelim;
345
+ return Romo.data(this.elem, 'romo-picker-values-delim') || this.defaultValuesDelim;
362
346
  }
363
347
 
364
348
  RomoPicker.prototype._refreshUI = function() {
365
- // need to use `attr` so it will always read from the DOM
366
- // using `data` works the first time but does some elem caching or something
367
- // so it won't work subsequent times.
368
- var text = this.elem.attr('data-romo-picker-display-text');
349
+ var text = Romo.data(this.elem, 'romo-picker-display-text') || '';
369
350
  if (this.romoSelectedOptionsList !== undefined) {
370
351
  this.romoSelectedOptionsList.doRefreshUI();
371
352
  }
372
- if (text === '') {
373
- text = '&nbsp;'
374
- }
375
- this.romoOptionListDropdown.elem.find('.romo-picker-text').html(text);
376
- }
377
353
 
378
- RomoPicker.prototype._onCaretClick = function(e) {
379
- if (this.elem.prop('disabled') === false) {
380
- this.romoOptionListDropdown.doFocus();
381
- this.elem.trigger('romoPicker:triggerPopupOpen');
354
+ var textElem = Romo.find(this.romoOptionListDropdown.elem, '.romo-picker-text')[0];
355
+ if (text === '') {
356
+ Romo.updateHtml(textElem, '<span>&nbsp;</span>');
357
+ } else {
358
+ Romo.updateText(textElem, text);
382
359
  }
383
360
  }
384
361
 
385
362
  RomoPicker.prototype._getCaretPaddingPx = function() {
386
363
  return (
387
- this.elem.data('romo-picker-caret-padding-px') ||
364
+ Romo.data(this.elem, 'romo-picker-caret-padding-px') ||
388
365
  this.defaultCaretPaddingPx
389
366
  );
390
367
  }
391
368
 
392
369
  RomoPicker.prototype._getCaretWidthPx = function() {
393
370
  return (
394
- this.elem.data('romo-picker-caret-width-px') ||
395
- parseInt(Romo.getComputedStyle(this.caretElem[0], "width"), 10)
371
+ Romo.data(this.elem, 'romo-picker-caret-width-px') ||
372
+ this._parseCaretWidthPx()
396
373
  );
397
374
  }
398
375
 
399
376
  RomoPicker.prototype._getCaretPosition = function() {
400
377
  return (
401
- this.elem.data('romo-picker-caret-position') ||
378
+ Romo.data(this.elem, 'romo-picker-caret-position') ||
402
379
  this.defaultCaretPosition
403
380
  );
404
381
  }
405
382
 
406
- Romo.onInitUI(function(e) {
407
- Romo.initUIElems(e, '[data-romo-picker-auto="true"]').romoPicker();
408
- });
383
+ RomoPicker.prototype._parseCaretWidthPx = function() {
384
+ var widthPx = parseInt(Romo.css(this.caretElem, "width"), 10);
385
+ if (isNaN(widthPx)) {
386
+ widthPx = this.defaultCaretWidthPx;
387
+ }
388
+ return widthPx;
389
+ }
390
+
391
+ // event functions
392
+
393
+ RomoPicker.prototype.romoEvFn._onCaretClick = function(e) {
394
+ if (this.elem.disabled === false) {
395
+ this.romoOptionListDropdown.doFocus();
396
+ Romo.trigger(this.elem, 'romoPicker:triggerPopupOpen');
397
+ }
398
+ }
399
+
400
+ // init
401
+
402
+ Romo.addElemsInitSelector('[data-romo-picker-auto="true"]', RomoPicker);