romo 0.19.3 → 0.19.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/assets/css/romo/_mixins.scss +2 -2
- data/assets/css/romo/forms.scss +72 -19
- data/assets/css/romo/picker.scss +47 -0
- data/assets/css/romo/select.scss +1 -51
- data/assets/js/romo/indicator.js +40 -25
- data/assets/js/romo/indicator_text_input.js +48 -31
- data/assets/js/romo/option_list_dropdown.js +532 -0
- data/assets/js/romo/picker.js +287 -0
- data/assets/js/romo/select.js +45 -39
- data/assets/js/romo/select_dropdown.js +98 -375
- data/lib/romo/dassets.rb +4 -1
- data/lib/romo/version.rb +1 -1
- data/test/unit/dassets_tests.rb +4 -1
- metadata +5 -2
@@ -0,0 +1,532 @@
|
|
1
|
+
$.fn.romoOptionListDropdown = function() {
|
2
|
+
return $.map(this, function(element) {
|
3
|
+
return new RomoOptionListDropdown(element);
|
4
|
+
});
|
5
|
+
}
|
6
|
+
|
7
|
+
var RomoOptionListDropdown = function(element) {
|
8
|
+
this.elem = $(element);
|
9
|
+
this.prevValue = '';
|
10
|
+
|
11
|
+
var selCustomization = this.elem.data('romo-option-list-dropdown-item-selector-customization') || '';
|
12
|
+
this.itemSelector = 'LI[data-romo-option-list-dropdown-item="opt"]:not(.disabled)'+selCustomization;
|
13
|
+
this.focusStyleClass = this.elem.data('romo-option-list-focus-style-class');
|
14
|
+
|
15
|
+
this.doInit();
|
16
|
+
this._bindElem();
|
17
|
+
|
18
|
+
this.elem.trigger('romoOptionListDropdown:ready', [this]);
|
19
|
+
}
|
20
|
+
|
21
|
+
RomoOptionListDropdown.prototype.bodyElem = function() {
|
22
|
+
return this.romoDropdown.bodyElem;
|
23
|
+
}
|
24
|
+
|
25
|
+
RomoOptionListDropdown.prototype.popupElem = function() {
|
26
|
+
return this.romoDropdown.popupElem;
|
27
|
+
}
|
28
|
+
|
29
|
+
RomoOptionListDropdown.prototype.selectedItemElem = function() {
|
30
|
+
return this.romoDropdown.bodyElem.find('LI.selected');
|
31
|
+
}
|
32
|
+
|
33
|
+
RomoOptionListDropdown.prototype.selectedItemValue = function() {
|
34
|
+
// need to use `attr` so it will always read from the DOM
|
35
|
+
// using `data` works the first time but does some elem caching or something
|
36
|
+
// so it won't work subsequent times.
|
37
|
+
return this.elem.attr('data-romo-option-list-dropdown-selected-value');
|
38
|
+
}
|
39
|
+
|
40
|
+
RomoOptionListDropdown.prototype.selectedItemText = function() {
|
41
|
+
// need to use `attr` so it will always read from the DOM
|
42
|
+
// using `data` works the first time but does some elem caching or something
|
43
|
+
// so it won't work subsequent times.
|
44
|
+
return this.elem.attr('data-romo-option-list-dropdown-selected-text');
|
45
|
+
}
|
46
|
+
|
47
|
+
RomoOptionListDropdown.prototype.optItemElems = function() {
|
48
|
+
return this.romoDropdown.bodyElem.find('LI[data-romo-option-list-dropdown-item="opt"]');
|
49
|
+
}
|
50
|
+
|
51
|
+
RomoOptionListDropdown.prototype.optgroupItemElems = function() {
|
52
|
+
return this.romoDropdown.bodyElem.find('LI[data-romo-option-list-dropdown-item="optgroup"]');
|
53
|
+
}
|
54
|
+
|
55
|
+
RomoOptionListDropdown.prototype.doInit = function() {
|
56
|
+
// override as needed
|
57
|
+
}
|
58
|
+
|
59
|
+
RomoOptionListDropdown.prototype.doSetNewValue = function(newValue) {
|
60
|
+
this.selectedItemElem().removeClass('selected');
|
61
|
+
this.romoDropdown.bodyElem.find(
|
62
|
+
'LI[data-romo-option-list-dropdown-option-value="'+newValue+'"]'
|
63
|
+
).addClass('selected');
|
64
|
+
this.doSetSelectedValueAndText(
|
65
|
+
newValue,
|
66
|
+
this.selectedItemElem().data('romo-option-list-dropdown-option-display-text')
|
67
|
+
);
|
68
|
+
}
|
69
|
+
|
70
|
+
RomoOptionListDropdown.prototype.doSetSelectedValueAndText = function(newValue, newText) {
|
71
|
+
// need to use `attr` to persist selected values to the DOM for back button logic
|
72
|
+
// to work. using `data` won't persist changes to DOM and breaks back button logic.
|
73
|
+
this.elem.attr('data-romo-option-list-dropdown-selected-value', newValue);
|
74
|
+
this.elem.attr('data-romo-option-list-dropdown-selected-text', newText);
|
75
|
+
|
76
|
+
this.prevValue = newValue;
|
77
|
+
}
|
78
|
+
|
79
|
+
/*
|
80
|
+
Options are specified as a list of items. Each 'option' item object
|
81
|
+
has either display text or html, a value, and can optionally be
|
82
|
+
selected or disabled. Each 'optgroup' item object has a label and
|
83
|
+
a list of items.
|
84
|
+
|
85
|
+
Example:
|
86
|
+
[ { 'type': 'option', 'value': 'a', 'displayText': 'A', 'displayHtml': 'A' },
|
87
|
+
{ 'type': 'option', 'value': 'b', 'displayText': 'B', 'displayHtml': 'B', 'selected': true },
|
88
|
+
{ 'type': 'option', 'value': 'c', 'displayText': 'C', 'displayHtml': 'C', 'disabled': true },
|
89
|
+
{ 'type': 'optgroup', 'label': 'Numbers', 'items': [
|
90
|
+
{ 'type': 'option', 'value': '1', 'displayText': '1', 'displayHtml': '<span>1</span>' },
|
91
|
+
{ 'type': 'option', 'value': '2', 'displayText': '2', 'displayHtml': '<span>2</span>' },
|
92
|
+
{ 'type': 'option', 'value': '3', 'displayText': '3', 'displayHtml': '<span>3</span>' }
|
93
|
+
] },
|
94
|
+
{ 'type': 'optgroup', 'label': 'Symbols', 'items': [
|
95
|
+
{ 'type': 'option', 'value': 'exclamation', 'displayText': '!', 'displayHtml': '<span>!</span>' },
|
96
|
+
{ 'type': 'option', 'value': 'at', 'displayText': '@', 'displayHtml': '<span>@</span>' },
|
97
|
+
{ 'type': 'option', 'value': 'pound', 'displayText': '#', 'displayHtml': '<span>#</span>' }
|
98
|
+
] }
|
99
|
+
]
|
100
|
+
*/
|
101
|
+
|
102
|
+
RomoOptionListDropdown.prototype.doSetListItems = function(itemsList) {
|
103
|
+
this.optionListContainer.html(this._buildListElem(itemsList));
|
104
|
+
|
105
|
+
this._updateOptionsListUI();
|
106
|
+
|
107
|
+
this.optionListContainer.find(this.itemSelector).on('mouseenter', $.proxy(this._onItemEnter, this));
|
108
|
+
this.optionListContainer.find(this.itemSelector).on('click', $.proxy(this._onItemClick, this));
|
109
|
+
}
|
110
|
+
|
111
|
+
/* private */
|
112
|
+
|
113
|
+
RomoOptionListDropdown.prototype._bindElem = function() {
|
114
|
+
this.elem.on('keydown', $.proxy(this._onElemKeyDown, this));
|
115
|
+
this.elem.on('dropdown:popupOpen', $.proxy(this._onPopupOpen, this));
|
116
|
+
this.elem.on('dropdown:popupClose', $.proxy(this._onPopupClose, this));
|
117
|
+
|
118
|
+
this.elem.on('dropdown:toggle', $.proxy(function(e, dropdown) {
|
119
|
+
this.elem.trigger('romoOptionListDropdown:dropdown:toggle', [dropdown, this]);
|
120
|
+
}, this));
|
121
|
+
this.elem.on('dropdown:popupOpen', $.proxy(function(e, dropdown) {
|
122
|
+
this.elem.trigger('romoOptionListDropdown:dropdown:popupOpen', [dropdown, this]);
|
123
|
+
}, this));
|
124
|
+
this.elem.on('dropdown:popupClose', $.proxy(function(e, dropdown) {
|
125
|
+
this.elem.trigger('romoOptionListDropdown:dropdown:popupClose', [dropdown, this]);
|
126
|
+
}, this));
|
127
|
+
|
128
|
+
this.elem.on('romoOptionListDropdown:triggerListOptionsUpdate', $.proxy(function(e, highlightOptionElem) {
|
129
|
+
this._updateOptionsListUI(highlightOptionElem);
|
130
|
+
}, this));
|
131
|
+
|
132
|
+
this.elem.on('romoOptionListDropdown:triggerToggle', $.proxy(function(e) {
|
133
|
+
this.elem.trigger('dropdown:triggerToggle', []);
|
134
|
+
}, this));
|
135
|
+
this.elem.on('romoOptionListDropdown:triggerPopupOpen', $.proxy(function(e) {
|
136
|
+
this.elem.trigger('dropdown:triggerPopupOpen', []);
|
137
|
+
}, this));
|
138
|
+
this.elem.on('romoOptionListDropdown:triggerPopupClose', $.proxy(function(e) {
|
139
|
+
this.elem.trigger('dropdown:triggerPopupClose', []);
|
140
|
+
}, this));
|
141
|
+
|
142
|
+
this.elem.on('romoOptionListDropdown:triggerFilterIndicatorStart', $.proxy(function(e) {
|
143
|
+
this.optionFilterElem.trigger(
|
144
|
+
'indicatorTextInput:triggerIndicatorStart',
|
145
|
+
[Romo.getComputedStyle(this.optionFilterElem[0], "height")]
|
146
|
+
);
|
147
|
+
}, this));
|
148
|
+
this.elem.on('romoOptionListDropdown:triggerFilterIndicatorStop', $.proxy(function(e) {
|
149
|
+
this.optionFilterElem.trigger('indicatorTextInput:triggerIndicatorStop', []);
|
150
|
+
}, this));
|
151
|
+
|
152
|
+
this.romoDropdown = this.elem.romoDropdown()[0];
|
153
|
+
this.romoDropdown.doSetPopupZIndex(this.elem);
|
154
|
+
|
155
|
+
this.romoDropdown.popupElem.on('keydown', $.proxy(this._onElemKeyDown, this));
|
156
|
+
this.romoDropdown.popupElem.on('mousedown', $.proxy(this._onPopupMouseDown, this));
|
157
|
+
this.romoDropdown.popupElem.on('mouseup', $.proxy(this._onPopupMouseUp, this));
|
158
|
+
|
159
|
+
this.romoDropdown.bodyElem.addClass('romo-input-option-list');
|
160
|
+
this.romoDropdown.bodyElem.html('');
|
161
|
+
|
162
|
+
if (this.elem.data('romo-option-list-dropdown-no-filter') !== true) {
|
163
|
+
this.optionFilterElem = this._buildOptionFilter();
|
164
|
+
var optionFilterWrapperElem = $('<div class="romo-option-list-dropdown-filter-wrapper"></div>');
|
165
|
+
optionFilterWrapperElem.append(this.optionFilterElem);
|
166
|
+
this.romoDropdown.popupElem.prepend(optionFilterWrapperElem);
|
167
|
+
this._bindDropdownOptionFilter();
|
168
|
+
}
|
169
|
+
|
170
|
+
this.romoDropdown.bodyElem.append($('<div class="romo-option-list-dropdown-container"></div>'));
|
171
|
+
this.optionListContainer = this.romoDropdown.bodyElem.find('.romo-option-list-dropdown-container');
|
172
|
+
|
173
|
+
this.doSetListItems([]);
|
174
|
+
}
|
175
|
+
|
176
|
+
RomoOptionListDropdown.prototype._buildListElem = function(itemsList, listClass) {
|
177
|
+
var listElem = $('<ul></ul>');
|
178
|
+
|
179
|
+
listElem.addClass(listClass);
|
180
|
+
$.each(itemsList, $.proxy(function(idx, item) {
|
181
|
+
if (item.type === 'option') {
|
182
|
+
listElem.append(this._buildListOptionElem(item));
|
183
|
+
} else if (item.type === 'optgroup') {
|
184
|
+
listElem.append(this._buildListOptGroupElem(item));
|
185
|
+
listElem.append(this._buildListElem(item.items, 'romo-option-list-optgroup'));
|
186
|
+
}
|
187
|
+
}, this));
|
188
|
+
|
189
|
+
return listElem;
|
190
|
+
}
|
191
|
+
|
192
|
+
RomoOptionListDropdown.prototype._buildListOptionElem = function(item) {
|
193
|
+
var itemElem = $('<li data-romo-option-list-dropdown-item="opt"></li>');
|
194
|
+
var value = item.value || '';
|
195
|
+
var displayText = item.displayText || '';
|
196
|
+
var displayHtml = item.displayHtml || item.displayText || ' '
|
197
|
+
|
198
|
+
itemElem.attr('data-romo-option-list-dropdown-option-value', value);
|
199
|
+
itemElem.attr('data-romo-option-list-dropdown-option-display-text', displayText);
|
200
|
+
itemElem.html(displayHtml);
|
201
|
+
|
202
|
+
if (item.selected === true) {
|
203
|
+
itemElem.addClass('selected');
|
204
|
+
this.prevValue = value; // the last option marked selected is used
|
205
|
+
}
|
206
|
+
if (item.disabled === true) {
|
207
|
+
itemElem.addClass('disabled');
|
208
|
+
}
|
209
|
+
|
210
|
+
return itemElem;
|
211
|
+
}
|
212
|
+
|
213
|
+
RomoOptionListDropdown.prototype._buildListOptGroupElemItem = function(item) {
|
214
|
+
var itemElem = $('<li data-romo-option-list-dropdown-item="optgroup"></li>');
|
215
|
+
|
216
|
+
itemElem.text(item.label);
|
217
|
+
|
218
|
+
return itemElem;
|
219
|
+
}
|
220
|
+
|
221
|
+
RomoOptionListDropdown.prototype._buildOptionFilter = function() {
|
222
|
+
var filter = $('<input type="text" size="1" class="romo-option-list-dropdown-filter"></input>');
|
223
|
+
|
224
|
+
if (this.elem.data('romo-option-list-dropdown-filter-placeholder') !== undefined) {
|
225
|
+
filter.attr('placeholder', this.elem.data('romo-option-list-dropdown-filter-placeholder'));
|
226
|
+
}
|
227
|
+
filter.attr('data-romo-indicator-text-input-elem-display', "block");
|
228
|
+
filter.attr('data-romo-indicator-text-input-indicator-position', "right");
|
229
|
+
if (this.elem.data('romo-option-list-dropdown-filter-indicator') !== undefined) {
|
230
|
+
filter.attr('data-romo-indicator-text-input-indicator', this.elem.data('romo-option-list-dropdown-filter-indicator'));
|
231
|
+
}
|
232
|
+
if (this.elem.data('romo-option-list-dropdown-filter-indicator-width-px') !== undefined) {
|
233
|
+
filter.attr('data-romo-indicator-text-input-indicator-width-px', this.elem.data('romo-option-list-dropdown-filter-indicator-width-px'));
|
234
|
+
}
|
235
|
+
filter.attr('data-romo-form-disable-enter-submit', "true");
|
236
|
+
filter.attr('data-romo-onkey-on', "keydown");
|
237
|
+
|
238
|
+
filter.attr('autocomplete', 'off');
|
239
|
+
|
240
|
+
return filter;
|
241
|
+
}
|
242
|
+
|
243
|
+
RomoOptionListDropdown.prototype._bindDropdownOptionFilter = function() {
|
244
|
+
this.optionFilterElem.romoIndicatorTextInput();
|
245
|
+
this.optionFilterElem.romoOnkey();
|
246
|
+
|
247
|
+
this.romoDropdown.elem.on('focus', $.proxy(function(e) {
|
248
|
+
if (this.blurTimeoutId !== undefined) {
|
249
|
+
clearTimeout(this.blurTimeoutId);
|
250
|
+
}
|
251
|
+
// remove any manual elem focus when elem is actually focused
|
252
|
+
this.optionFilterFocused = false;
|
253
|
+
this.romoDropdown.elem.removeClass(this.focusStyleClass);
|
254
|
+
}, this));
|
255
|
+
this.romoDropdown.elem.on('blur', $.proxy(function(e) {
|
256
|
+
if (this.blurTimeoutId !== undefined) {
|
257
|
+
clearTimeout(this.blurTimeoutId);
|
258
|
+
}
|
259
|
+
// close the dropdown when elem is blurred
|
260
|
+
// remove any manual focus as well
|
261
|
+
this.romoDropdown.elem.removeClass(this.focusStyleClass);
|
262
|
+
this.blurTimeoutId = setTimeout($.proxy(function() {
|
263
|
+
if (this.popupMouseDown !== true && this.optionFilterFocused !== true) {
|
264
|
+
this.romoDropdown.elem.trigger('dropdown:triggerPopupClose', []);
|
265
|
+
}
|
266
|
+
}, this), 10);
|
267
|
+
}, this));
|
268
|
+
this.optionFilterElem.on('focus', $.proxy(function(e) {
|
269
|
+
if (this.blurTimeoutId !== undefined) {
|
270
|
+
clearTimeout(this.blurTimeoutId);
|
271
|
+
}
|
272
|
+
// manually make the elem focused when its filter is focused
|
273
|
+
this.optionFilterFocused = true;
|
274
|
+
this.romoDropdown.elem.addClass(this.focusStyleClass);
|
275
|
+
}, this));
|
276
|
+
this.optionFilterElem.on('blur', $.proxy(function(e) {
|
277
|
+
// remove any manual elem focus when its filter is blurred
|
278
|
+
this.optionFilterFocused = false;
|
279
|
+
this.romoDropdown.elem.removeClass(this.focusStyleClass);
|
280
|
+
}, this));
|
281
|
+
|
282
|
+
this.romoDropdown.elem.on('dropdown:popupOpen', $.proxy(function(e, dropdown) {
|
283
|
+
this.optionFilterElem.trigger('indicatorTextInput:triggerPlaceIndicator');
|
284
|
+
this.optionFilterElem.focus();
|
285
|
+
this._filterOptionElems();
|
286
|
+
}, this));
|
287
|
+
this.romoDropdown.elem.on('dropdown:popupClose', $.proxy(function(e, dropdown) {
|
288
|
+
this.optionFilterElem.val('');
|
289
|
+
/*
|
290
|
+
don't call `_filterOptionElems()` here. we need to keep the option markup as is
|
291
|
+
until the popup is opened again so selecting an option works. selecting an option
|
292
|
+
depends on the selected item elem method which requires the markup to be in place
|
293
|
+
*/
|
294
|
+
}, this));
|
295
|
+
this.romoDropdown.elem.on('dropdown:popupClosedByEsc', $.proxy(function(e, dropdown) {
|
296
|
+
this.romoDropdown.elem.focus();
|
297
|
+
}, this));
|
298
|
+
this.optionFilterElem.on('click', $.proxy(function(e) {
|
299
|
+
if (e !== undefined) {
|
300
|
+
e.stopPropagation();
|
301
|
+
}
|
302
|
+
}, this));
|
303
|
+
this.romoDropdown.popupElem.on('click', $.proxy(function(e) {
|
304
|
+
this.optionFilterElem.focus();
|
305
|
+
}, this));
|
306
|
+
|
307
|
+
this.onkeySearchTimeout = undefined;
|
308
|
+
this.onkeySearchDelay = 100; // 0.1 secs, want it to be really responsive
|
309
|
+
|
310
|
+
this.optionFilterElem.on('onkey:trigger', $.proxy(function(e, triggerEvent, onkey) {
|
311
|
+
// TODO: incorp this timeout logic into the onkey component so don't have to repeat it
|
312
|
+
clearTimeout(this.onkeySearchTimeout);
|
313
|
+
this.onkeySearchTimeout = setTimeout($.proxy(function() {
|
314
|
+
if (Romo.nonInputTextKeyCodes().indexOf(triggerEvent.keyCode) === -1 /* Input Text */) {
|
315
|
+
this._filterOptionElems();
|
316
|
+
}
|
317
|
+
}, this), this.onkeySearchDelay);
|
318
|
+
}, this));
|
319
|
+
}
|
320
|
+
|
321
|
+
RomoOptionListDropdown.prototype._filterOptionElems = function() {
|
322
|
+
this.elem.trigger('romoOptionListDropdown:filterChange', [this.optionFilterElem.val(), this]);
|
323
|
+
}
|
324
|
+
|
325
|
+
RomoOptionListDropdown.prototype._updateOptionsListUI = function(highlightOptionElem) {
|
326
|
+
this.romoDropdown.doPlacePopupElem();
|
327
|
+
if (highlightOptionElem !== undefined) {
|
328
|
+
this._highlightItem(highlightOptionElem);
|
329
|
+
this._scrollTopToItem(highlightOptionElem);
|
330
|
+
} else {
|
331
|
+
this._highlightItem(this.selectedItemElem());
|
332
|
+
this._scrollTopToItem(this.selectedItemElem());
|
333
|
+
}
|
334
|
+
}
|
335
|
+
|
336
|
+
RomoOptionListDropdown.prototype._selectHighlightedItem = function() {
|
337
|
+
var curr = this._getHighlightedItem();
|
338
|
+
if (curr.length !== 0) {
|
339
|
+
var prevValue = this.prevValue;
|
340
|
+
var newValue = curr.data('romo-option-list-dropdown-option-value');
|
341
|
+
|
342
|
+
this.romoDropdown.doPopupClose();
|
343
|
+
this.elem.trigger('romoOptionListDropdown:itemSelected', [newValue, prevValue, this]);
|
344
|
+
|
345
|
+
if (newValue !== prevValue) {
|
346
|
+
this.doSetNewValue(newValue);
|
347
|
+
this.elem.trigger('romoOptionListDropdown:change', [newValue, prevValue, this]);
|
348
|
+
}
|
349
|
+
}
|
350
|
+
}
|
351
|
+
|
352
|
+
RomoOptionListDropdown.prototype._onPopupOpen = function(e) {
|
353
|
+
if (this.elem.hasClass('disabled') === false) {
|
354
|
+
this._highlightItem(this.selectedItemElem());
|
355
|
+
this._scrollTopToItem(this.selectedItemElem());
|
356
|
+
}
|
357
|
+
$('body').on('keydown', $.proxy(this._onPopupOpenBodyKeyDown, this));
|
358
|
+
}
|
359
|
+
|
360
|
+
RomoOptionListDropdown.prototype._onPopupClose = function(e) {
|
361
|
+
this._highlightItem($());
|
362
|
+
$('body').off('keydown', $.proxy(this._onPopupOpenBodyKeyDown, this));
|
363
|
+
}
|
364
|
+
|
365
|
+
RomoOptionListDropdown.prototype._onItemEnter = function(e) {
|
366
|
+
if (e !== undefined) {
|
367
|
+
e.preventDefault();
|
368
|
+
e.stopPropagation();
|
369
|
+
}
|
370
|
+
this._highlightItem($(e.target));
|
371
|
+
}
|
372
|
+
|
373
|
+
RomoOptionListDropdown.prototype._onItemClick = function(e) {
|
374
|
+
if (this.blurTimeoutId !== undefined) {
|
375
|
+
clearTimeout(this.blurTimeoutId);
|
376
|
+
this.blurTimeoutId = undefined;
|
377
|
+
}
|
378
|
+
if (e !== undefined) {
|
379
|
+
e.preventDefault();
|
380
|
+
e.stopPropagation();
|
381
|
+
}
|
382
|
+
this._selectHighlightedItem();
|
383
|
+
}
|
384
|
+
|
385
|
+
RomoOptionListDropdown.prototype._onPopupMouseDown = function(e) {
|
386
|
+
this.popupMouseDown = true;
|
387
|
+
}
|
388
|
+
|
389
|
+
RomoOptionListDropdown.prototype._onPopupMouseUp = function(e) {
|
390
|
+
this.popupMouseDown = false;
|
391
|
+
}
|
392
|
+
|
393
|
+
RomoOptionListDropdown.prototype._onPopupOpenBodyKeyDown = function(e) {
|
394
|
+
if (e !== undefined) {
|
395
|
+
e.stopPropagation();
|
396
|
+
}
|
397
|
+
|
398
|
+
var scroll = this.romoDropdown.bodyElem;
|
399
|
+
|
400
|
+
if (e.keyCode === 38 /* Up */) {
|
401
|
+
var prev = this._prevListItem();
|
402
|
+
|
403
|
+
this._highlightItem(prev);
|
404
|
+
if (scroll.offset().top > prev.offset().top) {
|
405
|
+
this._scrollTopToItem(prev);
|
406
|
+
} else if ((scroll.offset().top + scroll.height()) < prev.offset().top) {
|
407
|
+
this._scrollTopToItem(prev);
|
408
|
+
}
|
409
|
+
|
410
|
+
return false;
|
411
|
+
} else if(e.keyCode === 40 /* Down */) {
|
412
|
+
var next = this._nextListItem();
|
413
|
+
|
414
|
+
this._highlightItem(next);
|
415
|
+
if ((scroll.offset().top + scroll.height()) < next.offset().top + next.height()) {
|
416
|
+
this._scrollBottomToItem(next);
|
417
|
+
} else if (scroll.offset().top > next.offset().top) {
|
418
|
+
this._scrollTopToItem(next);
|
419
|
+
}
|
420
|
+
|
421
|
+
return false;
|
422
|
+
} else if (e.keyCode === 13 /* Enter */ ) {
|
423
|
+
this._selectHighlightedItem();
|
424
|
+
return false;
|
425
|
+
} else if (e.keyCode === 9 /* Tab */ ) {
|
426
|
+
e.preventDefault();
|
427
|
+
return false;
|
428
|
+
} else {
|
429
|
+
return true;
|
430
|
+
}
|
431
|
+
}
|
432
|
+
|
433
|
+
RomoOptionListDropdown.prototype._onElemKeyDown = function(e) {
|
434
|
+
if (this.elem.hasClass('disabled') === false) {
|
435
|
+
if (this.romoDropdown.popupElem.hasClass('romo-dropdown-open') === false) {
|
436
|
+
if (e.keyCode === 40 /* Down */ || e.keyCode === 38 /* Up */) {
|
437
|
+
this.romoDropdown.doPopupOpen();
|
438
|
+
return false;
|
439
|
+
} else if (this.optionFilterElem !== undefined &&
|
440
|
+
Romo.nonInputTextKeyCodes().indexOf(e.keyCode) === -1 /* Input Text */) {
|
441
|
+
if (e.metaKey === false) {
|
442
|
+
// don't prevent default on Cmd-* keys (preserve Cmd-R refresh, etc)
|
443
|
+
e.preventDefault();
|
444
|
+
this.optionFilterElem.val(e.key);
|
445
|
+
this.romoDropdown.doPopupOpen();
|
446
|
+
}
|
447
|
+
e.stopPropagation();
|
448
|
+
return true;
|
449
|
+
} else {
|
450
|
+
return true;
|
451
|
+
}
|
452
|
+
}
|
453
|
+
}
|
454
|
+
return true;
|
455
|
+
}
|
456
|
+
|
457
|
+
RomoOptionListDropdown.prototype._scrollTopToItem = function(item) {
|
458
|
+
if (item.size() > 0) {
|
459
|
+
var scroll = this.romoDropdown.bodyElem;
|
460
|
+
scroll.scrollTop(0);
|
461
|
+
|
462
|
+
var scrollOffsetTop = scroll.offset().top;
|
463
|
+
var selOffsetTop = item.offset().top;
|
464
|
+
var selOffset = item.height() / 2;
|
465
|
+
|
466
|
+
scroll.scrollTop(selOffsetTop - scrollOffsetTop - selOffset);
|
467
|
+
}
|
468
|
+
}
|
469
|
+
|
470
|
+
RomoOptionListDropdown.prototype._scrollBottomToItem = function(item) {
|
471
|
+
if (item.size() > 0) {
|
472
|
+
var scroll = this.romoDropdown.bodyElem;
|
473
|
+
scroll.scrollTop(0);
|
474
|
+
|
475
|
+
var scrollOffsetTop = scroll.offset().top;
|
476
|
+
var selOffsetTop = item.offset().top;
|
477
|
+
var selOffset = scroll[0].offsetHeight - item.height();
|
478
|
+
|
479
|
+
scroll.scrollTop(selOffsetTop - scrollOffsetTop - selOffset);
|
480
|
+
}
|
481
|
+
}
|
482
|
+
|
483
|
+
RomoOptionListDropdown.prototype._nextListItem = function() {
|
484
|
+
var curr = this._getHighlightedItem();
|
485
|
+
if (curr.length === 0) {
|
486
|
+
return curr;
|
487
|
+
}
|
488
|
+
var currList = curr.closest('UL');
|
489
|
+
var next = Romo.selectNext(curr, this.itemSelector);
|
490
|
+
|
491
|
+
while (next.length === 0) {
|
492
|
+
currList = Romo.selectNext(currList, 'UL');
|
493
|
+
if (currList.length !== 0) {
|
494
|
+
next = currList.find(this.itemSelector).first();
|
495
|
+
} else {
|
496
|
+
next = this.romoDropdown.bodyElem.find(this.itemSelector).first();
|
497
|
+
}
|
498
|
+
}
|
499
|
+
return next;
|
500
|
+
}
|
501
|
+
|
502
|
+
RomoOptionListDropdown.prototype._prevListItem = function() {
|
503
|
+
var curr = this._getHighlightedItem();
|
504
|
+
if (curr.length === 0) {
|
505
|
+
return curr;
|
506
|
+
}
|
507
|
+
var currList = curr.closest('UL');
|
508
|
+
var prev = Romo.selectPrev(curr, this.itemSelector);
|
509
|
+
|
510
|
+
while (prev.length === 0) {
|
511
|
+
currList = Romo.selectPrev(currList, 'UL');
|
512
|
+
if (currList.length !== 0) {
|
513
|
+
prev = currList.find(this.itemSelector).last();
|
514
|
+
} else {
|
515
|
+
prev = this.romoDropdown.bodyElem.find(this.itemSelector).last();
|
516
|
+
}
|
517
|
+
}
|
518
|
+
return prev;
|
519
|
+
}
|
520
|
+
|
521
|
+
RomoOptionListDropdown.prototype._highlightItem = function(item) {
|
522
|
+
this._getHighlightedItem().removeClass('romo-option-list-dropdown-highlight');
|
523
|
+
item.addClass('romo-option-list-dropdown-highlight');
|
524
|
+
}
|
525
|
+
|
526
|
+
RomoOptionListDropdown.prototype._getHighlightedItem = function() {
|
527
|
+
return this.romoDropdown.bodyElem.find('LI.romo-option-list-dropdown-highlight');
|
528
|
+
}
|
529
|
+
|
530
|
+
Romo.onInitUI(function(e) {
|
531
|
+
Romo.initUIElems(e, '[data-romo-option-list-dropdown-auto="true"]').romoOptionListDropdown();
|
532
|
+
});
|