assets/js/romo/select.js in romo-0.19.3 vs assets/js/romo/select.js in romo-0.19.4
- old
+ new
@@ -10,24 +10,21 @@
this.defaultCaretClass = undefined;
this.defaultCaretPaddingPx = 5;
this.defaultCaretPosition = 'right'
this.doInit();
- this.doBindSelectDropdown();
+ this._bindElem();
this.doRefreshUI();
if (this.elem.attr('id') !== undefined) {
$('label[for="'+this.elem.attr('id')+'"]').on('click', $.proxy(function(e) {
this.romoSelectDropdown.elem.focus();
}, this));
}
$(window).on("pageshow", $.proxy(function(e) {
- var selectedVal = this.elem.find('option[selected]').attr('value');
- if (selectedVal === undefined) {
- selectedVal = '';
- }
+ var selectedVal = this.romoSelectDropdown.selectedItemValue();
if (selectedVal !== this.elem[0].value) {
this.doSetValue(selectedVal);
}
}, this));
@@ -40,11 +37,40 @@
RomoSelect.prototype.doInit = function() {
// override as needed
}
-RomoSelect.prototype.doBindSelectDropdown = function() {
+RomoSelect.prototype.doRefreshUI = function() {
+ var text = this.romoSelectDropdown.selectedItemText();
+ if (text === '') {
+ text = ' '
+ }
+ this.romoSelectDropdown.elem.find('.romo-select-text').html(text);
+}
+
+RomoSelect.prototype.doSetValue = function(value) {
+ this.romoSelectDropdown.doSetNewValue(value);
+ this._setNewValue(value);
+}
+
+/* private */
+
+RomoSelect.prototype._bindElem = function() {
+ this._bindSelectDropdown();
+
+ this.elem.on('select:triggerToggle', $.proxy(function(e) {
+ this.romoSelectDropdown.elem.trigger('selectDropdown:triggerToggle', []);
+ }, this));
+ this.elem.on('select:triggerPopupOpen', $.proxy(function(e) {
+ this.romoSelectDropdown.elem.trigger('selectDropdown:triggerPopupOpen', []);
+ }, this));
+ this.elem.on('select:triggerPopupClose', $.proxy(function(e) {
+ this.romoSelectDropdown.elem.trigger('selectDropdown:triggerPopupClose', []);
+ }, this));
+}
+
+RomoSelect.prototype._bindSelectDropdown = function() {
this.romoSelectDropdown = this._buildSelectDropdownElem().romoSelectDropdown(this.elem)[0];
this.romoSelectDropdown.elem.on('selectDropdown:dropdown:toggle', $.proxy(function(e, dropdown, selectDropdown) {
this.elem.trigger('select:dropdown:toggle', [dropdown, this]);
}, this));
@@ -62,44 +88,12 @@
this.romoSelectDropdown.elem.on('selectDropdown:change', $.proxy(function(e, newValue, prevValue, selectDropdown) {
this._setNewValue(newValue);
this.elem.trigger('change');
this.elem.trigger('select:change', [newValue, prevValue, this]);
}, this));
-
- this.elem.on('select:triggerToggle', $.proxy(function(e) {
- this.romoSelectDropdown.elem.trigger('selectDropdown:triggerToggle', []);
- }, this));
- this.elem.on('select:triggerPopupOpen', $.proxy(function(e) {
- this.romoSelectDropdown.elem.trigger('selectDropdown:triggerPopupOpen', []);
- }, this));
- this.elem.on('select:triggerPopupClose', $.proxy(function(e) {
- this.romoSelectDropdown.elem.trigger('selectDropdown:triggerPopupClose', []);
- }, this));
}
-RomoSelect.prototype.doRefreshUI = function() {
- var text = this.romoSelectDropdown.selectedListing().text() || ' ';
- this.romoSelectDropdown.elem.find('.romo-select-text').html(text);
-}
-
-RomoSelect.prototype.doSetValue = function(value) {
- this.romoSelectDropdown.doSetNewValue(value);
- this._setNewValue(value);
-}
-
-RomoSelect.prototype.onCaretClick = function(e) {
- if (this.elem.prop('disabled') === false) {
- this.romoSelectDropdown.elem.focus();
- this.elem.trigger('select:triggerPopupOpen');
- }
-}
-
-RomoSelect.prototype._setNewValue = function(newValue) {
- this.elem[0].value = newValue;
- this.doRefreshUI();
-}
-
RomoSelect.prototype._buildSelectDropdownElem = function() {
var romoSelectDropdownElem = $('<div class="romo-select romo-btn" tabindex="0"><span class="romo-select-text"></span></div>');
romoSelectDropdownElem.attr('data-romo-dropdown-position', this.elem.data('romo-select-dropdown-position'));
romoSelectDropdownElem.attr('data-romo-dropdown-style-class', this.elem.data('romo-select-dropdown-style-class'));
@@ -158,11 +152,11 @@
this.caretElem = $();
var caretClass = this.elem.data('romo-select-caret') || this.defaultCaretClass;
if (caretClass !== undefined && caretClass !== 'none') {
this.caretElem = $('<i class="romo-select-caret '+caretClass+'"></i>');
this.caretElem.css('line-height', parseInt(Romo.getComputedStyle(romoSelectDropdownElem[0], "line-height"), 10)+'px');
- this.caretElem.on('click', $.proxy(this.onCaretClick, this));
+ this.caretElem.on('click', $.proxy(this._onCaretClick, this));
romoSelectDropdownElem.append(this.caretElem);
var caretPaddingPx = this._getCaretPaddingPx();
var caretWidthPx = this._getCaretWidthPx();
var caretPosition = this._getCaretPosition();
@@ -176,9 +170,21 @@
var dropdownPaddingPx = caretPaddingPx + caretWidthPx + caretPaddingPx;
romoSelectDropdownElem.css('padding-'+caretPosition, dropdownPaddingPx+'px');
}
return romoSelectDropdownElem;
+}
+
+RomoSelect.prototype._onCaretClick = function(e) {
+ if (this.elem.prop('disabled') === false) {
+ this.romoSelectDropdown.elem.focus();
+ this.elem.trigger('select:triggerPopupOpen');
+ }
+}
+
+RomoSelect.prototype._setNewValue = function(newValue) {
+ this.elem[0].value = newValue;
+ this.doRefreshUI();
}
RomoSelect.prototype._getCaretPaddingPx = function() {
return (
this.elem.data('romo-select-caret-padding-px') ||