Permalink
Browse files

Several small changes

* Remove `init` and replace it with use of the
  `classNames` concatenated property
* Eliminate dependency on the Handlebars compiler
  at runtime
  • Loading branch information...
1 parent cd62d9f commit 783580fe82ca12e26bc1efd71925139631e6e05f @wycats committed Sep 23, 2012
Showing with 22 additions and 13 deletions.
  1. +22 −13 lib/BarView.js
View
@@ -1,25 +1,34 @@
Ember.ProgressBars = Ember.ProgressBars || {};
Ember.ProgressBars.Bar = Ember.View.extend({
- template: Em.Handlebars.compile('<div class="bar" {{bindAttr class="statusClass"}}></div>'),
+ classNames: 'progress',
+
+ template: function(context) {
+ var statusClass = context.get('statusClass');
+ return "<div class='bar" + (statusClass ? " " + statusClass : '') + "'></div>";
+ },
percent: 0,
status: undefined,
- init: function() {
- var classNames = this.get('classNames') || [];
- classNames.push('progress');
- this.set('classNames', classNames);
- return this._super.apply(this, arguments);
- },
-
- onPercentChange: function() {
+ percentDidChange: Ember.observer(function() {
var percent = this.get('percent') || 0;
- this.$('.bar').css('width', "%@%".fmt(percent) );
- }.observes('percent'),
+ this.$('.bar').css('width', percent + "%");
+ }, 'percent'),
statusClass: Ember.computed(function() {
var status = this.get('status');
- return status == null ? '' : 'bar-%@'.fmt(status);
- }).property('status').cacheable()
+ return status == null ? '' : 'bar-' + status;
+ }).property('status').cacheable(),
+
+ // This is more annoying than doing the same thing in a template,
+ // but it eliminates a dependency on the Handlebars compiler at
+ // runtime.
+ statusClassWillChange: Ember.beforeObserver(function() {
+ this.$('.bar').removeClass(this.get('statusClass'));
+ }, 'statusClass'),
+
+ statusClassDidChange: Ember.observer(function() {
+ this.$('.bar').addClass(this.get('statusClass'));
+ }, 'statusClass')
});

0 comments on commit 783580f

Please sign in to comment.