romo 0.19.3 → 0.19.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,287 @@
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);
9
+
10
+ this.defaultCaretClass = undefined;
11
+ this.defaultCaretPaddingPx = 5;
12
+ this.defaultCaretPosition = 'right'
13
+
14
+ this.defaultOptionItems = this._buildDefaultOptionItems();
15
+
16
+ this.doInit();
17
+ this._bindElem();
18
+ this.doRefreshUI();
19
+
20
+ if (this.elem.attr('id') !== undefined) {
21
+ $('label[for="'+this.elem.attr('id')+'"]').on('click', $.proxy(function(e) {
22
+ this.romoOptionListDropdown.elem.focus();
23
+ }, this));
24
+ }
25
+
26
+ $(window).on("pageshow", $.proxy(function(e) {
27
+ var selectedVal = this.romoOptionListDropdown.selectedItemValue();
28
+ if (selectedVal !== this.elem[0].value) {
29
+ var selectedText = this.romoOptionListDropdown.selectedItemText();
30
+ this.doSetSelectedValueAndText(selectedVal, selectedText);
31
+ }
32
+ }, this));
33
+
34
+ this.elem.on('romoPicker:triggerSetValue', $.proxy(function(e, value) {
35
+ this.doSetValue(value)
36
+ }, this));
37
+
38
+ this.elem.trigger('romoPicker:ready', [this]);
39
+ }
40
+
41
+ RomoPicker.prototype.doInit = function() {
42
+ // override as needed
43
+ }
44
+
45
+ RomoPicker.prototype.doRefreshUI = function() {
46
+ var text = this.romoOptionListDropdown.selectedItemText();
47
+ if (text === '') {
48
+ text = ' '
49
+ }
50
+ this.romoOptionListDropdown.elem.find('.romo-picker-text').html(text);
51
+ }
52
+
53
+ RomoPicker.prototype.doSetValue = function(value) {
54
+ $.ajax({
55
+ type: 'GET',
56
+ url: this.elem.data('romo-picker-url'),
57
+ data: { 'values': value },
58
+ success: $.proxy(function(data, status, xhr) {
59
+ if (data[0] !== undefined) {
60
+ this.doSetSelectedValueAndText(data[0].value, data[0].displayText);
61
+ } else {
62
+ this.doSetSelectedValueAndText('', '');
63
+ }
64
+ }, this),
65
+ });
66
+ }
67
+
68
+ RomoPicker.prototype.doSetSelectedValueAndText = function(value, text) {
69
+ this.romoOptionListDropdown.doSetSelectedValueAndText(value, text);
70
+ this._setNewValue(value);
71
+ }
72
+
73
+ /* private */
74
+
75
+ RomoPicker.prototype._bindElem = function() {
76
+ this._bindOptionListDropdown();
77
+ this._bindAjax();
78
+
79
+ this.elem.on('romoPicker:triggerToggle', $.proxy(function(e) {
80
+ this.romoOptionListDropdown.elem.trigger('romoOptionListDropdown:triggerToggle', []);
81
+ }, this));
82
+ this.elem.on('romoPicker:triggerPopupOpen', $.proxy(function(e) {
83
+ this.romoOptionListDropdown.elem.trigger('romoOptionListDropdown:triggerPopupOpen', []);
84
+ }, this));
85
+ this.elem.on('romoPicker:triggerPopupClose', $.proxy(function(e) {
86
+ this.romoOptionListDropdown.elem.trigger('romoOptionListDropdown:triggerPopupClose', []);
87
+ }, this));
88
+
89
+ this.romoOptionListDropdown.doSetListItems(this.defaultOptionItems);
90
+
91
+ var presetVal = this.elem[0].value;
92
+ if (presetVal !== '') {
93
+ this.doSetValue(presetVal);
94
+ }
95
+ }
96
+
97
+ RomoPicker.prototype._bindOptionListDropdown = function() {
98
+ this.romoOptionListDropdown = this._buildOptionListDropdownElem().romoOptionListDropdown(this.elem)[0];
99
+
100
+ this.romoOptionListDropdown.elem.on('romoOptionListDropdown:dropdown:toggle', $.proxy(function(e, dropdown, optionListDropdown) {
101
+ this.elem.trigger('romoPicker:dropdown:toggle', [dropdown, this]);
102
+ }, this));
103
+ this.romoOptionListDropdown.elem.on('romoOptionListDropdown:dropdown:popupOpen', $.proxy(function(e, dropdown, optionListDropdown) {
104
+ this.elem.trigger('romoPicker:dropdown:popupOpen', [dropdown, this]);
105
+ }, this));
106
+ this.romoOptionListDropdown.elem.on('romoOptionListDropdown:dropdown:popupClose', $.proxy(function(e, dropdown, optionListDropdown) {
107
+ this.elem.trigger('romoPicker:dropdown:popupClose', [dropdown, this]);
108
+ }, this));
109
+
110
+ this.romoOptionListDropdown.elem.on('romoOptionListDropdown:filterChange', $.proxy(function(e, filterValue, romoOptionListDropdown) {
111
+ if (filterValue !== '') {
112
+ this.elem.trigger('romoAjax:triggerInvoke', [{ 'filter': filterValue }]);
113
+ } else {
114
+ this._setListItems(this.defaultOptionItems);
115
+ }
116
+ }, this));
117
+ this.romoOptionListDropdown.elem.on('romoOptionListDropdown:itemSelected', $.proxy(function(e, newValue, prevValue, optionListDropdown) {
118
+ this.romoOptionListDropdown.elem.focus();
119
+ this.elem.trigger('romoPicker:itemSelected', [newValue, prevValue, this]);
120
+ }, this));
121
+ this.romoOptionListDropdown.elem.on('romoOptionListDropdown:change', $.proxy(function(e, newValue, prevValue, optionListDropdown) {
122
+ this._setNewValue(newValue);
123
+ this.elem.trigger('change');
124
+ this.elem.trigger('romoPicker:change', [newValue, prevValue, this]);
125
+ }, this));
126
+ }
127
+
128
+ RomoPicker.prototype._buildOptionListDropdownElem = function() {
129
+ var romoOptionListDropdownElem = $('<div class="romo-picker romo-btn" tabindex="0"><span class="romo-picker-text"></span></div>');
130
+
131
+ romoOptionListDropdownElem.attr('data-romo-option-list-focus-style-class', 'romo-picker-focus');
132
+
133
+ romoOptionListDropdownElem.attr('data-romo-dropdown-position', this.elem.data('romo-picker-dropdown-position'));
134
+ romoOptionListDropdownElem.attr('data-romo-dropdown-style-class', this.elem.data('romo-picker-dropdown-style-class'));
135
+ romoOptionListDropdownElem.attr('data-romo-dropdown-min-height', this.elem.data('romo-picker-dropdown-min-height'));
136
+ romoOptionListDropdownElem.attr('data-romo-dropdown-max-height', this.elem.data('romo-picker-dropdown-max-height'));
137
+ romoOptionListDropdownElem.attr('data-romo-dropdown-height', this.elem.data('romo-picker-dropdown-height'));
138
+ romoOptionListDropdownElem.attr('data-romo-dropdown-overflow-x', 'hidden');
139
+ romoOptionListDropdownElem.attr('data-romo-dropdown-width', 'elem');
140
+ if (romoOptionListDropdownElem.data('romo-dropdown-max-height') === undefined) {
141
+ romoOptionListDropdownElem.attr('data-romo-dropdown-max-height', 'detect');
142
+ }
143
+ if (this.elem.data('romo-picker-filter-placeholder') !== undefined) {
144
+ romoOptionListDropdownElem.attr('data-romo-option-list-dropdown-filter-placeholder', this.elem.data('romo-picker-filter-placeholder'));
145
+ }
146
+ if (this.elem.data('romo-picker-filter-indicator') !== undefined) {
147
+ romoOptionListDropdownElem.attr('data-romo-option-list-dropdown-filter-indicator', this.elem.data('romo-picker-filter-indicator'));
148
+ }
149
+ if (this.elem.data('romo-picker-filter-indicator-width-px') !== undefined) {
150
+ romoOptionListDropdownElem.attr('data-romo-option-list-filter-indicator-width-px', this.elem.data('romo-picker-filter-indicator-width-px'));
151
+ }
152
+ if (this.elem.data('romo-picker-no-filter') !== undefined) {
153
+ romoOptionListDropdownElem.attr('data-romo-option-list-dropdown-no-filter', this.elem.data('romo-picker-no-filter'));
154
+ }
155
+
156
+ var classList = this.elem.attr('class') !== undefined ? this.elem.attr('class').split(/\s+/) : [];
157
+ $.each(classList, function(idx, classItem) {
158
+ romoOptionListDropdownElem.addClass(classItem);
159
+ });
160
+ if (this.elem.attr('style') !== undefined) {
161
+ romoOptionListDropdownElem.attr('style', this.elem.attr('style'));
162
+ }
163
+ romoOptionListDropdownElem.css({'width': this.elem.css('width')});
164
+ if (this.elem.attr('disabled') !== undefined) {
165
+ this.romoOptionListDropdown.elem.attr('disabled', this.elem.attr('disabled'));
166
+ }
167
+
168
+ this.elem.after(romoOptionListDropdownElem);
169
+ this.elem.hide();
170
+
171
+ this.elemWrapper = $('<div class="romo-picker-wrapper"></div>');
172
+ if (this.elem.data('romo-picker-btn-group') === true) {
173
+ this.elemWrapper.addClass('romo-btn-group');
174
+ }
175
+ romoOptionListDropdownElem.before(this.elemWrapper);
176
+ this.elemWrapper.append(romoOptionListDropdownElem);
177
+
178
+ // the elem wrapper should be treated like a child elem. add it to Romo's
179
+ // parent-child elems so it will be removed when the elem (picker input) is removed.
180
+ // delay adding it b/c other components may `append` generated pickers
181
+ // meaning the picker is removed and then re-added. if added immediately
182
+ // the "remove" part will incorrectly remove the wrapper.
183
+ setTimeout($.proxy(function() {
184
+ Romo.parentChildElems.add(this.elem, [this.elemWrapper]);
185
+ }, this), 1);
186
+
187
+ this.caretElem = $();
188
+ var caretClass = this.elem.data('romo-picker-caret') || this.defaultCaretClass;
189
+ if (caretClass !== undefined && caretClass !== 'none') {
190
+ this.caretElem = $('<i class="romo-picker-caret '+caretClass+'"></i>');
191
+ this.caretElem.css('line-height', parseInt(Romo.getComputedStyle(romoOptionListDropdownElem[0], "line-height"), 10)+'px');
192
+ this.caretElem.on('click', $.proxy(this._onCaretClick, this));
193
+ romoOptionListDropdownElem.append(this.caretElem);
194
+
195
+ var caretPaddingPx = this._getCaretPaddingPx();
196
+ var caretWidthPx = this._getCaretWidthPx();
197
+ var caretPosition = this._getCaretPosition();
198
+
199
+ // add a pixel to account for the default input border
200
+ this.caretElem.css(caretPosition, caretPaddingPx+1);
201
+
202
+ // left-side padding
203
+ // + caret width
204
+ // + right-side padding
205
+ var dropdownPaddingPx = caretPaddingPx + caretWidthPx + caretPaddingPx;
206
+ romoOptionListDropdownElem.css('padding-'+caretPosition, dropdownPaddingPx+'px');
207
+ }
208
+
209
+ return romoOptionListDropdownElem;
210
+ }
211
+
212
+ RomoPicker.prototype._bindAjax = function() {
213
+ this.elem.attr('data-romo-ajax-disable-default-invoke-on', true);
214
+ this.elem.attr('data-romo-ajax-url-attr', 'data-romo-picker-url');
215
+ this.elem.attr('data-romo-ajax-auto', false);
216
+
217
+ this.elem.on('romoAjax:callStart', $.proxy(function(e, data, romoAjax) {
218
+ this.romoOptionListDropdown.elem.trigger('romoOptionListDropdown:triggerFilterIndicatorStart', []);
219
+ }, this));
220
+ this.elem.on('romoAjax:callSuccess', $.proxy(function(e, data, romoAjax) {
221
+ this._setListItems(data);
222
+ this.romoOptionListDropdown.elem.trigger('romoOptionListDropdown:triggerFilterIndicatorStop', []);
223
+ }, this));
224
+ this.elem.on('romoAjax:callError', $.proxy(function(e, xhr, romoAjax) {
225
+ this._setListItems(this.defaultOptionItems);
226
+ this.romoOptionListDropdown.elem.trigger('romoOptionListDropdown:triggerFilterIndicatorStop', []);
227
+ }, this));
228
+
229
+ this.elem.romoAjax();
230
+ }
231
+
232
+ RomoPicker.prototype._setListItems = function(items) {
233
+ this.romoOptionListDropdown.doSetListItems(items);
234
+ this.romoOptionListDropdown.elem.trigger('romoOptionListDropdown:triggerListOptionsUpdate', [this.romoOptionListDropdown.optItemElems().first()]);
235
+ }
236
+
237
+ RomoPicker.prototype._buildDefaultOptionItems = function(e) {
238
+ var items = []
239
+
240
+ if (this.elem.data('romo-picker-empty-option') === true) {
241
+ items.push({
242
+ 'type': 'option',
243
+ 'value': '',
244
+ 'displayText': '',
245
+ 'displayHtml': '&nbsp;'
246
+ });
247
+ }
248
+
249
+ return items;
250
+ }
251
+
252
+ RomoPicker.prototype._onCaretClick = function(e) {
253
+ if (this.elem.prop('disabled') === false) {
254
+ this.romoOptionListDropdown.elem.focus();
255
+ this.elem.trigger('romoPicker:triggerPopupOpen');
256
+ }
257
+ }
258
+
259
+ RomoPicker.prototype._setNewValue = function(newValue) {
260
+ this.elem[0].value = newValue;
261
+ this.doRefreshUI();
262
+ }
263
+
264
+ RomoPicker.prototype._getCaretPaddingPx = function() {
265
+ return (
266
+ this.elem.data('romo-picker-caret-padding-px') ||
267
+ this.defaultCaretPaddingPx
268
+ );
269
+ }
270
+
271
+ RomoPicker.prototype._getCaretWidthPx = function() {
272
+ return (
273
+ this.elem.data('romo-picker-caret-width-px') ||
274
+ parseInt(Romo.getComputedStyle(this.caretElem[0], "width"), 10)
275
+ );
276
+ }
277
+
278
+ RomoPicker.prototype._getCaretPosition = function() {
279
+ return (
280
+ this.elem.data('romo-picker-caret-position') ||
281
+ this.defaultCaretPosition
282
+ );
283
+ }
284
+
285
+ Romo.onInitUI(function(e) {
286
+ Romo.initUIElems(e, '[data-romo-picker-auto="true"]').romoPicker();
287
+ });
@@ -12,7 +12,7 @@ var RomoSelect = function(element) {
12
12
  this.defaultCaretPosition = 'right'
13
13
 
14
14
  this.doInit();
15
- this.doBindSelectDropdown();
15
+ this._bindElem();
16
16
  this.doRefreshUI();
17
17
 
18
18
  if (this.elem.attr('id') !== undefined) {
@@ -22,10 +22,7 @@ var RomoSelect = function(element) {
22
22
  }
23
23
 
24
24
  $(window).on("pageshow", $.proxy(function(e) {
25
- var selectedVal = this.elem.find('option[selected]').attr('value');
26
- if (selectedVal === undefined) {
27
- selectedVal = '';
28
- }
25
+ var selectedVal = this.romoSelectDropdown.selectedItemValue();
29
26
  if (selectedVal !== this.elem[0].value) {
30
27
  this.doSetValue(selectedVal);
31
28
  }
@@ -42,7 +39,36 @@ RomoSelect.prototype.doInit = function() {
42
39
  // override as needed
43
40
  }
44
41
 
45
- RomoSelect.prototype.doBindSelectDropdown = function() {
42
+ RomoSelect.prototype.doRefreshUI = function() {
43
+ var text = this.romoSelectDropdown.selectedItemText();
44
+ if (text === '') {
45
+ text = '&nbsp;'
46
+ }
47
+ this.romoSelectDropdown.elem.find('.romo-select-text').html(text);
48
+ }
49
+
50
+ RomoSelect.prototype.doSetValue = function(value) {
51
+ this.romoSelectDropdown.doSetNewValue(value);
52
+ this._setNewValue(value);
53
+ }
54
+
55
+ /* private */
56
+
57
+ RomoSelect.prototype._bindElem = function() {
58
+ this._bindSelectDropdown();
59
+
60
+ this.elem.on('select:triggerToggle', $.proxy(function(e) {
61
+ this.romoSelectDropdown.elem.trigger('selectDropdown:triggerToggle', []);
62
+ }, this));
63
+ this.elem.on('select:triggerPopupOpen', $.proxy(function(e) {
64
+ this.romoSelectDropdown.elem.trigger('selectDropdown:triggerPopupOpen', []);
65
+ }, this));
66
+ this.elem.on('select:triggerPopupClose', $.proxy(function(e) {
67
+ this.romoSelectDropdown.elem.trigger('selectDropdown:triggerPopupClose', []);
68
+ }, this));
69
+ }
70
+
71
+ RomoSelect.prototype._bindSelectDropdown = function() {
46
72
  this.romoSelectDropdown = this._buildSelectDropdownElem().romoSelectDropdown(this.elem)[0];
47
73
 
48
74
  this.romoSelectDropdown.elem.on('selectDropdown:dropdown:toggle', $.proxy(function(e, dropdown, selectDropdown) {
@@ -64,38 +90,6 @@ RomoSelect.prototype.doBindSelectDropdown = function() {
64
90
  this.elem.trigger('change');
65
91
  this.elem.trigger('select:change', [newValue, prevValue, this]);
66
92
  }, this));
67
-
68
- this.elem.on('select:triggerToggle', $.proxy(function(e) {
69
- this.romoSelectDropdown.elem.trigger('selectDropdown:triggerToggle', []);
70
- }, this));
71
- this.elem.on('select:triggerPopupOpen', $.proxy(function(e) {
72
- this.romoSelectDropdown.elem.trigger('selectDropdown:triggerPopupOpen', []);
73
- }, this));
74
- this.elem.on('select:triggerPopupClose', $.proxy(function(e) {
75
- this.romoSelectDropdown.elem.trigger('selectDropdown:triggerPopupClose', []);
76
- }, this));
77
- }
78
-
79
- RomoSelect.prototype.doRefreshUI = function() {
80
- var text = this.romoSelectDropdown.selectedListing().text() || '&nbsp;';
81
- this.romoSelectDropdown.elem.find('.romo-select-text').html(text);
82
- }
83
-
84
- RomoSelect.prototype.doSetValue = function(value) {
85
- this.romoSelectDropdown.doSetNewValue(value);
86
- this._setNewValue(value);
87
- }
88
-
89
- RomoSelect.prototype.onCaretClick = function(e) {
90
- if (this.elem.prop('disabled') === false) {
91
- this.romoSelectDropdown.elem.focus();
92
- this.elem.trigger('select:triggerPopupOpen');
93
- }
94
- }
95
-
96
- RomoSelect.prototype._setNewValue = function(newValue) {
97
- this.elem[0].value = newValue;
98
- this.doRefreshUI();
99
93
  }
100
94
 
101
95
  RomoSelect.prototype._buildSelectDropdownElem = function() {
@@ -160,7 +154,7 @@ RomoSelect.prototype._buildSelectDropdownElem = function() {
160
154
  if (caretClass !== undefined && caretClass !== 'none') {
161
155
  this.caretElem = $('<i class="romo-select-caret '+caretClass+'"></i>');
162
156
  this.caretElem.css('line-height', parseInt(Romo.getComputedStyle(romoSelectDropdownElem[0], "line-height"), 10)+'px');
163
- this.caretElem.on('click', $.proxy(this.onCaretClick, this));
157
+ this.caretElem.on('click', $.proxy(this._onCaretClick, this));
164
158
  romoSelectDropdownElem.append(this.caretElem);
165
159
 
166
160
  var caretPaddingPx = this._getCaretPaddingPx();
@@ -180,6 +174,18 @@ RomoSelect.prototype._buildSelectDropdownElem = function() {
180
174
  return romoSelectDropdownElem;
181
175
  }
182
176
 
177
+ RomoSelect.prototype._onCaretClick = function(e) {
178
+ if (this.elem.prop('disabled') === false) {
179
+ this.romoSelectDropdown.elem.focus();
180
+ this.elem.trigger('select:triggerPopupOpen');
181
+ }
182
+ }
183
+
184
+ RomoSelect.prototype._setNewValue = function(newValue) {
185
+ this.elem[0].value = newValue;
186
+ this.doRefreshUI();
187
+ }
188
+
183
189
  RomoSelect.prototype._getCaretPaddingPx = function() {
184
190
  return (
185
191
  this.elem.data('romo-select-caret-padding-px') ||