Ember Latest
The latest build of Ember.
HTML
<script src="http://builds.emberjs.com/handlebars-1.0.0-rc.4.js"></script>
<script src="http://builds.emberjs.com/ember-latest.js"></script>
<script type="text/x-handlebars" data-template-name="application">
<h1>ember-latest jsfiddle</h1>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="posts">
{{outlet}}
<ul>
{{#each post in controller}}
<li>
{{#linkTo posts.show post}}
{{post.title}}
{{/linkTo}}
</li>
{{/each}}
<li> {{#linkTo posts}}BACK{{/linkTo}}</li>
</ul>
</script>
<script type="text/x-handlebars" data-template-name="posts/show">
{{title}}
</script>
CSS
h1 { font-size: 1.6em; padding-bottom: 10px; }
h2 { font-size: 1.4em; }
ul { padding: 15px; font-size: 1.4em; color: green; }
JavaScript
App = Ember.Application.create({
LOG_TRANSITIONS: true
});
App.IndexRoute = Ember.Route.extend({
redirect: function(){
this.transitionTo('posts')
}
});
App.PostsRoute = Ember.Route.extend({
model: function(){
return [
{id: 1, title: "first"},
{id: 2, title: "second"}
];
}
});
App.Router.map(function(){
this.resource('posts',function(){
this.route('show', {path: '/:post_id'});
});
});
App.ApplicationController = Ember.Controller.extend({
currentPathChanged: function() {
var page;
// window.location gets updated later in the current run loop, so we will
// wait until the next run loop to inspect its value and make the call
// to track the page view
Ember.run.next(function() {
page = window.location.hash.length > 0 ?
window.location.hash.substring(1) :
window.location.pathname;
console.log(page);
});
}.observes('currentPath')
});