Commit 8454528e authored by Sindre Sorhus's avatar Sindre Sorhus

Dijon app - style cleanup

Add strict
Spacing and code style
Missing semicolons
Add jshint header comments
parent 7d7de006
......@@ -22,7 +22,7 @@
<button id="clear-completed">Clear completed</button>
</footer>
</section>
<footer id="info">
<footer id="info">
<p>Double-click to edit a todo</p>
<p>Based on app and template by <a href="http://sindresorhus.com">Sindre Sorhus</a></p>
<p>Created by <a href="http://www.creynders.be">Camille Reynders</a></p>
......@@ -42,14 +42,14 @@
</script>
<script src="../../../assets/jquery.min.js"></script>
<script src="../../../assets/handlebars.min.js"></script>
<script src="http://creynders.github.com/dijon-framework/bin/dijon-0.5.3.min.js"></script>
<script src="js/config.js"></script>
<script src="js/models/TodosModel.js"></script>
<script src="js/services/LocalStorageService.js"></script>
<script src="js/utils/Utils.js"></script>
<script src="js/views/FooterView.js"></script>
<script src="js/views/TodoFormView.js"></script>
<script src="js/views/TodoListView.js"></script>
<script src="js/lib/dijon-0.5.3.min.js"></script>
<script src="js/config.js"></script>
<script src="js/models/TodosModel.js"></script>
<script src="js/services/LocalStorageService.js"></script>
<script src="js/utils/Utils.js"></script>
<script src="js/views/FooterView.js"></script>
<script src="js/views/TodoFormView.js"></script>
<script src="js/views/TodoListView.js"></script>
<script src="js/app.js"></script>
</body>
</html>
</html>
\ No newline at end of file
/*global jQuery, Handlebars */
( function ( ns ) {
/*global dijon, dijondemo */
(function( ns ) {
'use strict';
ns.App = function () {
var system;
return {
startup:function () {
startup: function() {
system = new dijon.System();
system.mapValue( 'system', system );
system.mapOutlet( 'system' );
system.mapOutlet('system');
system.injectInto( new ns.Config() );
system.notify( 'App:startup' );
system.notify( 'App:startupComplete' );
system.notify('App:startup');
system.notify('App:startupComplete');
}
}
}
}( dijondemo ) );
};
};
}( dijondemo ));
dijondemo.app = new dijondemo.App();
dijondemo.app.startup();
\ No newline at end of file
......@@ -3,41 +3,42 @@
* Date: 03/02/12
* Time: 15:23
*/
var dijondemo = {};
( function ( ns ) {
(function( ns ) {
'use strict';
ns.views = {};
ns.models = {};
ns.controllers = {};
ns.services = {};
ns.utils = {};
ns.Config = function () {
return{
system:undefined, //inject
setup:function () {
ns.Config = function() {
return {
system: undefined, //inject
setup: function() {
this.system.autoMapOutlets = true;
//values
// Values
this.system.mapValue( 'enterKey', 13 );
this.system.mapValue( 'uuidUtil', ns.utils.Utils );
this.system.mapValue( 'pluralizeUtil', ns.utils.Utils );
//models
// Models
this.system.mapSingleton( 'todosModel', ns.models.TodosModel );
//services
// Services
this.system.mapSingleton( 'storageService', ns.services.LocalStorageService );
//views
// Views
this.system.mapSingleton( 'footerView', ns.views.FooterView );
this.system.mapSingleton( 'formView', ns.views.TodoFormView );
this.system.mapSingleton( 'listView', ns.views.TodoListView );
//handlers
//Handlers
this.system.mapHandler( 'TodoFormView:addTodo', 'todosModel', 'add' );
this.system.mapHandler( 'TodoListView:toggleDoneOfTodo', 'todosModel', 'toggleDone' );
this.system.mapHandler( 'TodoListView:setTitleOfTodo', 'todosModel', 'setTitle' );
......@@ -53,6 +54,7 @@ var dijondemo = {};
this.system.mapHandler( 'App:startupComplete', 'storageService', 'retrieve' );
}
}
}
}( dijondemo ) );
\ No newline at end of file
};
};
}( dijondemo ));
\ No newline at end of file
/*! dijon - v0.5.3 - 2012-04-23
* /
* Copyright (c) 2012 Camille Reynders (http://www.creynders.be/); Licensed MIT */
(function(a){"use strict";var b={VERSION:"0.5.3"};b.System=function(){this._mappings={},this._outlets={},this._handlers={},this.strictInjections=!0,this.autoMapOutlets=!1,this.postInjectionHook="setup"},b.System.prototype={_createAndSetupInstance:function(a,b){var c=new b;return this.injectInto(c,a),c},_retrieveFromCacheOrCreate:function(a,b){typeof b=="undefined"&&(b=!1);var c;if(!this._mappings.hasOwnProperty(a))throw new Error(1e3);var d=this._mappings[a];return!b&&d.isSingleton?(d.object==null&&(d.object=this._createAndSetupInstance(a,d.clazz)),c=d.object):d.clazz?c=this._createAndSetupInstance(a,d.clazz):c=d.object,c},mapOutlet:function(a,b,c){if(typeof a=="undefined")throw new Error(1010);return b=b||"global",c=c||a,this._outlets.hasOwnProperty(b)||(this._outlets[b]={}),this._outlets[b][c]=a,this},getObject:function(a){if(typeof a=="undefined")throw new Error(1020);return this._retrieveFromCacheOrCreate(a)},mapValue:function(a,b){if(typeof a=="undefined")throw new Error(1030);return this._mappings[a]={clazz:null,object:b,isSingleton:!0},this.autoMapOutlets&&this.mapOutlet(a),this.hasMapping(a)&&this.injectInto(b,a),this},hasMapping:function(a){if(typeof a=="undefined")throw new Error(1040);return this._mappings.hasOwnProperty(a)},mapClass:function(a,b){if(typeof a=="undefined")throw new Error(1050);if(typeof b=="undefined")throw new Error(1051);return this._mappings[a]={clazz:b,object:null,isSingleton:!1},this.autoMapOutlets&&this.mapOutlet(a),this},mapSingleton:function(a,b){if(typeof a=="undefined")throw new Error(1060);if(typeof b=="undefined")throw new Error(1061);return this._mappings[a]={clazz:b,object:null,isSingleton:!0},this.autoMapOutlets&&this.mapOutlet(a),this},instantiate:function(a){if(typeof a=="undefined")throw new Error(1070);return this._retrieveFromCacheOrCreate(a,!0)},injectInto:function(a,b){if(typeof a=="undefined")throw new Error(1080);if(typeof a=="object"){var c=[];this._outlets.hasOwnProperty("global")&&c.push(this._outlets.global),typeof b!="undefined"&&this._outlets.hasOwnProperty(b)&&c.push(this._outlets[b]);for(var d in c){var e=c[d];for(var f in e){var g=e[f];if(!this.strictInjections||f in a)a[f]=this.getObject(g)}}"setup"in a&&a.setup.call(a)}return this},unmap:function(a){if(typeof a=="undefined")throw new Error(1090);return delete this._mappings[a],this},unmapOutlet:function(a,b){if(typeof a=="undefined")throw new Error(1100);if(typeof b=="undefined")throw new Error(1101);return delete this._outlets[a][b],this},mapHandler:function(a,b,c,d,e){if(typeof a=="undefined")throw new Error(1110);return b=b||"global",c=c||a,typeof d=="undefined"&&(d=!1),typeof e=="undefined"&&(e=!1),this._handlers.hasOwnProperty(a)||(this._handlers[a]={}),this._handlers[a].hasOwnProperty(b)||(this._handlers[a][b]=[]),this._handlers[a][b].push({handler:c,oneShot:d,passEvent:e}),this},unmapHandler:function(a,b,c){if(typeof a=="undefined")throw new Error(1120);b=b||"global",c=c||a;if(this._handlers.hasOwnProperty(a)&&this._handlers[a].hasOwnProperty(b)){var d=this._handlers[a][b];for(var e in d){var f=d[e];if(f.handler===c){d.splice(e,1);break}}}return this},notify:function(a){if(typeof a=="undefined")throw new Error(1130);var b=Array.prototype.slice.call(arguments),c=b.slice(1);if(this._handlers.hasOwnProperty(a)){var d=this._handlers[a];for(var e in d){var f=d[e],g;e!=="global"&&(g=this.getObject(e));var h=[],i,j;for(i=0,j=f.length;i<j;i++){var k,l=f[i];g&&typeof l.handler=="string"?k=g[l.handler]:k=l.handler,l.oneShot&&h.unshift(i),l.passEvent?k.apply(g,b):k.apply(g,c)}for(i=0,j=h.length;i<j;i++)f.splice(h[i],1)}}return this}},a.dijon=b})(this)
\ No newline at end of file
/*global dijondemo */
/**
* @author Camille Reynders
* Date: 03/02/12
* Time: 14:39
*/
( function ( ns ) {
ns.models.TodosModel = function () {
(function( ns ) {
'use strict';
ns.models.TodosModel = function() {
var _list = [];
return {
system:undefined, //inject,
getTodo:function ( id ) {
system: undefined, //inject,
getTodo: function( id ) {
return _list[ this.getIndex( id ) ];
},
getIndex:function ( id ) {
getIndex: function( id ) {
var list = _list,
todo;
for ( var i in _list ) {
todo,
i;
for ( i in _list ) {
todo = _list[ i ];
if ( todo.id == id ) {
if ( todo.id === id ) {
return i;
}
}
return -1;
},
notifyOfListUpdate:function () {
notifyOfListUpdate: function() {
var list = this.getList();
this.system.notify( 'TodosModel:todosListUpdated', list );
},
setList:function ( list ) {
setList: function( list ) {
_list = list || [];
this.system.notify( 'TodosModel:todosListUpdated', list );
},
getList:function () {
getList: function() {
return _list;
},
add:function ( vo ) {
add: function( vo ) {
_list.push( vo );
this.notifyOfListUpdate();
},
toggleDone:function ( id ) {
toggleDone: function( id ) {
var todo = this.getTodo( id );
todo.completed = !todo.completed;
this.notifyOfListUpdate();
},
setTitle:function ( id, title ) {
setTitle: function( id, title ) {
this.getTodo( id ).title = title;
this.notifyOfListUpdate();
},
remove:function ( id ) {
remove: function( id ) {
_list.splice( this.getIndex( id ), 1 );
this.notifyOfListUpdate();
},
setDoneForAll:function ( completed ) {
setDoneForAll: function( completed ) {
var i;
for ( i in _list ) {
_list[ i ].completed = completed;
}
this.notifyOfListUpdate();
},
removeAllDone:function () {
removeAllDone: function() {
var i,
n = 0;
for ( i = _list.length - 1 ; i >= n ; i-- ) {
......@@ -69,10 +73,10 @@
}
this.notifyOfListUpdate();
},
getNumTotal:function () {
getNumTotal: function() {
return _list.length;
},
getNumActive:function () {
getNumActive: function() {
var count = 0,
i;
for ( i in _list ) {
......@@ -82,7 +86,7 @@
}
return count;
}
};
};
}
}
}( dijondemo ) );
\ No newline at end of file
}( dijondemo ));
\ No newline at end of file
/*global dijondemo */
/**
* @author Camille Reynders
* Date: 03/02/12
* Time: 13:27
*/
( function ( ns ) {
dijondemo.services.LocalStorageService = function () {
(function( ns ) {
'use strict';
dijondemo.services.LocalStorageService = function() {
return {
system:undefined, //inject
store:function ( data ) {
system: undefined, //inject
store: function( data ) {
return localStorage.setItem( 'todos-dijon', JSON.stringify( data ) );
},
retrieve:function () {
retrieve: function() {
var data = localStorage.getItem( 'todos-dijon' ),
output = ( data && JSON.parse( data ) ) || [];
this.system.notify( 'StorageService:retrieveCompleted', output );
}
}
}
}( dijondemo ) )
\ No newline at end of file
};
};
}( dijondemo ));
\ No newline at end of file
/*global dijondemo */
/**
* @author Camille Reynders
* Date: 03/02/12
* Time: 14:34
*/
( function ( ns ) {
(function( ns ) {
'use strict';
ns.utils.Utils = {
// https://gist.github.com/1308368
uuid:function ( a, b ) {
uuid: function( a, b ) {
for ( b = a = '' ; a++ < 36 ; b += a * 51 & 52 ? (a ^ 15 ? 8 ^ Math.random() * (a ^ 20 ? 16 : 4) : 4).toString( 16 ) : '_' );
return b
return b;
},
pluralize:function ( count, word ) {
pluralize: function( count, word ) {
return count === 1 ? word : word + 's';
}
};
}( dijondemo ) );
\ No newline at end of file
}( dijondemo ));
\ No newline at end of file
/*global dijondemo, $ */
/**
* @author Camille Reynders
* Date: 03/02/12
* Time: 14:20
*/
( function ( ns ) {
ns.views.FooterView = function () {
var $count = $( '#todo-count' ),
$clearBtn = $( '#clear-completed' ),
$footer = $( '#todoapp' ).find( 'footer' );
(function( ns ) {
'use strict';
ns.views.FooterView = function() {
var $count = $('#todo-count'),
$clearBtn = $('#clear-completed'),
$footer = $('#todoapp').find('footer');
return {
system:undefined, //inject
pluralizeUtil:undefined, //inject,
todosModel : undefined, //inject
setup:function () {
system: undefined, //inject
pluralizeUtil: undefined, //inject,
todosModel: undefined, //inject
setup: function() {
var self = this;
$clearBtn.on( 'click', function () {
$clearBtn.on( 'click', function() {
self.system.notify( 'TodoListView:removeAllDoneTodos' );
} );
});
},
render:function () {
render: function() {
this.renderCounts( this.todosModel.getNumTotal(), this.todosModel.getNumActive() );
},
renderCounts:function ( numTodosTotal, numTodosActive ) {
renderCounts: function( numTodosTotal, numTodosActive ) {
var numTodosCompleted = numTodosTotal - numTodosActive,
countTitle = '<b>' + numTodosActive + '</b> ' + this.pluralizeUtil.pluralize( numTodosActive, 'item' ) + ' left',
countTitle = '<strong>' + numTodosActive + '</strong> ' + this.pluralizeUtil.pluralize( numTodosActive, 'item' ) + ' left',
clearTitle = 'Clear completed (' + numTodosCompleted + ')';
// Only show the footer when there are at least one todo.
$footer.toggle( !!numTodosTotal );
......@@ -37,6 +40,7 @@
// Toggle clear button and update title
$clearBtn.text( clearTitle ).toggle( !!numTodosCompleted );
}
}
}
}( dijondemo ) );
\ No newline at end of file
};
};
}( dijondemo ));
\ No newline at end of file
/*global dijondemo, $ */
/**
* @author Camille Reynders
* Date: 03/02/12
* Time: 13:38
*/
( function ( ns ) {
ns.views.TodoFormView = function () {
var $newTodo = $( '#new-todo' );
(function( ns ) {
'use strict';
ns.views.TodoFormView = function() {
var $newTodo = $('#new-todo');
return {
system:undefined, //inject
enterKey:undefined, //inject
uuidUtil:undefined, //inject
setup:function () {
system: undefined, //inject
enterKey: undefined, //inject
uuidUtil: undefined, //inject
setup: function() {
var self = this;
$newTodo.on( 'keyup', function ( e ) {
$newTodo.on( 'keyup', function( e ) {
var $input = $( this ),
val = $.trim( $input.val() );
if ( e.which !== self.enterKey || !val ) {
return;
}
self.system.notify( 'TodoFormView:addTodo', {
title:val,
id:self.uuidUtil.uuid(),
completed:false
title: val,
id: self.uuidUtil.uuid(),
completed: false
} );
$input.val( '' );
$input.val('');
} );
},
render:function () {
render: function() {}
};
};
}
}
}
}( dijondemo ))
\ No newline at end of file
}( dijondemo ));
\ No newline at end of file
/*global dijondemo, $, Handlebars */
/**
* @author Camille Reynders
* Date: 03/02/12
* Time: 13:39
*/
( function ( ns ) {
ns.views.TodoListView = function () {
var _template = Handlebars.compile( $( '#todo-template' ).html() );
var $toggleAll = $( '#toggle-all' );
var $todoList = $( '#todo-list' );
var $main = $( '#main' );
var $count = $( '#todo-count' );
(function( ns ) {
'use strict';
ns.views.TodoListView = function() {
var _template = Handlebars.compile( $('#todo-template').html() ),
$toggleAll = $('#toggle-all'),
$todoList = $('#todo-list'),
$main = $('#main'),
$count = $('#todo-count');
return {
system:undefined, //inject
enterKey:undefined,
todosModel : undefined, //inject
setup:function () {
system: undefined, //inject
enterKey: undefined,
todosModel: undefined, //inject
setup: function() {
var self = this;
$todoList.on( 'change', '.toggle', function () {
var id = $( this ).closest( 'li' ).data( 'id' );
$todoList.on( 'change', '.toggle', function() {
var id = $( this ).closest('li').data('id');
self.system.notify( 'TodoListView:toggleDoneOfTodo', id );
});
$todoList.on( 'dblclick', '.view', function() {
$( this ).closest('li').addClass('editing').find('.edit').focus();
} );
$todoList.on( 'dblclick', '.view', function () {
$( this )
.closest( 'li' )
.addClass( 'editing' )
.find( '.edit' )
.focus();
} );
$todoList.on( 'keypress', '.edit', function ( e ) {
if ( e.keyCode === self.enterKey ) {
$todoList.on( 'keypress', '.edit', function( e ) {
if ( e.which === self.enterKey ) {
e.target.blur();
}
} );
$todoList.on( 'blur', '.edit', function () {
var id = $( this ).closest( 'li' ).data( 'id' ),
val = $.trim( $( this ).removeClass( 'editing' ).val() );
if( val ){
});
$todoList.on( 'blur', '.edit', function() {
var id = $( this ).closest('li').data('id'),
val = $.trim( $( this ).removeClass('editing').val() );
if ( val ){
self.system.notify( 'TodoListView:setTitleOfTodo', id, val );
}else{
} else {
self.system.notify( 'TodoListView:removeTodo', id );
}
} );
$todoList.on( 'click', '.destroy', function () {
var id = $( this ).closest( 'li' ).data( 'id' );
});
$todoList.on( 'click', '.destroy', function() {
var id = $( this ).closest('li').data('id');
self.system.notify( 'TodoListView:removeTodo', id );
} );
$toggleAll.on( 'change', function () {
var isChecked = !!$( this ).attr( 'checked' );
});
$toggleAll.on( 'change', function() {
var isChecked = !!$( this ).prop('checked');
self.system.notify( 'TodoListView:setDoneForAllTodos', isChecked );
} );
});
},
render:function () {
render: function() {
var todoList = this.todosModel.getList();
$todoList.html( _template( todoList ) );
$main.toggle( !!todoList.length );
$toggleAll.prop( 'checked', !this.todosModel.getNumActive() );
}
}
}
}( dijondemo ))
\ No newline at end of file
};
};
}( dijondemo ));
\ No newline at end of file
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