Commit 33e1cf94 authored by Sindre Sorhus's avatar Sindre Sorhus

Angular perf - code style

parent ad9e0238
......@@ -46,7 +46,7 @@
<a ng-class="{selected: location.path() == '/completed'}" href="#/completed">Completed</a>
</li>
</ul>
<button id="clear-completed" ng-click="clearDoneTodos()" ng-show="remainingCount < todos.length">Clear completed ({{todos.length - remainingCount}})</button>
<button id="clear-completed" ng-click="clearCompletedTodos()" ng-show="remainingCount < todos.length">Clear completed ({{todos.length - remainingCount}})</button>
</footer>
</section>
<footer id="info">
......
/*global angular*/
/*jshint unused:false*/
/*global angular */
/*jshint unused:false */
'use strict';
/**
* The main TodoMVC app module.
* The main TodoMVC app module
*
* @type {angular.Module}
*/
......
/*global todomvc*/
/*global todomvc */
'use strict';
/**
......@@ -16,6 +16,7 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage,
if ($location.path() === '') {
$location.path('/');
}
$scope.location = $location;
$scope.$watch('location.path()', function (path) {
......@@ -28,7 +29,6 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage,
$scope.allChecked = val;
});
$scope.addTodo = function () {
if ($scope.newTodo.length === 0) {
return;
......@@ -44,28 +44,26 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage,
$scope.remainingCount++;
};
$scope.editTodo = function (todo) {
$scope.editedTodo = todo;
};
$scope.doneEditing = function (todo) {
$scope.editedTodo = null;
if (!todo.title) {
$scope.removeTodo(todo);
}
todoStorage.put(todos);
};
$scope.removeTodo = function (todo) {
$scope.remainingCount -= todo.completed ? 0 : 1;
todos.splice(todos.indexOf(todo), 1);
todoStorage.put(todos);
};
$scope.todoCompleted = function (todo) {
if (todo.completed) {
$scope.remainingCount--;
......@@ -75,20 +73,18 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage,
todoStorage.put(todos);
};
$scope.clearDoneTodos = function () {
$scope.clearCompletedTodos = function () {
$scope.todos = todos = todos.filter(function (val) {
return !val.completed;
});
todoStorage.put(todos);
};
$scope.markAll = function (done) {
$scope.markAll = function (completed) {
todos.forEach(function (todo) {
todo.completed = done;
todo.completed = completed;
});
$scope.remainingCount = done ? 0 : todos.length;
$scope.remainingCount = completed ? 0 : todos.length;
todoStorage.put(todos);
};
});
/*global todomvc*/
/*global todomvc */
'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 () {
return function (scope, elem, attrs) {
......
/*global todomvc*/
/*global todomvc */
'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) {
return function (scope, elem, attrs) {
scope.$watch(attrs.todoFocus, function (newval) {
if (newval) {
scope.$watch(attrs.todoFocus, function (newVal) {
if (newVal) {
$timeout(function () {
elem[0].focus();
}, 0, false);
......
/*global todomvc*/
/*global todomvc */
'use strict';
/**
* Services that persists and retrieves TODOs from localStorage.
* Services that persists and retrieves TODOs from localStorage
*/
todomvc.factory('todoStorage', function () {
var STORAGE_ID = 'todos-angularjs-perf';
......
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