romo 0.19.4 → 0.19.5
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/forms.scss +3 -2
- data/assets/js/romo/option_list_dropdown.js +79 -28
- data/assets/js/romo/picker.js +43 -5
- data/assets/js/romo/select.js +15 -0
- data/assets/js/romo/select_dropdown.js +60 -16
- data/lib/romo/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
SHA512:
|
3
|
-
metadata.gz: 05431cecaec71b465c4986bf8aa7df0e2a71c88a693c4d082f8937c0e562c351371e4dd45e945881297f2316a14498194969f712ceb6465cacc2532e03f78d7b
|
4
|
-
data.tar.gz: 85887b774157ab564966b5007f4f0f04c51140af7a3be6e792d01731793801a6177ffc2c20538fea6c6f63afcbd2f263e7d1789b0addd8344471f4da6180f28c
|
5
2
|
SHA1:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fc3f8ffd4150f3516e977cc2c65e3fd25862848
|
4
|
+
data.tar.gz: 792b1f359b813c11cb40a595e23cd36aadd7f6e6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 112164a4224eb8e7ac852de31606510b95ae4a52063ab9ccb40598e458955b72bcba9d991671f1d649adc770162059b74bc7a3cc25a0ea039a3e134cfb1e618d
|
7
|
+
data.tar.gz: e513bd994b174937fb9c6c5d3aa15c6c03a78020447705ec54c145bfad17ea67b6e5cd2093b6b47e5a614ba05bd84a79558064b98b5dfd26816b239ddd0cd565
|
data/assets/css/romo/forms.scss
CHANGED
@@ -342,12 +342,13 @@
|
|
342
342
|
padding-left: $spacingSize1;
|
343
343
|
}
|
344
344
|
|
345
|
-
.romo-input-option-list LI {
|
345
|
+
.romo-input-option-list LI[data-romo-option-list-dropdown-item="opt"] {
|
346
346
|
@include input-option-list-option;
|
347
347
|
}
|
348
348
|
|
349
|
-
.romo-input-option-list LI[data-romo-option-list-item="optgroup"] {
|
349
|
+
.romo-input-option-list LI[data-romo-option-list-dropdown-item="optgroup"] {
|
350
350
|
@include input-option-list-optgroup;
|
351
|
+
padding: 0 $spacingSize0;
|
351
352
|
}
|
352
353
|
|
353
354
|
.romo-input-option-list LI.romo-option-list-dropdown-highlight {
|
@@ -5,12 +5,15 @@ $.fn.romoOptionListDropdown = function() {
|
|
5
5
|
}
|
6
6
|
|
7
7
|
var RomoOptionListDropdown = function(element) {
|
8
|
-
this.elem
|
9
|
-
|
8
|
+
this.elem = $(element);
|
9
|
+
|
10
|
+
this.prevValue = '';
|
11
|
+
this.optionListItems = [];
|
10
12
|
|
11
13
|
var selCustomization = this.elem.data('romo-option-list-dropdown-item-selector-customization') || '';
|
12
14
|
this.itemSelector = 'LI[data-romo-option-list-dropdown-item="opt"]:not(.disabled)'+selCustomization;
|
13
15
|
this.focusStyleClass = this.elem.data('romo-option-list-focus-style-class');
|
16
|
+
this.openOnFocus = this.elem.data('romo-option-list-dropdown-open-on-focus');
|
14
17
|
|
15
18
|
this.doInit();
|
16
19
|
this._bindElem();
|
@@ -44,6 +47,10 @@ RomoOptionListDropdown.prototype.selectedItemText = function() {
|
|
44
47
|
return this.elem.attr('data-romo-option-list-dropdown-selected-text');
|
45
48
|
}
|
46
49
|
|
50
|
+
RomoOptionListDropdown.prototype.optionFilterValue = function() {
|
51
|
+
return this.optionFilterElem.val();
|
52
|
+
}
|
53
|
+
|
47
54
|
RomoOptionListDropdown.prototype.optItemElems = function() {
|
48
55
|
return this.romoDropdown.bodyElem.find('LI[data-romo-option-list-dropdown-item="opt"]');
|
49
56
|
}
|
@@ -80,7 +87,8 @@ RomoOptionListDropdown.prototype.doSetSelectedValueAndText = function(newValue,
|
|
80
87
|
Options are specified as a list of items. Each 'option' item object
|
81
88
|
has either display text or html, a value, and can optionally be
|
82
89
|
selected or disabled. Each 'optgroup' item object has a label and
|
83
|
-
a list of items.
|
90
|
+
a list of items. Option groups cannot contain other option groups in
|
91
|
+
their items.
|
84
92
|
|
85
93
|
Example:
|
86
94
|
[ { 'type': 'option', 'value': 'a', 'displayText': 'A', 'displayHtml': 'A' },
|
@@ -100,6 +108,7 @@ Example:
|
|
100
108
|
*/
|
101
109
|
|
102
110
|
RomoOptionListDropdown.prototype.doSetListItems = function(itemsList) {
|
111
|
+
this.optionListItems = itemsList;
|
103
112
|
this.optionListContainer.html(this._buildListElem(itemsList));
|
104
113
|
|
105
114
|
this._updateOptionsListUI();
|
@@ -210,7 +219,7 @@ RomoOptionListDropdown.prototype._buildListOptionElem = function(item) {
|
|
210
219
|
return itemElem;
|
211
220
|
}
|
212
221
|
|
213
|
-
RomoOptionListDropdown.prototype.
|
222
|
+
RomoOptionListDropdown.prototype._buildListOptGroupElem = function(item) {
|
214
223
|
var itemElem = $('<li data-romo-option-list-dropdown-item="optgroup"></li>');
|
215
224
|
|
216
225
|
itemElem.text(item.label);
|
@@ -251,6 +260,12 @@ RomoOptionListDropdown.prototype._bindDropdownOptionFilter = function() {
|
|
251
260
|
// remove any manual elem focus when elem is actually focused
|
252
261
|
this.optionFilterFocused = false;
|
253
262
|
this.romoDropdown.elem.removeClass(this.focusStyleClass);
|
263
|
+
|
264
|
+
if (this.openOnFocus === true) {
|
265
|
+
this.romoDropdown.elem.trigger('dropdown:triggerPopupOpen', []);
|
266
|
+
} else {
|
267
|
+
this.openOnFocus = this.elem.data('romo-option-list-dropdown-open-on-focus');
|
268
|
+
}
|
254
269
|
}, this));
|
255
270
|
this.romoDropdown.elem.on('blur', $.proxy(function(e) {
|
256
271
|
if (this.blurTimeoutId !== undefined) {
|
@@ -283,6 +298,7 @@ RomoOptionListDropdown.prototype._bindDropdownOptionFilter = function() {
|
|
283
298
|
this.optionFilterElem.trigger('indicatorTextInput:triggerPlaceIndicator');
|
284
299
|
this.optionFilterElem.focus();
|
285
300
|
this._filterOptionElems();
|
301
|
+
this.openOnFocus = false;
|
286
302
|
}, this));
|
287
303
|
this.romoDropdown.elem.on('dropdown:popupClose', $.proxy(function(e, dropdown) {
|
288
304
|
this.optionFilterElem.val('');
|
@@ -334,7 +350,7 @@ RomoOptionListDropdown.prototype._updateOptionsListUI = function(highlightOption
|
|
334
350
|
}
|
335
351
|
|
336
352
|
RomoOptionListDropdown.prototype._selectHighlightedItem = function() {
|
337
|
-
var curr = this.
|
353
|
+
var curr = this._getHighlightedItemElem();
|
338
354
|
if (curr.length !== 0) {
|
339
355
|
var prevValue = this.prevValue;
|
340
356
|
var newValue = curr.data('romo-option-list-dropdown-option-value');
|
@@ -481,49 +497,84 @@ RomoOptionListDropdown.prototype._scrollBottomToItem = function(item) {
|
|
481
497
|
}
|
482
498
|
|
483
499
|
RomoOptionListDropdown.prototype._nextListItem = function() {
|
484
|
-
var curr = this.
|
500
|
+
var curr = this._getHighlightedItemElem();
|
485
501
|
if (curr.length === 0) {
|
486
502
|
return curr;
|
487
503
|
}
|
488
|
-
var
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
if
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
504
|
+
var next = Romo.selectNext(curr, this.itemSelector+', UL.romo-option-list-optgroup');
|
505
|
+
if (next.length === 0) {
|
506
|
+
// curr is either the last ungrouped opt elem in the overall
|
507
|
+
// list OR is the last opt elem in a grouped list.
|
508
|
+
|
509
|
+
// if the hightlighted opt elem is in an opt group list, use
|
510
|
+
// its list as the reference elem. otherwise keep using the
|
511
|
+
// hightlighted opt elem itself.
|
512
|
+
curr = curr.closest('UL.romo-option-list-optgroup') || curr;
|
513
|
+
next = Romo.selectNext(curr, this.itemSelector+', UL.romo-option-list-optgroup');
|
498
514
|
}
|
515
|
+
while (next.hasClass('romo-option-list-optgroup') && next.children().size() === 0) {
|
516
|
+
// keep trying until you find a opt group list with options or an option or nothing
|
517
|
+
curr = next;
|
518
|
+
next = Romo.selectNext(curr, this.itemSelector+', UL.romo-option-list-optgroup');
|
519
|
+
}
|
520
|
+
if (next.length === 0) {
|
521
|
+
// curr is the last opt elem (grouped or not) in the overall
|
522
|
+
// list. get the the first opt elem in the overall list
|
523
|
+
next = this.romoDropdown.bodyElem.find(this.itemSelector).first();
|
524
|
+
} else if (next.hasClass('romo-option-list-optgroup')) {
|
525
|
+
// curr (grouped or not) is before an opt group list. get
|
526
|
+
// the first opt elem in that list.
|
527
|
+
next = next.find(this.itemSelector).first();
|
528
|
+
}
|
529
|
+
// otherwise curr (grouped or not) is before an opt elem.
|
530
|
+
// use that opt elem.
|
531
|
+
|
499
532
|
return next;
|
500
533
|
}
|
501
534
|
|
502
535
|
RomoOptionListDropdown.prototype._prevListItem = function() {
|
503
|
-
var curr = this.
|
536
|
+
var curr = this._getHighlightedItemElem();
|
504
537
|
if (curr.length === 0) {
|
505
538
|
return curr;
|
506
539
|
}
|
507
|
-
var currList = curr.closest('UL');
|
508
|
-
var prev = Romo.selectPrev(curr, this.itemSelector);
|
509
540
|
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
541
|
+
var prev = Romo.selectPrev(curr, this.itemSelector+', UL.romo-option-list-optgroup');
|
542
|
+
if (prev.length === 0) {
|
543
|
+
// curr is either the first ungrouped opt elem in the overall
|
544
|
+
// list OR is the first opt elem in a grouped list
|
545
|
+
|
546
|
+
// if the hightlighted opt elem is in an opt group list, use
|
547
|
+
// its list as the reference elem. otherwise keep using the
|
548
|
+
// hightlighted opt elem itself.
|
549
|
+
curr = curr.closest('UL.romo-option-list-optgroup') || curr;
|
550
|
+
prev = Romo.selectPrev(curr, this.itemSelector+', UL.romo-option-list-optgroup');
|
551
|
+
}
|
552
|
+
while (prev.hasClass('romo-option-list-optgroup') && prev.children().size() === 0) {
|
553
|
+
// keep trying until you find a opt group list with options or an option or nothing
|
554
|
+
curr = prev;
|
555
|
+
prev = Romo.selectPrev(curr, this.itemSelector+', UL.romo-option-list-optgroup');
|
517
556
|
}
|
557
|
+
if (prev.length === 0) {
|
558
|
+
// curr is the first opt elem (grouped or not) in the overall
|
559
|
+
// list. get the the last opt elem in the overall list
|
560
|
+
prev = this.romoDropdown.bodyElem.find(this.itemSelector).last();
|
561
|
+
} else if (prev.hasClass('romo-option-list-optgroup')) {
|
562
|
+
// curr (grouped or not) is after an opt group list. get
|
563
|
+
// the last opt elem in that list.
|
564
|
+
prev = prev.find(this.itemSelector).last();
|
565
|
+
}
|
566
|
+
// otherwise curr (grouped or not) is after an opt elem.
|
567
|
+
// use that opt elem.
|
568
|
+
|
518
569
|
return prev;
|
519
570
|
}
|
520
571
|
|
521
572
|
RomoOptionListDropdown.prototype._highlightItem = function(item) {
|
522
|
-
this.
|
573
|
+
this._getHighlightedItemElem().removeClass('romo-option-list-dropdown-highlight');
|
523
574
|
item.addClass('romo-option-list-dropdown-highlight');
|
524
575
|
}
|
525
576
|
|
526
|
-
RomoOptionListDropdown.prototype.
|
577
|
+
RomoOptionListDropdown.prototype._getHighlightedItemElem = function() {
|
527
578
|
return this.romoDropdown.bodyElem.find('LI.romo-option-list-dropdown-highlight');
|
528
579
|
}
|
529
580
|
|
data/assets/js/romo/picker.js
CHANGED
@@ -11,7 +11,8 @@ var RomoPicker = function(element) {
|
|
11
11
|
this.defaultCaretPaddingPx = 5;
|
12
12
|
this.defaultCaretPosition = 'right'
|
13
13
|
|
14
|
-
this.defaultOptionItems
|
14
|
+
this.defaultOptionItems = this._buildDefaultOptionItems();
|
15
|
+
this.filteredOptionItems = [];
|
15
16
|
|
16
17
|
this.doInit();
|
17
18
|
this._bindElem();
|
@@ -109,9 +110,13 @@ RomoPicker.prototype._bindOptionListDropdown = function() {
|
|
109
110
|
|
110
111
|
this.romoOptionListDropdown.elem.on('romoOptionListDropdown:filterChange', $.proxy(function(e, filterValue, romoOptionListDropdown) {
|
111
112
|
if (filterValue !== '') {
|
113
|
+
// immediately update the custom opt as the filter changes
|
114
|
+
// but keep the current filtered option items
|
115
|
+
this._setListItems(this.filteredOptionItems.concat(this._buildCustomOptionItems()));
|
116
|
+
// this will update with the new filtered items plus the custom on ajax callback
|
112
117
|
this.elem.trigger('romoAjax:triggerInvoke', [{ 'filter': filterValue }]);
|
113
118
|
} else {
|
114
|
-
this._setListItems(this.defaultOptionItems);
|
119
|
+
this._setListItems(this.defaultOptionItems.concat(this._buildCustomOptionItems()));
|
115
120
|
}
|
116
121
|
}, this));
|
117
122
|
this.romoOptionListDropdown.elem.on('romoOptionListDropdown:itemSelected', $.proxy(function(e, newValue, prevValue, optionListDropdown) {
|
@@ -152,6 +157,9 @@ RomoPicker.prototype._buildOptionListDropdownElem = function() {
|
|
152
157
|
if (this.elem.data('romo-picker-no-filter') !== undefined) {
|
153
158
|
romoOptionListDropdownElem.attr('data-romo-option-list-dropdown-no-filter', this.elem.data('romo-picker-no-filter'));
|
154
159
|
}
|
160
|
+
if (this.elem.data('romo-picker-open-on-focus') !== undefined) {
|
161
|
+
romoOptionListDropdownElem.attr('data-romo-option-list-dropdown-open-on-focus', this.elem.data('romo-picker-open-on-focus'));
|
162
|
+
}
|
155
163
|
|
156
164
|
var classList = this.elem.attr('class') !== undefined ? this.elem.attr('class').split(/\s+/) : [];
|
157
165
|
$.each(classList, function(idx, classItem) {
|
@@ -218,11 +226,12 @@ RomoPicker.prototype._bindAjax = function() {
|
|
218
226
|
this.romoOptionListDropdown.elem.trigger('romoOptionListDropdown:triggerFilterIndicatorStart', []);
|
219
227
|
}, this));
|
220
228
|
this.elem.on('romoAjax:callSuccess', $.proxy(function(e, data, romoAjax) {
|
221
|
-
this.
|
229
|
+
this.filteredOptionItems = data;
|
230
|
+
this._setListItems(this.filteredOptionItems.concat(this._buildCustomOptionItems()));
|
222
231
|
this.romoOptionListDropdown.elem.trigger('romoOptionListDropdown:triggerFilterIndicatorStop', []);
|
223
232
|
}, this));
|
224
233
|
this.elem.on('romoAjax:callError', $.proxy(function(e, xhr, romoAjax) {
|
225
|
-
this._setListItems(this.defaultOptionItems);
|
234
|
+
this._setListItems(this.defaultOptionItems.concat(this._buildCustomOptionItems()));
|
226
235
|
this.romoOptionListDropdown.elem.trigger('romoOptionListDropdown:triggerFilterIndicatorStop', []);
|
227
236
|
}, this));
|
228
237
|
|
@@ -234,7 +243,7 @@ RomoPicker.prototype._setListItems = function(items) {
|
|
234
243
|
this.romoOptionListDropdown.elem.trigger('romoOptionListDropdown:triggerListOptionsUpdate', [this.romoOptionListDropdown.optItemElems().first()]);
|
235
244
|
}
|
236
245
|
|
237
|
-
RomoPicker.prototype._buildDefaultOptionItems = function(
|
246
|
+
RomoPicker.prototype._buildDefaultOptionItems = function() {
|
238
247
|
var items = []
|
239
248
|
|
240
249
|
if (this.elem.data('romo-picker-empty-option') === true) {
|
@@ -249,6 +258,35 @@ RomoPicker.prototype._buildDefaultOptionItems = function(e) {
|
|
249
258
|
return items;
|
250
259
|
}
|
251
260
|
|
261
|
+
RomoPicker.prototype._buildCustomOptionItems = function() {
|
262
|
+
var items = [];
|
263
|
+
|
264
|
+
var value = this.romoOptionListDropdown.optionFilterValue();
|
265
|
+
if (value !== '' && this.elem.data('romo-picker-custom-option') === true) {
|
266
|
+
var prompt = this.elem.data('romo-picker-custom-option-prompt');
|
267
|
+
if (prompt !== undefined) {
|
268
|
+
items.push({
|
269
|
+
'type': 'optgroup',
|
270
|
+
'label': prompt,
|
271
|
+
'items': [this._buildCustomOptionItem(value)]
|
272
|
+
});
|
273
|
+
} else {
|
274
|
+
items.push(this._buildCustomOptionItem(value));
|
275
|
+
}
|
276
|
+
}
|
277
|
+
|
278
|
+
return items;
|
279
|
+
}
|
280
|
+
|
281
|
+
RomoPicker.prototype._buildCustomOptionItem = function(value) {
|
282
|
+
return {
|
283
|
+
'type': 'option',
|
284
|
+
'value': value,
|
285
|
+
'displayText': value,
|
286
|
+
'displayHtml': value
|
287
|
+
};
|
288
|
+
}
|
289
|
+
|
252
290
|
RomoPicker.prototype._onCaretClick = function(e) {
|
253
291
|
if (this.elem.prop('disabled') === false) {
|
254
292
|
this.romoOptionListDropdown.elem.focus();
|
data/assets/js/romo/select.js
CHANGED
@@ -66,6 +66,12 @@ RomoSelect.prototype._bindElem = function() {
|
|
66
66
|
this.elem.on('select:triggerPopupClose', $.proxy(function(e) {
|
67
67
|
this.romoSelectDropdown.elem.trigger('selectDropdown:triggerPopupClose', []);
|
68
68
|
}, this));
|
69
|
+
|
70
|
+
|
71
|
+
var presetVal = this.elem[0].value;
|
72
|
+
if (presetVal !== '') {
|
73
|
+
this.doSetValue(presetVal);
|
74
|
+
}
|
69
75
|
}
|
70
76
|
|
71
77
|
RomoSelect.prototype._bindSelectDropdown = function() {
|
@@ -117,6 +123,15 @@ RomoSelect.prototype._buildSelectDropdownElem = function() {
|
|
117
123
|
if (this.elem.data('romo-select-no-filter') !== undefined) {
|
118
124
|
romoSelectDropdownElem.attr('data-romo-select-dropdown-no-filter', this.elem.data('romo-select-no-filter'));
|
119
125
|
}
|
126
|
+
if (this.elem.data('romo-select-custom-option') !== undefined) {
|
127
|
+
romoSelectDropdownElem.attr('data-romo-select-dropdown-custom-option', this.elem.data('romo-select-custom-option'));
|
128
|
+
}
|
129
|
+
if (this.elem.data('romo-select-custom-option-prompt') !== undefined) {
|
130
|
+
romoSelectDropdownElem.attr('data-romo-select-dropdown-custom-option-prompt', this.elem.data('romo-select-custom-option-prompt'));
|
131
|
+
}
|
132
|
+
if (this.elem.data('romo-select-open-on-focus') !== undefined) {
|
133
|
+
romoSelectDropdownElem.attr('data-romo-select-dropdown-open-on-focus', this.elem.data('romo-select-open-on-focus'));
|
134
|
+
}
|
120
135
|
|
121
136
|
var classList = this.elem.attr('class') !== undefined ? this.elem.attr('class').split(/\s+/) : [];
|
122
137
|
$.each(classList, function(idx, classItem) {
|
@@ -7,10 +7,9 @@ $.fn.romoSelectDropdown = function(optionElemsParent) {
|
|
7
7
|
var RomoSelectDropdown = function(element, optionElemsParent) {
|
8
8
|
this.elem = $(element);
|
9
9
|
|
10
|
-
this.filterHiddenClass
|
11
|
-
|
12
|
-
|
13
|
-
this.optionElems = optsParent.children();
|
10
|
+
this.filterHiddenClass = 'romo-select-filter-hidden';
|
11
|
+
this.optionElemSelector = ':not(.'+this.filterHiddenClass+')';
|
12
|
+
this.optionElemsParent = (optionElemsParent || this.elem.find('.romo-select-dropdown-options-parent'));
|
14
13
|
|
15
14
|
this.doInit();
|
16
15
|
this._bindElem();
|
@@ -44,6 +43,10 @@ RomoSelectDropdown.prototype.selectedItemText = function() {
|
|
44
43
|
return this.romoOptionListDropdown.selectedItemText();
|
45
44
|
}
|
46
45
|
|
46
|
+
RomoSelectDropdown.prototype.optionFilterValue = function() {
|
47
|
+
return this.romoOptionListDropdown.optionFilterValue();
|
48
|
+
}
|
49
|
+
|
47
50
|
RomoSelectDropdown.prototype.optItemElems = function() {
|
48
51
|
return this.romoOptionListDropdown.optItemElems();
|
49
52
|
}
|
@@ -63,7 +66,6 @@ RomoSelectDropdown.prototype.doSetNewValue = function(newValue) {
|
|
63
66
|
/* private */
|
64
67
|
|
65
68
|
RomoSelectDropdown.prototype._bindElem = function() {
|
66
|
-
this.elem.attr('data-romo-option-list-dropdown-item-selector-customization', ':not(.'+this.filterHiddenClass+')');
|
67
69
|
this.elem.attr('data-romo-option-list-focus-style-class', 'romo-select-focus');
|
68
70
|
|
69
71
|
if (this.elem.data('romo-select-dropdown-no-filter') !== undefined) {
|
@@ -78,6 +80,9 @@ RomoSelectDropdown.prototype._bindElem = function() {
|
|
78
80
|
if (this.elem.data('romo-select-dropdown-filter-indicator-width-px') !== undefined) {
|
79
81
|
this.elem.attr('data-romo-option-list-dropdown-filter-indicator-width-px', this.elem.data('romo-select-dropdown-filter-indicator-width-px'));
|
80
82
|
}
|
83
|
+
if (this.elem.data('romo-select-dropdown-open-on-focus') !== undefined) {
|
84
|
+
this.elem.attr('data-romo-option-list-dropdown-open-on-focus', this.elem.data('romo-select-dropdown-open-on-focus'));
|
85
|
+
}
|
81
86
|
|
82
87
|
this.elem.on('romoOptionListDropdown:dropdown:toggle', $.proxy(function(e, dropdown) {
|
83
88
|
this.elem.trigger('selectDropdown:dropdown:toggle', [dropdown, this]);
|
@@ -109,36 +114,46 @@ RomoSelectDropdown.prototype._bindElem = function() {
|
|
109
114
|
this.romoOptionListDropdown = this.elem.romoOptionListDropdown()[0];
|
110
115
|
|
111
116
|
this.elem.on('romoOptionListDropdown:filterChange', $.proxy(function(e, filterValue, romoOptionListDropdown) {
|
112
|
-
var
|
113
|
-
|
114
|
-
//
|
115
|
-
// as word boundaries
|
117
|
+
var elems = this.optionElemsParent.find('option');
|
118
|
+
var wbFilter = new RomoWordBoundaryFilter(filterValue, elems, function(elem) {
|
119
|
+
// The romo word boundary filter by default considers a space, "-" and "_"
|
120
|
+
// as word boundaries. We want to also consider other non-word characters
|
121
|
+
// (such as ":", "/", ".", "?", "=", "&") as word boundaries as well.
|
116
122
|
return elem[0].textContent.replace(/\W/g, ' ');
|
117
123
|
});
|
118
124
|
|
119
|
-
wbFilter.matchingElems.show();
|
120
|
-
wbFilter.notMatchingElems.hide();
|
121
125
|
wbFilter.matchingElems.removeClass(this.filterHiddenClass);
|
122
126
|
wbFilter.notMatchingElems.addClass(this.filterHiddenClass);
|
127
|
+
this._setListItems();
|
123
128
|
|
124
129
|
if (filterValue !== '') {
|
125
|
-
this.elem.trigger('romoOptionListDropdown:triggerListOptionsUpdate', [
|
130
|
+
this.romoOptionListDropdown.elem.trigger('romoOptionListDropdown:triggerListOptionsUpdate', [this.optItemElems().first()]);
|
126
131
|
} else {
|
127
132
|
this.elem.trigger('romoOptionListDropdown:triggerListOptionsUpdate', [this.selectedItemElem()]);
|
128
133
|
}
|
129
134
|
}, this));
|
130
135
|
|
131
|
-
this.
|
136
|
+
this._setListItems();
|
137
|
+
this.elem.trigger('romoOptionListDropdown:triggerListOptionsUpdate', [this.selectedItemElem()]);
|
132
138
|
}
|
133
139
|
|
134
|
-
RomoSelectDropdown.prototype.
|
140
|
+
RomoSelectDropdown.prototype._setListItems = function() {
|
141
|
+
var optElems = this.optionElemsParent.children(this.optionElemSelector);
|
142
|
+
var items = this._buildOptionListItems(optElems).concat(this._buildCustomOptionItems());
|
143
|
+
this.romoOptionListDropdown.doSetListItems(items);
|
144
|
+
}
|
145
|
+
|
146
|
+
RomoSelectDropdown.prototype._buildOptionListItems = function(optionElems) {
|
135
147
|
var list = [];
|
136
148
|
|
137
149
|
$.each(optionElems, $.proxy(function(idx, optionNode) {
|
138
150
|
if (optionNode.tagName === "OPTION") {
|
139
151
|
list.push(this._buildOptionItem($(optionNode)));
|
140
152
|
} else if (optionNode.tagName === "OPTGROUP") {
|
141
|
-
|
153
|
+
var optGroupItem = this._buildOptGroupItem($(optionNode));
|
154
|
+
if (optGroupItem.items.length !== 0) {
|
155
|
+
list.push(optGroupItem);
|
156
|
+
}
|
142
157
|
}
|
143
158
|
}, this));
|
144
159
|
|
@@ -168,11 +183,40 @@ RomoSelectDropdown.prototype._buildOptGroupItem = function(optGroupElem) {
|
|
168
183
|
|
169
184
|
item['type'] = 'optgroup';
|
170
185
|
item['label'] = optGroupElem.attr('label');
|
171
|
-
item['items'] = this.
|
186
|
+
item['items'] = this._buildOptionListItems(optGroupElem.children(this.optionElemSelector));
|
172
187
|
|
173
188
|
return item;
|
174
189
|
}
|
175
190
|
|
191
|
+
RomoSelectDropdown.prototype._buildCustomOptionItems = function() {
|
192
|
+
var items = [];
|
193
|
+
|
194
|
+
var value = this.romoOptionListDropdown.optionFilterValue();
|
195
|
+
if (value !== '' && this.elem.data('romo-select-dropdown-custom-option') === true) {
|
196
|
+
var prompt = this.elem.data('romo-select-dropdown-custom-option-prompt');
|
197
|
+
if (prompt !== undefined) {
|
198
|
+
items.push({
|
199
|
+
'type': 'optgroup',
|
200
|
+
'label': prompt,
|
201
|
+
'items': [this._buildCustomOptionItem(value)]
|
202
|
+
});
|
203
|
+
} else {
|
204
|
+
items.push(this._buildCustomOptionItem(value));
|
205
|
+
}
|
206
|
+
}
|
207
|
+
|
208
|
+
return items;
|
209
|
+
}
|
210
|
+
|
211
|
+
RomoSelectDropdown.prototype._buildCustomOptionItem = function(value) {
|
212
|
+
return {
|
213
|
+
'type': 'option',
|
214
|
+
'value': value,
|
215
|
+
'displayText': value,
|
216
|
+
'displayHtml': value
|
217
|
+
};
|
218
|
+
}
|
219
|
+
|
176
220
|
Romo.onInitUI(function(e) {
|
177
221
|
Romo.initUIElems(e, '[data-romo-select-dropdown-auto="true"]').romoSelectDropdown();
|
178
222
|
});
|
data/lib/romo/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: romo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.19.
|
4
|
+
version: 0.19.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Redding
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2017-08-
|
13
|
+
date: 2017-08-23 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: assert
|