Commit 2daf0563 authored by Pascal Hartig's avatar Pascal Hartig

AngularJS: jshint style

parent f0c582c3
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
<!--[if IE]> <!--[if IE]>
<script src="../../assets/ie.js"></script> <script src="../../assets/ie.js"></script>
<![endif]--> <![endif]-->
</head> </head>
<body> <body>
<section id="todoapp" ng-controller="TodoCtrl"> <section id="todoapp" ng-controller="TodoCtrl">
......
/*global angular*/
/*jshint unused:false*/
'use strict'; 'use strict';
/** /**
......
/*global todomvc*/
'use strict'; 'use strict';
/** /**
...@@ -5,31 +6,32 @@ ...@@ -5,31 +6,32 @@
* - retrieves and persist the model via the todoStorage service * - retrieves and persist the model via the todoStorage service
* - exposes the model to the template and provides event handlers * - exposes the model to the template and provides event handlers
*/ */
todomvc.controller( 'TodoCtrl', function TodoCtrl( $scope, $location, todoStorage, filterFilter ) { todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage, filterFilter) {
var todos = $scope.todos = todoStorage.get(); var todos = $scope.todos = todoStorage.get();
$scope.newTodo = ""; $scope.newTodo = '';
$scope.editedTodo = null; $scope.editedTodo = null;
$scope.$watch('todos', function() { $scope.$watch('todos', function () {
$scope.remainingCount = filterFilter(todos, {completed: false}).length; $scope.remainingCount = filterFilter(todos, {completed: false}).length;
$scope.doneCount = todos.length - $scope.remainingCount; $scope.doneCount = todos.length - $scope.remainingCount;
$scope.allChecked = !$scope.remainingCount $scope.allChecked = !$scope.remainingCount;
todoStorage.put(todos); todoStorage.put(todos);
}, true); }, true);
if ( $location.path() === '' ) $location.path('/'); if ($location.path() === '') {
$location.path('/');
}
$scope.location = $location; $scope.location = $location;
$scope.$watch( 'location.path()', function( path ) { $scope.$watch('location.path()', function (path) {
$scope.statusFilter = (path == '/active') ? $scope.statusFilter = (path === '/active') ?
{ completed: false } : (path == '/completed') ? { completed: false } : (path === '/completed') ?
{ completed: true } : null; { completed: true } : null;
}); });
$scope.addTodo = function () {
$scope.addTodo = function() { if (!$scope.newTodo.length) {
if ( !$scope.newTodo.length ) {
return; return;
} }
...@@ -41,34 +43,29 @@ todomvc.controller( 'TodoCtrl', function TodoCtrl( $scope, $location, todoStorag ...@@ -41,34 +43,29 @@ todomvc.controller( 'TodoCtrl', function TodoCtrl( $scope, $location, todoStorag
$scope.newTodo = ''; $scope.newTodo = '';
}; };
$scope.editTodo = function (todo) {
$scope.editTodo = function( todo ) {
$scope.editedTodo = todo; $scope.editedTodo = todo;
}; };
$scope.doneEditing = function (todo) {
$scope.doneEditing = function( todo ) {
$scope.editedTodo = null; $scope.editedTodo = null;
if ( !todo.title ) { if (!todo.title) {
$scope.removeTodo(todo); $scope.removeTodo(todo);
} }
}; };
$scope.removeTodo = function (todo) {
$scope.removeTodo = function( todo ) {
todos.splice(todos.indexOf(todo), 1); todos.splice(todos.indexOf(todo), 1);
}; };
$scope.clearDoneTodos = function () {
$scope.clearDoneTodos = function() { $scope.todos = todos = todos.filter(function (val) {
$scope.todos = todos = todos.filter(function( val ) {
return !val.completed; return !val.completed;
}); });
}; };
$scope.markAll = function (done) {
$scope.markAll = function( done ) { todos.forEach(function (todo) {
todos.forEach(function( todo ) {
todo.completed = done; todo.completed = done;
}); });
}; };
......
/*global todomvc*/
'use strict'; 'use strict';
/** /**
* Directive that executes an expression when the element it is applied to loses focus. * Directive that executes an expression when the element it is applied to loses focus.
*/ */
todomvc.directive('todoBlur', function() { todomvc.directive('todoBlur', function () {
return function( scope, elem, attrs ) { return function (scope, elem, attrs) {
elem.bind('blur', function() { elem.bind('blur', function () {
scope.$apply(attrs.todoBlur); scope.$apply(attrs.todoBlur);
}); });
}; };
......
/*global todomvc*/
'use strict'; 'use strict';
/** /**
* Directive that places focus on the element it is applied to when the expression it binds to evaluates to true. * Directive that places focus on the element it is applied to when the expression it binds to evaluates to true.
*/ */
todomvc.directive('todoFocus', function( $timeout ) { todomvc.directive('todoFocus', function todoFocus($timeout) {
return function( scope, elem, attrs ) { return function (scope, elem, attrs) {
scope.$watch(attrs.todoFocus, function( newval ) { scope.$watch(attrs.todoFocus, function (newval) {
if ( newval ) { if (newval) {
$timeout(function() { $timeout(function () {
elem[0].focus(); elem[0].focus();
}, 0, false); }, 0, false);
} }
......
/*global todomvc*/
'use strict'; 'use strict';
/** /**
* Services that persists and retrieves TODOs from localStorage. * Services that persists and retrieves TODOs from localStorage.
*/ */
todomvc.factory( 'todoStorage', function() { todomvc.factory('todoStorage', function () {
var STORAGE_ID = 'todos-angularjs'; var STORAGE_ID = 'todos-angularjs';
return { return {
get: function() { get: function () {
return JSON.parse(localStorage.getItem(STORAGE_ID) || '[]'); return JSON.parse(localStorage.getItem(STORAGE_ID) || '[]');
}, },
put: function( todos ) { put: function (todos) {
localStorage.setItem(STORAGE_ID, JSON.stringify(todos)); localStorage.setItem(STORAGE_ID, JSON.stringify(todos));
} }
}; };
......
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