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
8ad3e2dd
Commit
8ad3e2dd
authored
Jan 01, 2012
by
Sindre Sorhus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code formatting improvements
parent
fd14f902
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
27 deletions
+31
-27
todo-example/jquery/js/app.js
todo-example/jquery/js/app.js
+31
-27
No files found.
todo-example/jquery/js/app.js
View file @
8ad3e2dd
// Array Remove - By John Resig (MIT Licensed)
// Array Remove - By John Resig (MIT Licensed)
Array
.
prototype
.
remove
=
function
(
from
,
to
)
{
Array
.
prototype
.
remove
=
function
(
from
,
to
)
{
var
rest
=
this
.
slice
(
(
to
||
from
)
+
1
||
this
.
length
);
var
rest
=
this
.
slice
(
(
to
||
from
)
+
1
||
this
.
length
);
this
.
length
=
from
<
0
?
this
.
length
+
from
:
from
;
this
.
length
=
from
<
0
?
this
.
length
+
from
:
from
;
return
this
.
push
.
apply
(
this
,
rest
);
return
this
.
push
.
apply
(
this
,
rest
);
};
};
/*
/*
...
@@ -13,24 +13,28 @@ sindresorhus.com
...
@@ -13,24 +13,28 @@ sindresorhus.com
*/
*/
jQuery
(
function
(
$
){
jQuery
(
function
(
$
){
jQuery
(
function
(
$
)
{
"
use strict
"
;
var
Utils
=
{
var
Utils
=
{
// https://gist.github.com/823878
// https://gist.github.com/823878
uuid
:
function
()
{
uuid
:
function
()
{
var
uuid
=
""
,
i
,
random
;
var
uuid
=
""
,
i
,
random
;
for
(
i
=
0
;
i
<
32
;
i
++
)
{
for
(
i
=
0
;
i
<
32
;
i
++
)
{
random
=
Math
.
random
()
*
16
|
0
;
random
=
Math
.
random
()
*
16
|
0
;
if
(
i
==
8
||
i
==
12
||
i
==
16
||
i
==
20
)
{
if
(
i
==
=
8
||
i
===
12
||
i
===
16
||
i
=
==
20
)
{
uuid
+=
"
-
"
;
uuid
+=
"
-
"
;
}
}
uuid
+=
(
i
==
12
?
4
:
(
i
==
16
?
(
random
&
3
|
8
)
:
random
)
).
toString
(
16
);
uuid
+=
(
i
===
12
?
4
:
(
i
===
16
?
(
random
&
3
|
8
)
:
random
)
).
toString
(
16
);
}
}
return
uuid
;
return
uuid
;
},
},
pluralize
:
function
(
count
,
word
)
{
pluralize
:
function
(
count
,
word
)
{
return
count
===
1
?
word
:
word
+
'
s
'
;
return
count
===
1
?
word
:
word
+
'
s
'
;
}
}
};
};
var
App
=
{
var
App
=
{
init
:
function
()
{
init
:
function
()
{
this
.
$template
=
$
(
'
#todo-template
'
);
this
.
$template
=
$
(
'
#todo-template
'
);
...
@@ -49,22 +53,22 @@ jQuery(function($){
...
@@ -49,22 +53,22 @@ jQuery(function($){
var
html
=
this
.
$template
.
tmpl
(
this
.
todos
);
var
html
=
this
.
$template
.
tmpl
(
this
.
todos
);
this
.
$todoList
.
html
(
html
);
this
.
$todoList
.
html
(
html
);
this
.
renderFooter
();
this
.
renderFooter
();
this
.
store
.
set
(
'
todos
'
,
this
.
todos
);
this
.
store
.
set
(
'
todos
'
,
this
.
todos
);
},
},
bindEvents
:
function
()
{
bindEvents
:
function
()
{
var
elem
=
this
.
$todoApp
,
var
app
=
this
.
$todoApp
,
list
=
this
.
$todoList
;
list
=
this
.
$todoList
;
elem
.
on
(
'
click
'
,
'
.clear
'
,
this
.
destroyDone
);
app
.
on
(
'
click
'
,
'
.clear
'
,
this
.
destroyDone
);
elem
.
on
(
'
submit
'
,
'
form
'
,
this
.
create
);
app
.
on
(
'
submit
'
,
'
form
'
,
this
.
create
);
list
.
on
(
'
change
'
,
'
input[type="checkbox"]
'
,
this
.
toggle
);
list
.
on
(
'
change
'
,
'
input[type="checkbox"]
'
,
this
.
toggle
);
list
.
on
(
'
dblclick
'
,
'
.view
'
,
this
.
edit
);
list
.
on
(
'
dblclick
'
,
'
.view
'
,
this
.
edit
);
list
.
on
(
'
keypress
'
,
'
input[type="text"]
'
,
this
.
blurOnEnter
);
list
.
on
(
'
keypress
'
,
'
input[type="text"]
'
,
this
.
blurOnEnter
);
list
.
on
(
'
blur
'
,
'
input[type="text"]
'
,
this
.
update
);
list
.
on
(
'
blur
'
,
'
input[type="text"]
'
,
this
.
update
);
list
.
on
(
'
click
'
,
'
.destroy
'
,
this
.
destroy
);
list
.
on
(
'
click
'
,
'
.destroy
'
,
this
.
destroy
);
},
},
activeTodoCount
:
function
()
{
activeTodoCount
:
function
()
{
var
count
=
0
;
var
count
=
0
;
$
.
each
(
this
.
todos
,
function
(
i
,
val
)
{
$
.
each
(
this
.
todos
,
function
(
i
,
val
)
{
if
(
!
val
.
done
)
{
if
(
!
val
.
done
)
{
count
++
;
count
++
;
}
}
...
@@ -75,7 +79,7 @@ jQuery(function($){
...
@@ -75,7 +79,7 @@ jQuery(function($){
var
todoCount
=
this
.
todos
.
length
,
var
todoCount
=
this
.
todos
.
length
,
activeTodos
=
this
.
activeTodoCount
(),
activeTodos
=
this
.
activeTodoCount
(),
completedTodos
=
todoCount
-
activeTodos
,
completedTodos
=
todoCount
-
activeTodos
,
countTitle
=
'
<b>
'
+
activeTodos
+
'
</b>
'
+
Utils
.
pluralize
(
activeTodos
,
'
item
'
)
+
'
left
'
;
countTitle
=
'
<b>
'
+
activeTodos
+
'
</b>
'
+
Utils
.
pluralize
(
activeTodos
,
'
item
'
)
+
'
left
'
,
clearTitle
=
'
Clear
'
+
completedTodos
+
'
completed
'
+
Utils
.
pluralize
(
completedTodos
,
'
item
'
);
clearTitle
=
'
Clear
'
+
completedTodos
+
'
completed
'
+
Utils
.
pluralize
(
completedTodos
,
'
item
'
);
// Only show the footer when there are at least one todo.
// Only show the footer when there are at least one todo.
this
.
$footer
.
toggle
(
!!
todoCount
);
this
.
$footer
.
toggle
(
!!
todoCount
);
...
@@ -93,12 +97,12 @@ jQuery(function($){
...
@@ -93,12 +97,12 @@ jQuery(function($){
}
}
App
.
render
();
App
.
render
();
},
},
// Accepts an element from inside the ".item" div
,
and returns the corresponding todo in the todos array.
// Accepts an element from inside the ".item" div and returns the corresponding todo in the todos array.
getTodo
:
function
(
elem
,
callback
)
{
getTodo
:
function
(
elem
,
callback
)
{
var
id
=
$
(
elem
).
closest
(
'
.item
'
).
data
(
'
id
'
);
var
id
=
$
(
elem
).
closest
(
'
.item
'
).
data
(
'
id
'
);
$
.
each
(
this
.
todos
,
function
(
i
,
val
)
{
$
.
each
(
this
.
todos
,
function
(
i
,
val
)
{
if
(
val
.
id
===
id
)
{
if
(
val
.
id
===
id
)
{
callback
.
apply
(
App
,
arguments
);
callback
.
apply
(
App
,
arguments
);
return
false
;
return
false
;
}
}
});
});
...
@@ -119,7 +123,7 @@ jQuery(function($){
...
@@ -119,7 +123,7 @@ jQuery(function($){
App
.
render
();
App
.
render
();
},
},
toggle
:
function
()
{
toggle
:
function
()
{
App
.
getTodo
(
this
,
function
(
i
,
val
)
{
App
.
getTodo
(
this
,
function
(
i
,
val
)
{
val
.
done
=
!
val
.
done
;
val
.
done
=
!
val
.
done
;
});
});
App
.
render
();
App
.
render
();
...
@@ -134,13 +138,13 @@ jQuery(function($){
...
@@ -134,13 +138,13 @@ jQuery(function($){
},
},
update
:
function
()
{
update
:
function
()
{
var
newVal
=
$
(
this
).
removeClass
(
'
editing
'
).
val
();
var
newVal
=
$
(
this
).
removeClass
(
'
editing
'
).
val
();
App
.
getTodo
(
this
,
function
(
i
)
{
App
.
getTodo
(
this
,
function
(
i
)
{
this
.
todos
[
i
].
title
=
newVal
;
this
.
todos
[
i
].
title
=
newVal
;
});
});
App
.
render
();
App
.
render
();
},
},
destroy
:
function
()
{
destroy
:
function
()
{
App
.
getTodo
(
this
,
function
(
i
)
{
App
.
getTodo
(
this
,
function
(
i
)
{
this
.
todos
.
remove
(
i
);
this
.
todos
.
remove
(
i
);
this
.
render
();
this
.
render
();
});
});
...
@@ -148,5 +152,5 @@ jQuery(function($){
...
@@ -148,5 +152,5 @@ jQuery(function($){
};
};
window
.
TodoApp
=
App
.
init
();
window
.
TodoApp
=
App
.
init
();
});
});
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