{I" class:ETI"ProcessedAsset;FI"logical_path;TI"outpost/field_counter.js;FI" pathname;TI"`/Users/bricker/websites/kpcc/outpost/app/assets/javascripts/outpost/field_counter.js.coffee;FI"content_type;TI"application/javascript;TI" mtime;Tl+d}RI" length;Ti I" digest;TI"%953d1af3da17cad0976f03c68965936e;FI" source;TI" (function() { $(function() { var el, field, fuzziness, target, _i, _len, _ref, _results; _ref = $("form .field-counter"); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { field = _ref[_i]; el = $(field); target = el.attr("data-target"); fuzziness = el.attr("data-fuzziness"); _results.push(new outpost.FieldCounter(el, { target: target, fuzziness: fuzziness })); } return _results; }); outpost.FieldCounter = (function() { FieldCounter.prototype.DefaultOptions = { target: 145, fuzziness: 20, inRangeClass: "alert alert-success", outOfRangeClass: "alert alert-warning", counterClass: "counter-notify", counterWrapper: ".controls", counterStyle: "padding: 3px; margin: 0 0 2px 0;" }; function FieldCounter(el, options) { this.el = el; if (options == null) { options = {}; } this.options = _.defaults(options, this.DefaultOptions); this.field = $("input, textarea", this.el); this.counterEl = $("
", { "class": this.options.counterClass, style: this.options.counterStyle }); $(this.options.counterWrapper, this.el).prepend(this.counterEl); this.count = 0; this.target = parseInt(this.options.target); this.fuzziness = parseInt(this.options.fuzziness); this.rangeLow = this.target - this.fuzziness; this.rangeHigh = this.target + this.fuzziness; this.inRangeClass = this.options.inRangeClass; this.outOfRangeClass = this.options.outOfRangeClass; this.field.on({ keyup: (function(_this) { return function(event) { return _this.updateCount($(event.target).val().length); }; })(this) }); this.el.on({ updateCounter: (function(_this) { return function(event, count) { _this.updateText(count); return _this.updateColor(count); }; })(this) }); this.updateCount(this.field.val().length); } FieldCounter.prototype.inRange = function() { return this.rangeLow <= this.count && this.count <= this.rangeHigh; }; FieldCounter.prototype.updateCount = function(length) { this.count = length; return this.el.trigger("updateCounter", this.count); }; FieldCounter.prototype.updateText = function(count) { return this.counterEl.html("Optimal Length: " + count + " of " + this.target + " (+/- " + this.fuzziness + ")"); }; FieldCounter.prototype.updateColor = function(count) { if (this.inRange()) { this.counterEl.removeClass(this.outOfRangeClass); return this.counterEl.addClass(this.inRangeClass); } else { this.counterEl.removeClass(this.inRangeClass); return this.counterEl.addClass(this.outOfRangeClass); } }; return FieldCounter; })(); }).call(this); ;TI"dependency_digest;TI"%c8fad88fc72af0d5ddbc3e27f367515d;FI"required_paths;T[I"`/Users/bricker/websites/kpcc/outpost/app/assets/javascripts/outpost/field_counter.js.coffee;FI"dependency_paths;T[{I" path;TI"`/Users/bricker/websites/kpcc/outpost/app/assets/javascripts/outpost/field_counter.js.coffee;FI" mtime;TI"2013-11-08T18:26:44-08:00;TI" digest;TI"%67b22a0b4e62f27830b2f25080ccdd37;FI" _version;TI"%1005ed9f20e25fb0a0599a7017dd0e6b;F