Commit 687f280d authored by Sindre Sorhus's avatar Sindre Sorhus

Angular app - code style and some variable name fixes

parent 107c0e6c
<!doctype html> <!doctype html>
<html lang="en" ng-app="todomvc"> <html lang="en" ng-app="todomvc">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>AngularJS • TodoMVC</title> <title>AngularJS • TodoMVC</title>
<link rel="stylesheet" href="components/todomvc-common/base.css"> <link rel="stylesheet" href="components/todomvc-common/base.css">
<style>[ng-cloak] {display: none}</style> <style>[ng-cloak] {display: none}</style>
</head> </head>
<body> <body>
<section id="todoapp" ng-controller="TodoCtrl"> <section id="todoapp" ng-controller="TodoCtrl">
<header id="header"> <header id="header">
<h1>todos</h1> <h1>todos</h1>
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
<a ng-class="{selected: location.path() == '/completed'}" href="#/completed">Completed</a> <a ng-class="{selected: location.path() == '/completed'}" href="#/completed">Completed</a>
</li> </li>
</ul> </ul>
<button id="clear-completed" ng-click="clearDoneTodos()" ng-show="doneCount">Clear completed ({{doneCount}})</button> <button id="clear-completed" ng-click="clearCompletedTodos()" ng-show="completedCount">Clear completed ({{doneCount}})</button>
</footer> </footer>
</section> </section>
<footer id="info"> <footer id="info">
...@@ -66,5 +66,5 @@ ...@@ -66,5 +66,5 @@
<script src="js/services/todoStorage.js"></script> <script src="js/services/todoStorage.js"></script>
<script src="js/directives/todoFocus.js"></script> <script src="js/directives/todoFocus.js"></script>
<script src="js/directives/todoBlur.js"></script> <script src="js/directives/todoBlur.js"></script>
</body> </body>
</html> </html>
/*global angular*/ /*global angular */
/*jshint unused:false*/ /*jshint unused:false */
'use strict'; 'use strict';
/** /**
* The main TodoMVC app module. * The main TodoMVC app module
* *
* @type {angular.Module} * @type {angular.Module}
*/ */
......
/*global todomvc*/ /*global todomvc */
'use strict'; 'use strict';
/** /**
...@@ -14,7 +14,7 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage, ...@@ -14,7 +14,7 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage,
$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.completedCount = todos.length - $scope.remainingCount;
$scope.allChecked = !$scope.remainingCount; $scope.allChecked = !$scope.remainingCount;
todoStorage.put(todos); todoStorage.put(todos);
}, true); }, true);
...@@ -22,6 +22,7 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage, ...@@ -22,6 +22,7 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage,
if ($location.path() === '') { if ($location.path() === '') {
$location.path('/'); $location.path('/');
} }
$scope.location = $location; $scope.location = $location;
$scope.$watch('location.path()', function (path) { $scope.$watch('location.path()', function (path) {
...@@ -58,15 +59,15 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage, ...@@ -58,15 +59,15 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage,
todos.splice(todos.indexOf(todo), 1); todos.splice(todos.indexOf(todo), 1);
}; };
$scope.clearDoneTodos = function () { $scope.clearCompletedTodos = 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 (completed) {
todos.forEach(function (todo) { todos.forEach(function (todo) {
todo.completed = done; todo.completed = completed;
}); });
}; };
}); });
/*global todomvc*/ /*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) {
......
/*global todomvc*/ /*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 todoFocus($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*/ /*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';
......
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