Sha256: f249c5f5321c731dc9148d10cd5413632d38c1fa4d6890dec78c67b3353eb8b7
Contents?: true
Size: 1.93 KB
Versions: 19
Compression:
Stored size: 1.93 KB
Contents
(function() { var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; Backbone.Poised.Value = (function(superClass) { extend(Value, superClass); function Value() { this.render = bind(this.render, this); this.initialize = bind(this.initialize, this); return Value.__super__.constructor.apply(this, arguments); } Value.prototype.tagName = 'span'; Value.prototype.className = 'poised value'; Value.prototype.initialize = function(options) { if (options == null) { options = {}; } if (options.model == null) { throw new Error('Missing `model` option'); } if (options.attribute == null) { throw new Error('Missing `attribute` option'); } this.attribute = options.attribute; this.options = _.chain(options).pick('unit', 'precision').value(); return this.model.on("change:" + this.attribute, this.render); }; Value.prototype.value = function() { var v; v = this.model.get(this.attribute); if (typeof v === 'number' && isNaN(v)) { return '-'; } else if (this.options.precision != null) { return this.model.get(this.attribute).toFixed(this.options.precision); } else { return v; } }; Value.prototype.unit = function() { if (this.options.unit) { return " " + this.options.unit; } else { return ''; } }; Value.prototype.render = function() { this.$el.html("" + (this.value()) + (this.unit())); return this; }; return Value; })(Backbone.Poised.View); }).call(this);
Version data entries
19 entries across 19 versions & 1 rubygems