// Generated by github.com/steida/coffee2closure 0.1.12 goog.provide('spark.components.TextareaWithCharCounter'); goog.require('spark.components.Textarea'); goog.require('goog.ui.CharCounter'); /** Texarea component with built-in char counter like Twitter 140 char input. By default char limit is 140. See `charLimit` option. Counter element may be configured to be invisible. See `isCounterVisible` option. Default char counter is a remaining counter also it may be an incremental counter. See `showRemainingCount` option. By default the counter view will be appended to `document.body`. To change it see `counterContainer` option. @constructor @export @param {Object=} options Class options. @param {*=} data Class data @extends {spark.components.Textarea} */ spark.components.TextareaWithCharCounter = function(options, data) { var _ref, _ref1; if (options == null) { options = {}; } options.charLimit || (options.charLimit = options['charLimit'] || 140); options.counterContainer || (options.counterContainer = options['counterContainer'] || document.body); if (options.isCounterVisible == null) { options.isCounterVisible = (_ref = options['isCounterVisible']) != null ? _ref : true; } if (options.showRemainingCount == null) { options.showRemainingCount = (_ref1 = options['showRemainingCount']) != null ? _ref1 : true; } spark.components.TextareaWithCharCounter.superClass_.constructor.call(this, options, data); } goog.inherits(spark.components.TextareaWithCharCounter, spark.components.Textarea); /** @override */ spark.components.TextareaWithCharCounter.prototype.decorate_ = function() { var charLimit, charMode, counterContainer, counterEl, isCounterVisible, showRemainingCount, textareaEl, _ref; spark.components.TextareaWithCharCounter.superClass_.decorate_.apply(this, arguments); _ref = this.getOptions(), counterContainer = _ref.counterContainer, charLimit = _ref.charLimit, isCounterVisible = _ref.isCounterVisible, showRemainingCount = _ref.showRemainingCount; this.counterView = new spark.core.View({ cssClass: 'textarea-counter', renderTo: counterContainer }); if (!isCounterVisible) { this.counterView.addClass('hidden'); } counterEl = this.counterView.getElement(); textareaEl = this.getTextaraeElement_(); charMode = goog.ui.CharCounter.Display.REMAINING; if (!showRemainingCount) { charMode = goog.ui.CharCounter.Display.INCREMENTAL; } this.counter = new goog.ui.CharCounter(textareaEl, counterEl, charLimit, charMode); return this.counter.checkLength(); }; /** Returns the textarea element. This method should live here because of the return annotation, Compiler needs it. @private @return {HTMLTextAreaElement} */ spark.components.TextareaWithCharCounter.prototype.getTextaraeElement_ = function() { return this.textarea_.getElement(); }; /** Sets the value and triggers counter to check it's length. @export @override */ spark.components.TextareaWithCharCounter.prototype.setValue = function(value) { spark.components.TextareaWithCharCounter.superClass_.setValue.apply(this, arguments); if (this.counter) { return this.counter.checkLength(); } }; /** Set counter's max length. It can be modified on run time. If you set the new length to be less than the previous value, counter will update itself and it will also truncate the value in textbox if the textbox value's length is more than the new max length. @export @param {number} length Max length for counter. */ spark.components.TextareaWithCharCounter.prototype.setCharLimit = function(length) { return this.counter.setMaxLength(length); }; /** Returns counter view instance. @export @return {spark.core.View} */ spark.components.TextareaWithCharCounter.prototype.getCounterView = function() { return this.counterView; }; /** Destroy's the component and it's dependencies. @export @override */ spark.components.TextareaWithCharCounter.prototype.destroy = function() { if (!this.isDestroyed()) { this.counter.disposeInternal(); this.counter = null; this.getCounterView().destroy(); this.counterView = null; } return spark.components.TextareaWithCharCounter.superClass_.destroy.apply(this, arguments); };