Commit 6e43c8dd authored by Pascal Hartig's avatar Pascal Hartig

AngularJS + require.js: jshint style

parent 9b5e8b15
<!doctype html> <!doctype html>
<html lang="en"> <html lang="en">
<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>
...@@ -16,9 +16,8 @@ ...@@ -16,9 +16,8 @@
(c) 2010-2012 Google, Inc. http://angularjs.org (c) 2010-2012 Google, Inc. http://angularjs.org
License: MIT License: MIT
*/ */
(function(i){'use strict';function d(c,b,e){return c[b]||(c[b]=e())}return d(d(i,"angular",Object),"module",function(){var c={};return function(b,e,f){e&&c.hasOwnProperty(b)&&(c[b]=null);return d(c,b,function(){function a(a,b,d){return function(){c[d||"push"]([a,b,arguments]);return g}}if(!e)throw Error("No module: "+b);var c=[],d=[],h=a("$injector","invoke"),g={_invokeQueue:c,_runBlocks:d,requires:e,name:b,provider:a("$provide","provider"),factory:a("$provide","factory"),service:a("$provide","service"), (function(i){'use strict';function d(c,b,e){return c[b]||(c[b]=e())}return d(d(i,"angular",Object),"module",function(){var c={};return function(b,e,f){e&&c.hasOwnProperty(b)&&(c[b]=null);return d(c,b,function(){function a(a,b,d){return function(){c[d||"push"]([a,b,arguments]);return g}}if(!e)throw Error("No module: "+b);var c=[],d=[],h=a("$injector","invoke"),g={_invokeQueue:c,_runBlocks:d,requires:e,name:b,provider:a("$provide","provider"),factory:a("$provide","factory"),service:a("$provide","service"), value:a("$provide","value"),constant:a("$provide","constant","unshift"),filter:a("$filterProvider","register"),controller:a("$controllerProvider","register"),directive:a("$compileProvider","directive"),config:h,run:function(a){d.push(a);return this}};f&&h(f);return g})}})})(window);
value:a("$provide","value"),constant:a("$provide","constant","unshift"),filter:a("$filterProvider","register"),controller:a("$controllerProvider","register"),directive:a("$compileProvider","directive"),config:h,run:function(a){d.push(a);return this}};f&&h(f);return g})}})})(window); </script>
</script>
</head> </head>
<body> <body>
<section id="todoapp" ng-controller="TodoController"> <section id="todoapp" ng-controller="TodoController">
......
/*global define*/
'use strict'; 'use strict';
define(['angular'], function (angular) { define(['angular'], function (angular) {
......
/*global define*/
'use strict'; 'use strict';
/** /**
...@@ -8,31 +9,34 @@ ...@@ -8,31 +9,34 @@
define(['app', 'services/todoStorage'], function (app) { define(['app', 'services/todoStorage'], function (app) {
return app.controller('TodoController', ['$scope', '$location', 'todoStorage', 'filterFilter', return app.controller('TodoController', ['$scope', '$location', 'todoStorage', 'filterFilter',
function TodoController( $scope, $location, todoStorage, filterFilter ) { function TodoController($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;
} }
...@@ -45,33 +49,33 @@ define(['app', 'services/todoStorage'], function (app) { ...@@ -45,33 +49,33 @@ define(['app', 'services/todoStorage'], function (app) {
}; };
$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 define*/
'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.
*/ */
define(['app'], function ( app ) { define(['app'], function (app) {
app.directive('todoBlur', function() { app.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 define*/
'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.
*/ */
define(['app'], function ( app ) { define(['app'], function (app) {
app.directive('todoFocus', ['$timeout', function( $timeout ) { app.directive('todoFocus', ['$timeout', function ($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 require*/
'use strict'; 'use strict';
require.config({ require.config({
......
/*global define*/
'use strict'; 'use strict';
/** /**
* Services that persists and retrieves TODOs from localStorage. * Services that persists and retrieves TODOs from localStorage.
*/ */
define(['app'], function (app) { define(['app'], function (app) {
app.factory( 'todoStorage', function() { app.factory('todoStorage', function () {
var STORAGE_ID = 'todos-angularjs-requirejs'; var STORAGE_ID = 'todos-angularjs-requirejs';
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