Commit ffff5854 authored by Sindre Sorhus's avatar Sindre Sorhus

PlastronJS app: Tweaks

parent 5f8b7fa0
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<title>PlastronJS • TodoMVC</title> <title>PlastronJS • TodoMVC</title>
<link rel="stylesheet" href="../../../assets/base.css"> <link rel="stylesheet" href="../../../assets/base.css">
<style type="text/css"> <style>
#filters.none li.none, #filters.none li.none,
#filters.active li.active, #filters.active li.active,
#filters.completed li.completed { #filters.completed li.completed {
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
</section> </section>
<footer id="info"> <footer id="info">
<p>Double-click to edit a todo</p> <p>Double-click to edit a todo</p>
<p>Created by <a href="http://rhysbrettbowen.com">Rhys Brett-Bowen</a> (<a href="https://twitter.com/#!/RhysBB">RhysBB</a>)</p> <p>Created by <a href="http://rhysbrettbowen.com">Rhys Brett-Bowen</a> (<a href="https://twitter.com/RhysBB">RhysBB</a>)</p>
<p>Using <a href="https://github.com/rhysbrettbowen/PlastronJS">PlastronJS</a> and <a href="https://developers.google.com/closure/">Closure Tools</a></p> <p>Using <a href="https://github.com/rhysbrettbowen/PlastronJS">PlastronJS</a> and <a href="https://developers.google.com/closure/">Closure Tools</a></p>
<p>Part of <a href="http://todomvc.com">TodoMVC</a></p> <p>Part of <a href="http://todomvc.com">TodoMVC</a></p>
</footer> </footer>
......
...@@ -24,5 +24,3 @@ router.route( '/active', function() { ...@@ -24,5 +24,3 @@ router.route( '/active', function() {
router.route( '/completed', function() { router.route( '/completed', function() {
todolist.set( 'filter', 'completed' ); todolist.set( 'filter', 'completed' );
}); });
/*global goog, mvc, todomvc */
goog.provide('todomvc.listcontrol'); goog.provide('todomvc.listcontrol');
goog.require('goog.events.KeyCodes'); goog.require('goog.events.KeyCodes');
......
/*global goog, mvc, soy, todomvc */
goog.provide('todomvc.todocontrol'); goog.provide('todomvc.todocontrol');
goog.require('goog.dom'); goog.require('goog.dom');
...@@ -44,19 +45,19 @@ todomvc.todocontrol.prototype.enterDocument = function() { ...@@ -44,19 +45,19 @@ todomvc.todocontrol.prototype.enterDocument = function() {
this.autobind('.toggle', '{$completed}'); this.autobind('.toggle', '{$completed}');
// Delete the model // Delete the model
this.click(function( e ) { this.click(function() {
model.dispose(); model.dispose();
}, '.destroy' ); }, '.destroy');
// keep label inline with title // keep label inline with title
this.autobind( 'label', '{$title}') this.autobind( 'label', '{$title}' );
var inputEl = this.getEls('.edit')[0]; var inputEl = this.getEls('.edit')[0];
// Dblclick to edit // Dblclick to edit
this.on( goog.events.EventType.DBLCLICK, function( e ) { this.on( goog.events.EventType.DBLCLICK, function() {
goog.dom.classes.add( this.getElement(), 'editing' ); goog.dom.classes.add( this.getElement(), 'editing' );
inputEl.focus(); inputEl.focus();
}, '.view' ); }, '.view');
// blur on enter // blur on enter
this.on( goog.events.EventType.KEYUP, function( e ) { this.on( goog.events.EventType.KEYUP, function( e ) {
...@@ -66,10 +67,10 @@ todomvc.todocontrol.prototype.enterDocument = function() { ...@@ -66,10 +67,10 @@ todomvc.todocontrol.prototype.enterDocument = function() {
}); });
// finish editing on blur // finish editing on blur
this.on( goog.events.EventType.BLUR, function( e ) { this.on( goog.events.EventType.BLUR, function() {
goog.dom.classes.remove( this.getElement(), 'editing' ); goog.dom.classes.remove( this.getElement(), 'editing' );
}); });
// bind the title and the edit input // bind the title and the edit input
this.autobind('.edit', '{$title}'); this.autobind( '.edit', '{$title}' );
}; };
/*global goog, mvc, todomvc */
goog.provide('todomvc.listmodel'); goog.provide('todomvc.listmodel');
goog.require('mvc.Collection'); goog.require('mvc.Collection');
...@@ -13,32 +14,32 @@ todomvc.listmodel = function() { ...@@ -13,32 +14,32 @@ todomvc.listmodel = function() {
var todosSchema = { var todosSchema = {
// number of completed // number of completed
'completed': { completed: {
get: function() { get: function() {
return this.getModels( 'completed' ).length; return this.getModels('completed').length;
}, },
models: true models: true
}, },
'allDone': { allDone: {
get: function() { get: function() {
return this.getLength() == this.getModels( 'completed' ).length; return this.getLength() === this.getModels( 'completed' ).length;
}, },
set: function( done ) { set: function( done ) {
goog.array.forEach( this.getModels( 'none' ), function( model ) { goog.array.forEach( this.getModels('none'), function( model ) {
model.set( 'completed', done ); model.set( 'completed', done );
}); });
}, },
models: true models: true
}, },
// number of active models // number of active models
'active': { active: {
get: function() { get: function() {
return this.getLength() - this.getModels( 'completed' ).length; return this.getLength() - this.getModels( 'completed' ).length;
}, },
models: true models: true
}, },
// the total // the total
'total': { total: {
get: function() { get: function() {
return this.getLength(); return this.getLength();
}, },
...@@ -47,10 +48,10 @@ todomvc.listmodel = function() { ...@@ -47,10 +48,10 @@ todomvc.listmodel = function() {
}; };
goog.base( this, { goog.base( this, {
'id': 'todos-plastronjs', id: 'todos-plastronjs',
'sync': new todomvc.listsync(), sync: new todomvc.listsync(),
'schema': todosSchema, schema: todosSchema,
'modelType': todomvc.todomodel modelType: todomvc.todomodel
}); });
// fetch from localstorage // fetch from localstorage
...@@ -63,14 +64,14 @@ goog.inherits( todomvc.listmodel, mvc.Collection ); ...@@ -63,14 +64,14 @@ goog.inherits( todomvc.listmodel, mvc.Collection );
todomvc.listmodel.Filter = { todomvc.listmodel.Filter = {
'none': function() { none: function() {
return true return true;
}, },
'active': function( model ) { active: function( model ) {
return !model.get('completed') return !model.get('completed');
}, },
'completed': function( model ) { completed: function( model ) {
return model.get('completed') return model.get('completed');
} }
}; };
...@@ -80,9 +81,9 @@ todomvc.listmodel.Filter = { ...@@ -80,9 +81,9 @@ todomvc.listmodel.Filter = {
* *
* @inheritDoc * @inheritDoc
*/ */
todomvc.listmodel.prototype.getModels = function(opt_filter) { todomvc.listmodel.prototype.getModels = function( optFilter ) {
return goog.base(this, 'getModels', return goog.base(this, 'getModels',
todomvc.listmodel.Filter[ opt_filter || this.get( 'filter' ) ] ); todomvc.listmodel.Filter[ optFilter || this.get('filter') ] );
}; };
...@@ -90,7 +91,7 @@ todomvc.listmodel.prototype.getModels = function(opt_filter) { ...@@ -90,7 +91,7 @@ todomvc.listmodel.prototype.getModels = function(opt_filter) {
* @return {Object} todos as json. * @return {Object} todos as json.
*/ */
todomvc.listmodel.prototype.toJson = function() { todomvc.listmodel.prototype.toJson = function() {
return goog.array.map( this.getModels( 'none' ), function( mod ) { return goog.array.map( this.getModels('none'), function( mod ) {
return mod.toJson(); return mod.toJson();
}); });
}; };
/*global goog, mvc, todomvc */
goog.provide('todomvc.listsync'); goog.provide('todomvc.listsync');
goog.require('mvc.LocalSync'); goog.require('mvc.LocalSync');
...@@ -16,7 +17,7 @@ goog.inherits( todomvc.listsync, mvc.LocalSync ); ...@@ -16,7 +17,7 @@ goog.inherits( todomvc.listsync, mvc.LocalSync );
/** /**
* @inheritDoc * @inheritDoc
*/ */
todomvc.listsync.prototype.read = function( model, opt_callback ) { todomvc.listsync.prototype.read = function( model ) {
var id = /** @type {string} */(model.get('id')); var id = /** @type {string} */(model.get('id'));
var todos = this.store_.get(id) || []; var todos = this.store_.get(id) || [];
goog.array.forEach(/** @type {Array} */(todos), goog.array.forEach(/** @type {Array} */(todos),
......
...@@ -42,7 +42,7 @@ and view the compiled version for the page by changing the bottom script src bac ...@@ -42,7 +42,7 @@ and view the compiled version for the page by changing the bottom script src bac
## Need help? ## Need help?
Message me on [twitter](https://twitter.com/#!/RhysBB) Message Rhys on [twitter](https://twitter.com/RhysBB)
## Credit ## Credit
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment