Skip to content

Commit

Permalink
PlastronJS app: Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 3, 2012
1 parent 5f8b7fa commit ffff585
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 34 deletions.
4 changes: 2 additions & 2 deletions labs/architecture-examples/plastronjs/index.html
Expand Up @@ -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 {
Expand Down Expand Up @@ -44,7 +44,7 @@ <h1>todos</h1>
</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>
Expand Down
2 changes: 0 additions & 2 deletions labs/architecture-examples/plastronjs/js/app.js
Expand Up @@ -24,5 +24,3 @@ router.route( '/active', function() {
router.route( '/completed', function() { router.route( '/completed', function() {
todolist.set( 'filter', 'completed' ); todolist.set( 'filter', 'completed' );
}); });


@@ -1,3 +1,4 @@
/*global goog, mvc, todomvc */
goog.provide('todomvc.listcontrol'); goog.provide('todomvc.listcontrol');


goog.require('goog.events.KeyCodes'); goog.require('goog.events.KeyCodes');
Expand Down
@@ -1,3 +1,4 @@
/*global goog, mvc, soy, todomvc */
goog.provide('todomvc.todocontrol'); goog.provide('todomvc.todocontrol');


goog.require('goog.dom'); goog.require('goog.dom');
Expand Down Expand Up @@ -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 ) {
Expand All @@ -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}' );
}; };
43 changes: 22 additions & 21 deletions labs/architecture-examples/plastronjs/js/models/listmodel.js
@@ -1,3 +1,4 @@
/*global goog, mvc, todomvc */
goog.provide('todomvc.listmodel'); goog.provide('todomvc.listmodel');


goog.require('mvc.Collection'); goog.require('mvc.Collection');
Expand All @@ -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();
}, },
Expand All @@ -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
Expand All @@ -63,34 +64,34 @@ 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');
} }
}; };




/** /**
* return models based on current filter or filter given * return models based on current filter or filter given
* *
* @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') ] );
}; };




/** /**
* @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();
}); });
}; };
3 changes: 2 additions & 1 deletion labs/architecture-examples/plastronjs/js/sync/listsync.js
@@ -1,3 +1,4 @@
/*global goog, mvc, todomvc */
goog.provide('todomvc.listsync'); goog.provide('todomvc.listsync');


goog.require('mvc.LocalSync'); goog.require('mvc.LocalSync');
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion labs/architecture-examples/plastronjs/readme.md
Expand Up @@ -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
Expand Down

0 comments on commit ffff585

Please sign in to comment.