Commit 3dd6105b authored by Pascal Hartig's avatar Pascal Hartig

Merge branch 'pr/1103'

Close #1103
parents e5adfb0c 189da5c8
node_modules/angular/*
!node_modules/angular/angular.js
node_modules/angularfire/*
node_modules/angularfire/dist/*
!node_modules/angularfire/dist/angularfire.js
node_modules/todomvc-app-css/*
!node_modules/todomvc-app-css/index.css
node_modules/todomvc-common/*
!node_modules/todomvc-common/base.css
!node_modules/todomvc-common/base.js
{
"name": "todomvc-angular",
"version": "0.0.0",
"dependencies": {
"angular": "1.2.8",
"angularfire": "~0.5.0",
"todomvc-common": "~0.3.0"
},
"devDependencies": {
"angular-mocks": "1.2.8"
},
"resolutions": {
"angular": "1.2.8"
}
}
{
"name": "angular",
"version": "1.2.8",
"main": "./angular.js",
"dependencies": {
}
}
......@@ -3,7 +3,8 @@
<head>
<meta charset="utf-8">
<title>Firebase &amp; AngularJS • TodoMVC</title>
<link rel="stylesheet" href="bower_components/todomvc-common/base.css">
<link rel="stylesheet" href="node_modules/todomvc-common/base.css">
<link rel="stylesheet" href="node_modules/todomvc-app-css/index.css">
<style>[ng-cloak] { display: none; }</style>
</head>
<body>
......@@ -20,12 +21,12 @@
<ul id="todo-list">
<li ng-repeat="(id, todo) in todos | todoFilter" ng-class="{completed: todo.completed, editing: todo == editedTodo}">
<div class="view">
<input class="toggle" type="checkbox" ng-model="todo.completed" ng-change="todos.$save(id)">
<label ng-dblclick="editTodo(id)">{{todo.title}}</label>
<button class="destroy" ng-click="removeTodo(id)"></button>
<input class="toggle" type="checkbox" ng-model="todo.completed" ng-change="todos.$save(todo)">
<label ng-dblclick="editTodo(todo)">{{todo.title}}</label>
<button class="destroy" ng-click="removeTodo(todo)"></button>
</div>
<form ng-submit="doneEditing(id)">
<input class="edit" ng-model="todo.title" todo-escape="revertEditing(id)" todo-blur="doneEditing(id)" todo-focus="todo == editedTodo">
<form ng-submit="doneEditing(todo)">
<input class="edit" ng-model="todo.title" todo-escape="revertEditing(todo)" todo-blur="doneEditing(todo)" todo-focus="todo == editedTodo">
</form>
</li>
</ul>
......@@ -53,15 +54,16 @@
<p>Credits:
<a href="http://twitter.com/cburgdorf">Christoph Burgdorf</a>,
<a href="http://ericbidelman.com">Eric Bidelman</a>,
<a href="http://twitter.com/_davideast">David East</a>,
<a href="http://jacobmumm.com">Jacob Mumm</a> and
<a href="http://igorminar.com">Igor Minar</a>
</p>
<p>Part of <a href="http://todomvc.com">TodoMVC</a></p>
</footer>
<script src="https://cdn.firebase.com/v0/firebase.js"></script>
<script src="bower_components/todomvc-common/base.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angularfire/angularfire.js"></script>
<script src="//cdn.firebase.com/js/client/2.2.2/firebase.js"></script>
<script src="node_modules/todomvc-common/base.js"></script>
<script src="node_modules/angular/angular.js"></script>
<script src="node_modules/angularfire/dist/angularfire.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers/todoCtrl.js"></script>
<script src="js/directives/todoFocus.js"></script>
......
......@@ -3,18 +3,22 @@
/**
* The main controller for the app. The controller:
* - retrieves and persists the model via the $firebase service
* - retrieves and persists the model via the $firebaseArray service
* - exposes the model to the template and provides event handlers
*/
todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, $firebase) {
var url = 'https://todomvc-angular.firebaseio.com/';
todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, $firebaseArray) {
var url = 'https://todomvc-angular.firebaseio.com/todos';
var fireRef = new Firebase(url);
// Bind the todos to the firebase provider.
$scope.todos = $firebaseArray(fireRef);
$scope.newTodo = '';
$scope.editedTodo = null;
$scope.$watch('todos', function () {
var total = 0;
var remaining = 0;
$scope.todos.$getIndex().forEach(function (index) {
var todo = $scope.todos[index];
$scope.todos.forEach(function (todo) {
// Skip invalid entries so they don't break the entire app.
if (!todo || !todo.title) {
return;
......@@ -43,59 +47,47 @@ todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, $firebase) {
$scope.newTodo = '';
};
$scope.editTodo = function (id) {
$scope.editedTodo = $scope.todos[id];
$scope.editTodo = function (todo) {
$scope.editedTodo = todo;
$scope.originalTodo = angular.extend({}, $scope.editedTodo);
};
$scope.doneEditing = function (id) {
$scope.doneEditing = function (todo) {
$scope.editedTodo = null;
var title = $scope.todos[id].title.trim();
var title = todo.title.trim();
if (title) {
$scope.todos.$save(id);
$scope.todos.$save(todo);
} else {
$scope.removeTodo(id);
$scope.removeTodo(todo);
}
};
$scope.revertEditing = function (id) {
$scope.todos[id] = $scope.originalTodo;
$scope.doneEditing(id);
};
$scope.removeTodo = function (id) {
$scope.todos.$remove(id);
$scope.revertEditing = function (todo) {
todo.title = $scope.originalTodo.title;
$scope.doneEditing(todo);
};
$scope.toggleCompleted = function (id) {
var todo = $scope.todos[id];
todo.completed = !todo.completed;
$scope.todos.$save(id);
$scope.removeTodo = function (todo) {
$scope.todos.$remove(todo);
};
$scope.clearCompletedTodos = function () {
angular.forEach($scope.todos.$getIndex(), function (index) {
if ($scope.todos[index].completed) {
$scope.todos.$remove(index);
$scope.todos.forEach(function(todo) {
if(todo.completed) {
$scope.removeTodo(todo);
}
});
};
$scope.markAll = function (allCompleted) {
angular.forEach($scope.todos.$getIndex(), function (index) {
$scope.todos[index].completed = !allCompleted;
$scope.todos.forEach(function(todo) {
todo.completed = allCompleted;
$scope.todos.$save(todo);
});
$scope.todos.$save();
};
$scope.newTodo = '';
$scope.editedTodo = null;
if ($location.path() === '') {
$location.path('/');
}
$scope.location = $location;
// Bind the todos to the firebase provider.
$scope.todos = $firebase(fireRef);
});
hr {
margin: 20px 0;
border: 0;
border-top: 1px dashed #c5c5c5;
border-bottom: 1px dashed #f7f7f7;
}
.learn a {
font-weight: normal;
text-decoration: none;
color: #b83f45;
}
.learn a:hover {
text-decoration: underline;
color: #787e7e;
}
.learn h3,
.learn h4,
.learn h5 {
margin: 10px 0;
font-weight: 500;
line-height: 1.2;
color: #000;
}
.learn h3 {
font-size: 24px;
}
.learn h4 {
font-size: 18px;
}
.learn h5 {
margin-bottom: 0;
font-size: 14px;
}
.learn ul {
padding: 0;
margin: 0 0 30px 25px;
}
.learn li {
line-height: 20px;
}
.learn p {
font-size: 15px;
font-weight: 300;
line-height: 1.3;
margin-top: 0;
margin-bottom: 0;
}
#issue-count {
display: none;
}
.quote {
border: none;
margin: 20px 0 60px 0;
}
.quote p {
font-style: italic;
}
.quote p:before {
content: '“';
font-size: 50px;
opacity: .15;
position: absolute;
top: -20px;
left: 3px;
}
.quote p:after {
content: '”';
font-size: 50px;
opacity: .15;
position: absolute;
bottom: -42px;
right: 3px;
}
.quote footer {
position: absolute;
bottom: -40px;
right: 0;
}
.quote footer img {
border-radius: 3px;
}
.quote footer a {
margin-left: 5px;
vertical-align: middle;
}
.speech-bubble {
position: relative;
padding: 10px;
background: rgba(0, 0, 0, .04);
border-radius: 5px;
}
.speech-bubble:after {
content: '';
position: absolute;
top: 100%;
right: 30px;
border: 13px solid transparent;
border-top-color: rgba(0, 0, 0, .04);
}
.learn-bar > .learn {
position: absolute;
width: 272px;
top: 8px;
left: -300px;
padding: 10px;
border-radius: 5px;
background-color: rgba(255, 255, 255, .6);
transition-property: left;
transition-duration: 500ms;
}
@media (min-width: 899px) {
.learn-bar {
width: auto;
padding-left: 300px;
}
.learn-bar > .learn {
left: 8px;
}
}
/* global _ */
(function () {
'use strict';
/* jshint ignore:start */
// Underscore's Template Module
// Courtesy of underscorejs.org
var _ = (function (_) {
......@@ -114,6 +116,7 @@
if (location.hostname === 'todomvc.com') {
window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script'));
}
/* jshint ignore:end */
function redirect() {
if (location.hostname === 'tastejs.github.io') {
......@@ -175,13 +178,17 @@
if (learnJSON.backend) {
this.frameworkJSON = learnJSON.backend;
this.frameworkJSON.issueLabel = framework;
this.append({
backend: true
});
} else if (learnJSON[framework]) {
this.frameworkJSON = learnJSON[framework];
this.frameworkJSON.issueLabel = framework;
this.append();
}
this.fetchIssueCount();
}
Learn.prototype.append = function (opts) {
......@@ -212,6 +219,26 @@
document.body.insertAdjacentHTML('afterBegin', aside.outerHTML);
};
Learn.prototype.fetchIssueCount = function () {
var issueLink = document.getElementById('issue-count-link');
if (issueLink) {
var url = issueLink.href.replace('https://github.com', 'https://api.github.com/repos');
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onload = function (e) {
var parsedResponse = JSON.parse(e.target.responseText);
if (parsedResponse instanceof Array) {
var count = parsedResponse.length
if (count !== 0) {
issueLink.innerHTML = 'This app has ' + count + ' open issues';
document.getElementById('issue-count').style.display = 'inline';
}
}
};
xhr.send();
}
};
redirect();
getFile('learn.json', Learn);
})();
{
"private": true,
"dependencies": {
"angular": "^1.3.15",
"angularfire": "^1.0.0",
"todomvc-app-css": "^1.0.1",
"todomvc-common": "^1.0.1"
}
}
......@@ -13,10 +13,10 @@ Here are some links you may find helpful:
* [Tutorial](https://www.firebase.com/tutorial/)
* [Documentation & Examples](https://www.firebase.com/docs/)
* [API Reference](https://www.firebase.com/docs/javascript/firebase/)
* [API Reference](https://www.firebase.com/docs/web)
* [Blog](https://www.firebase.com/blog/)
* [Firebase on Github](http://firebase.github.io)
* [AngularJS bindings for Firebase](http://github.com/firebase/angularFire)
* [AngularJS bindings for Firebase](https://www.firebase.com/docs/web/libraries/angular/)
Get help from other AngularJS users:
......
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