Skip to content

Instantly share code, notes, and snippets.

@benolee
Created June 30, 2013 23:04
Show Gist options
  • Save benolee/5897362 to your computer and use it in GitHub Desktop.
Save benolee/5897362 to your computer and use it in GitHub Desktop.
the final countdown
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<script src="http://builds.emberjs.com.s3.amazonaws.com/handlebars-1.0.0-rc.4.js"></script>
<script src="http://builds.emberjs.com.s3.amazonaws.com/ember-1.0.0-rc.6.js"></script>
<meta charset=utf-8 />
<title></title>
</head>
<body>
<script>
(function() {
"use strict";
var Ember = this.Ember, $ = this.$;
var context = Ember.Object.create({
greeting: 'Hello, world!',
seconds: 3,
isDoneCounting: false
});
var View = Ember.View.extend({
template: Ember.Handlebars.compile('{{greeting}} {{#if isDoneCounting}}(message changed!){{else}}This message will change in {{seconds}}..{{/if}}')
});
var view = View.create({
context: context,
didInsertElement: function() {
console.info('omg I entered the DOM!');
}
});
view.appendTo($('body'));
function countDown() {
if (context.get('seconds') > 1) {
context.decrementProperty('seconds');
setTimeout(countDown, 1000);
} else {
context.set('greeting', 'Hola, mundo!')
.set('isDoneCounting', true);
}
}
this.setTimeout(countDown, 1000);
}).call(this);
</script>
</body>
</html>
@evantravers
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment