romo 0.19.10 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/assets/css/romo/buttons.scss +1 -0
- data/assets/css/romo/modal.scss +5 -0
- data/assets/js/romo/ajax.js +75 -89
- data/assets/js/romo/base.js +699 -274
- data/assets/js/romo/currency_text_input.js +93 -83
- data/assets/js/romo/date.js +3 -3
- data/assets/js/romo/datepicker.js +227 -234
- data/assets/js/romo/dropdown.js +235 -344
- data/assets/js/romo/dropdown_form.js +77 -76
- data/assets/js/romo/form.js +215 -159
- data/assets/js/romo/indicator_text_input.js +64 -95
- data/assets/js/romo/inline.js +66 -59
- data/assets/js/romo/inline_form.js +74 -73
- data/assets/js/romo/modal.js +218 -294
- data/assets/js/romo/modal_form.js +83 -82
- data/assets/js/romo/onkey.js +25 -22
- data/assets/js/romo/option_list_dropdown.js +318 -298
- data/assets/js/romo/picker.js +175 -181
- data/assets/js/romo/select.js +177 -165
- data/assets/js/romo/select_dropdown.js +86 -93
- data/assets/js/romo/selected_options_list.js +66 -76
- data/assets/js/romo/sortable.js +154 -120
- data/assets/js/romo/{indicator.js → spinner.js} +74 -89
- data/assets/js/romo/tooltip.js +257 -271
- data/assets/js/romo/word_boundary_filter.js +7 -10
- data/lib/romo/dassets.rb +1 -1
- data/lib/romo/version.rb +1 -1
- data/test/unit/dassets_tests.rb +1 -1
- metadata +3 -3
data/assets/js/romo/picker.js
CHANGED
@@ -1,14 +1,9 @@
|
|
1
|
-
|
2
|
-
|
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
|
-
|
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 =
|
46
|
-
|
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
|
23
|
+
url: Romo.data(this.elem, 'romo-picker-url'),
|
54
24
|
data: { 'values': value },
|
55
|
-
success:
|
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
|
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
|
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
|
-
|
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
|
93
|
-
this.romoOptionListDropdown.elem
|
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
|
96
|
-
this.romoOptionListDropdown.elem
|
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
|
99
|
-
this.romoOptionListDropdown.elem
|
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.
|
108
|
-
if (this.elem
|
109
|
-
this.romoOptionListDropdown.elem
|
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
|
112
|
-
this.romoOptionListDropdown.elem
|
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
|
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
|
127
|
-
this.romoOptionListDropdown.elem
|
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
|
-
|
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 =
|
122
|
+
this.romoOptionListDropdown = new RomoOptionListDropdown(
|
123
|
+
this._buildOptionListDropdownElem()
|
124
|
+
);
|
138
125
|
|
139
|
-
this.romoOptionListDropdown.elem
|
140
|
-
this.elem
|
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
|
143
|
-
this.elem
|
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
|
146
|
-
this.elem
|
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
|
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
|
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
|
147
|
+
Romo.on(this.romoOptionListDropdown.elem, 'romoOptionListDropdown:itemSelected', Romo.proxy(function(e, itemValue, itemDisplayText, optionListDropdown) {
|
161
148
|
this.romoOptionListDropdown.doFocus();
|
162
|
-
this.elem
|
149
|
+
Romo.trigger(this.elem, 'romoPicker:itemSelected', [itemValue, itemDisplayText, this]);
|
163
150
|
}, this));
|
164
|
-
this.romoOptionListDropdown.elem
|
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
|
165
|
+
Romo.trigger(this.elem, 'romoPicker:newItemSelected', [itemValue, itemDisplayText, this]);
|
179
166
|
}, this));
|
180
|
-
this.romoOptionListDropdown.elem
|
181
|
-
this.elem
|
182
|
-
this.elem
|
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 =
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
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
|
202
|
-
|
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
|
205
|
-
|
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
|
208
|
-
|
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
|
211
|
-
|
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
|
214
|
-
|
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
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
if (this.elem
|
222
|
-
romoOptionListDropdownElem.attr(
|
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
|
-
|
225
|
-
if (this.elem
|
226
|
-
this.romoOptionListDropdown.elem
|
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
|
230
|
-
this.elem
|
226
|
+
Romo.after(this.elem, romoOptionListDropdownElem);
|
227
|
+
Romo.hide(this.elem);
|
231
228
|
|
232
|
-
this.elemWrapper =
|
233
|
-
if (this.elem
|
234
|
-
this.elemWrapper
|
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
|
-
|
237
|
-
this.elemWrapper
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
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 =
|
252
|
-
this.caretElem
|
253
|
-
this.caretElem
|
254
|
-
|
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
|
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
|
-
|
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
|
275
|
-
this.elem
|
276
|
-
this.elem
|
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
|
279
|
-
this.romoOptionListDropdown.elem
|
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
|
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
|
274
|
+
Romo.trigger(this.romoOptionListDropdown.elem, 'romoOptionListDropdown:triggerFilterSpinnerStop', []);
|
286
275
|
return false;
|
287
276
|
}, this));
|
288
|
-
this.elem
|
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
|
279
|
+
Romo.trigger(this.romoOptionListDropdown.elem, 'romoOptionListDropdown:triggerFilterSpinnerStop', []);
|
291
280
|
return false;
|
292
281
|
}, this));
|
293
282
|
|
294
|
-
this.
|
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
|
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
|
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
|
310
|
-
'displayHtml': '
|
298
|
+
'displayText': (Romo.data(this.elem, 'romo-picker-empty-option-display-text') || ''),
|
299
|
+
'displayHtml': '<span> </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
|
322
|
-
var prompt = this.elem
|
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
|
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
|
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
|
345
|
+
return Romo.data(this.elem, 'romo-picker-values-delim') || this.defaultValuesDelim;
|
362
346
|
}
|
363
347
|
|
364
348
|
RomoPicker.prototype._refreshUI = function() {
|
365
|
-
|
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 = ' '
|
374
|
-
}
|
375
|
-
this.romoOptionListDropdown.elem.find('.romo-picker-text').html(text);
|
376
|
-
}
|
377
353
|
|
378
|
-
|
379
|
-
if (
|
380
|
-
|
381
|
-
|
354
|
+
var textElem = Romo.find(this.romoOptionListDropdown.elem, '.romo-picker-text')[0];
|
355
|
+
if (text === '') {
|
356
|
+
Romo.updateHtml(textElem, '<span> </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
|
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
|
395
|
-
|
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
|
378
|
+
Romo.data(this.elem, 'romo-picker-caret-position') ||
|
402
379
|
this.defaultCaretPosition
|
403
380
|
);
|
404
381
|
}
|
405
382
|
|
406
|
-
|
407
|
-
Romo.
|
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);
|