Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
todomvc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Eugene Shen
todomvc
Commits
42c1985d
Commit
42c1985d
authored
Mar 01, 2012
by
Christoph Burgdorf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added localStorage functionality
parent
713a1a8a
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
502 additions
and
2 deletions
+502
-2
architecture-examples/angularjs/index.html
architecture-examples/angularjs/index.html
+1
-0
architecture-examples/angularjs/js/controllers.js
architecture-examples/angularjs/js/controllers.js
+20
-2
architecture-examples/angularjs/js/libs/json2.js
architecture-examples/angularjs/js/libs/json2.js
+481
-0
No files found.
architecture-examples/angularjs/index.html
View file @
42c1985d
...
...
@@ -41,6 +41,7 @@
<div
id=
"credits"
>
Created by
<a
href=
"http://twitter.com/cburgdorf"
>
Christoph Burgdorf
</a>
.
</div>
<script
src=
"js/libs/json2.js"
></script>
<script
src=
"js/booter.js"
></script>
<script
src=
"js/libs/angular/angular.min.js"
ng:autobind
></script>
<script
src=
"js/controllers.js"
></script>
...
...
architecture-examples/angularjs/js/controllers.js
View file @
42c1985d
...
...
@@ -5,6 +5,26 @@ App.Controllers.TodoController = function () {
self
.
newTodo
=
""
;
var
retrieveStore
=
function
()
{
var
store
=
localStorage
.
getItem
(
'
todo-angularjs
'
);
return
(
store
&&
JSON
.
parse
(
store
)
)
||
[];
};
var
updateStore
=
function
()
{
var
isEditing
=
angular
.
Array
.
count
(
self
.
todos
,
function
(
x
)
{
return
x
.
editing
;
});
if
(
!
isEditing
){
localStorage
.
setItem
(
'
todo-angularjs
'
,
JSON
.
stringify
(
self
.
todos
));
}
};
//not sure if its intended to do so. However, we need a hook to update the store
//whenever angular changes any properties
self
.
$watch
(
updateStore
);
self
.
todos
=
retrieveStore
();
self
.
addTodo
=
function
()
{
if
(
self
.
newTodo
.
trim
().
length
===
0
)
return
;
...
...
@@ -37,8 +57,6 @@ App.Controllers.TodoController = function () {
angular
.
Array
.
remove
(
self
.
todos
,
todo
);
};
self
.
todos
=
[];
var
countTodos
=
function
(
done
)
{
return
function
()
{
return
angular
.
Array
.
count
(
self
.
todos
,
function
(
x
)
{
...
...
architecture-examples/angularjs/js/libs/json2.js
0 → 100644
View file @
42c1985d
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment