assets/js/romo/indicator_text_input.js in romo-0.17.0 vs assets/js/romo/indicator_text_input.js in romo-0.17.1

- old
+ new

@@ -36,32 +36,21 @@ // incorrectly remove the wrapper. Any value will do - I chose 1 arbitrarily. setTimeout($.proxy(function() { Romo.parentChildElems.add(this.elem, [elemWrapper]); }, this), 1); - this.elem.attr('autocomplete', 'off'); - this.indicatorElem = $(); var indicatorClass = this.elem.data('romo-indicator-text-input-indicator') || this.defaultIndicatorClass; if (indicatorClass !== undefined && indicatorClass !== 'none') { this.indicatorElem = $('<i class="romo-indicator-text-input-indicator '+indicatorClass+'"></i>'); - this.indicatorElem.css({'line-height': this.elem.css('height')}); - if (this.elem.prop('disabled') === true) { - this.indicatorElem.addClass('disabled'); - } - if (this.elem.css('display') === 'none') { - this._hide(this.indicatorElem); - } + this.elem.after(this.indicatorElem); this.indicatorElem.on('click', $.proxy(this.onIndicatorClick, this)); + this.doPlaceIndicatorElem(); - var indicatorWidthPx = this.elem.data('romo-indicator-text-input-indicator-width-px') || this.defaultIndicatorWidthPx; - // left-side spacing - // + indicator width - // + right-side spacing - var indicatorPaddingPx = 4 + indicatorWidthPx + 4; - this.elem.css({'padding-right': indicatorPaddingPx + 'px'}); - this.elem.after(this.indicatorElem); + this.elem.on('indicatorTextInput:triggerPlaceIndicator', $.proxy(function(e) { + this.doPlaceIndicatorElem(); + }, this)); } this.elem.on('indicatorTextInput:triggerEnable', $.proxy(function(e) { this.doEnable(); }, this)); @@ -74,10 +63,29 @@ this.elem.on('indicatorTextInput:triggerHide', $.proxy(function(e) { this.doHide(); }, this)); } +RomoIndicatorTextInput.prototype.doPlaceIndicatorElem = function() { + if (this.indicatorElem !== undefined) { + this.indicatorElem.css({'line-height': this.elem.css('height')}); + if (this.elem.prop('disabled') === true) { + this.indicatorElem.addClass('disabled'); + } + if (this.elem.css('display') === 'none') { + this._hide(this.indicatorElem); + } + + var indicatorWidthPx = this.elem.data('romo-indicator-text-input-indicator-width-px') || this.defaultIndicatorWidthPx; + // left-side spacing + // + indicator width + // + right-side spacing + var indicatorPaddingPx = 4 + indicatorWidthPx + 4; + this.elem.css({'padding-right': indicatorPaddingPx + 'px'}); + } +} + RomoIndicatorTextInput.prototype.doEnable = function() { this.elem.prop('disabled', false); this.elem.removeClass('disabled'); this.indicatorElem.removeClass('disabled'); } @@ -89,10 +97,11 @@ } RomoIndicatorTextInput.prototype.doShow = function() { this._show(this.elem); this._show(this.indicatorElem); + this.doPlaceIndicatorElem(); } RomoIndicatorTextInput.prototype.doHide = function() { this._hide(this.elem); this._hide(this.indicatorElem); @@ -103,9 +112,10 @@ e.preventDefault(); e.stopPropagation(); } if (this.elem.prop('disabled') === false) { this.elem.focus(); + this.elem.trigger('indicatorTextInput:indicatorClick'); } } // private