Commit f7627310 authored by Pascal Hartig's avatar Pascal Hartig

Merge pull request #868 from stephenplusplus/gh-pages

[angularjs] use module instead of global variable.
parents ccb41288 b645c677
/*global angular */ /*global angular */
/*jshint unused:false */
'use strict';
/** /**
* The main TodoMVC app module * The main TodoMVC app module
* *
* @type {angular.Module} * @type {angular.Module}
*/ */
var todomvc = angular.module('todomvc', ['ngRoute']) angular.module('todomvc', ['ngRoute'])
.config(function ($routeProvider) { .config(function ($routeProvider) {
'use strict';
$routeProvider.when('/', { $routeProvider.when('/', {
controller: 'TodoCtrl', controller: 'TodoCtrl',
templateUrl: 'todomvc-index.html' templateUrl: 'todomvc-index.html'
......
/*global todomvc, angular */ /*global angular */
'use strict';
/** /**
* The main controller for the app. The controller: * The main controller for the app. The controller:
* - retrieves and persists the model via the todoStorage service * - retrieves and persists 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, $routeParams, todoStorage, filterFilter) { angular.module('todomvc')
.controller('TodoCtrl', function TodoCtrl($scope, $routeParams, todoStorage, filterFilter) {
'use strict';
var todos = $scope.todos = todoStorage.get(); var todos = $scope.todos = todoStorage.get();
$scope.newTodo = ''; $scope.newTodo = '';
...@@ -79,4 +81,4 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $routeParams, todoStora ...@@ -79,4 +81,4 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $routeParams, todoStora
todo.completed = !completed; todo.completed = !completed;
}); });
}; };
}); });
/*global todomvc */ /*global angular */
'use strict';
/** /**
* Directive that executes an expression when the element it is applied to gets * Directive that executes an expression when the element it is applied to gets
* an `escape` keydown event. * an `escape` keydown event.
*/ */
todomvc.directive('todoEscape', function () { angular.module('todomvc')
.directive('todoEscape', function () {
'use strict';
var ESCAPE_KEY = 27; var ESCAPE_KEY = 27;
return function (scope, elem, attrs) { return function (scope, elem, attrs) {
elem.bind('keydown', function (event) { elem.bind('keydown', function (event) {
if (event.keyCode === ESCAPE_KEY) { if (event.keyCode === ESCAPE_KEY) {
...@@ -14,4 +17,4 @@ todomvc.directive('todoEscape', function () { ...@@ -14,4 +17,4 @@ todomvc.directive('todoEscape', function () {
} }
}); });
}; };
}); });
/*global todomvc */ /*global angular */
'use strict';
/** /**
* Directive that places focus on the element it is applied to when the * Directive that places focus on the element it is applied to when the
* expression it binds to evaluates to true * expression it binds to evaluates to true
*/ */
todomvc.directive('todoFocus', function todoFocus($timeout) { angular.module('todomvc')
.directive('todoFocus', function todoFocus($timeout) {
'use strict';
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) {
...@@ -15,4 +17,4 @@ todomvc.directive('todoFocus', function todoFocus($timeout) { ...@@ -15,4 +17,4 @@ todomvc.directive('todoFocus', function todoFocus($timeout) {
} }
}); });
}; };
}); });
/*global todomvc */ /*global angular */
'use strict';
/** /**
* Services that persists and retrieves TODOs from localStorage * Services that persists and retrieves TODOs from localStorage
*/ */
todomvc.factory('todoStorage', function () { angular.module('todomvc')
.factory('todoStorage', function () {
'use strict';
var STORAGE_ID = 'todos-angularjs'; var STORAGE_ID = 'todos-angularjs';
return { return {
...@@ -16,4 +18,4 @@ todomvc.factory('todoStorage', function () { ...@@ -16,4 +18,4 @@ todomvc.factory('todoStorage', function () {
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