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
Sven Franck
todomvc
Commits
2dee7943
Commit
2dee7943
authored
Feb 20, 2013
by
Pascal Hartig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jquery: jshint style
parent
bcc74618
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
62 deletions
+62
-62
architecture-examples/jquery/js/app.js
architecture-examples/jquery/js/app.js
+62
-62
No files found.
architecture-examples/jquery/js/app.js
View file @
2dee7943
/*global jQuery, Handlebars */
jQuery
(
function
(
$
)
{
jQuery
(
function
(
$
)
{
'
use strict
'
;
var
Utils
=
{
// https://gist.github.com/1308368
uuid
:
function
(
a
,
b
){
for
(
b
=
a
=
''
;
a
++<
36
;
b
+=
a
*
51
&
52
?(
a
^
15
?
8
^
Math
.
random
()
*
(
a
^
20
?
16
:
4
):
4
).
toString
(
16
):
'
-
'
);
return
b
},
pluralize
:
function
(
count
,
word
)
{
uuid
:
function
(
a
,
b
){
for
(
b
=
a
=
''
;
a
++<
36
;
b
+=
a
*
51
&
52
?(
a
^
15
?
8
^
Math
.
random
()
*
(
a
^
20
?
16
:
4
):
4
).
toString
(
16
):
'
-
'
);
return
b
},
pluralize
:
function
(
count
,
word
)
{
return
count
===
1
?
word
:
word
+
'
s
'
;
},
store
:
function
(
namespace
,
data
)
{
if
(
arguments
.
length
>
1
)
{
return
localStorage
.
setItem
(
namespace
,
JSON
.
stringify
(
data
)
);
store
:
function
(
namespace
,
data
)
{
if
(
arguments
.
length
>
1
)
{
return
localStorage
.
setItem
(
namespace
,
JSON
.
stringify
(
data
)
);
}
else
{
var
store
=
localStorage
.
getItem
(
namespace
);
return
(
store
&&
JSON
.
parse
(
store
)
)
||
[];
var
store
=
localStorage
.
getItem
(
namespace
);
return
(
store
&&
JSON
.
parse
(
store
)
)
||
[];
}
}
};
var
App
=
{
init
:
function
()
{
init
:
function
()
{
this
.
ENTER_KEY
=
13
;
this
.
todos
=
Utils
.
store
(
'
todos-jquery
'
);
this
.
cacheElements
();
this
.
bindEvents
();
this
.
render
();
},
cacheElements
:
function
()
{
this
.
todoTemplate
=
Handlebars
.
compile
(
$
(
'
#todo-template
'
).
html
()
);
this
.
footerTemplate
=
Handlebars
.
compile
(
$
(
'
#footer-template
'
).
html
()
);
cacheElements
:
function
()
{
this
.
todoTemplate
=
Handlebars
.
compile
(
$
(
'
#todo-template
'
).
html
()
);
this
.
footerTemplate
=
Handlebars
.
compile
(
$
(
'
#footer-template
'
).
html
()
);
this
.
$todoApp
=
$
(
'
#todoapp
'
);
this
.
$newTodo
=
$
(
'
#new-todo
'
);
this
.
$toggleAll
=
$
(
'
#toggle-all
'
);
...
...
@@ -38,77 +38,77 @@ jQuery(function( $ ) {
this
.
$count
=
$
(
'
#todo-count
'
);
this
.
$clearBtn
=
$
(
'
#clear-completed
'
);
},
bindEvents
:
function
()
{
bindEvents
:
function
()
{
var
list
=
this
.
$todoList
;
this
.
$newTodo
.
on
(
'
keyup
'
,
this
.
create
);
this
.
$toggleAll
.
on
(
'
change
'
,
this
.
toggleAll
);
this
.
$footer
.
on
(
'
click
'
,
'
#clear-completed
'
,
this
.
destroyCompleted
);
list
.
on
(
'
change
'
,
'
.toggle
'
,
this
.
toggle
);
list
.
on
(
'
dblclick
'
,
'
label
'
,
this
.
edit
);
list
.
on
(
'
keypress
'
,
'
.edit
'
,
this
.
blurOnEnter
);
list
.
on
(
'
blur
'
,
'
.edit
'
,
this
.
update
);
list
.
on
(
'
click
'
,
'
.destroy
'
,
this
.
destroy
);
this
.
$newTodo
.
on
(
'
keyup
'
,
this
.
create
);
this
.
$toggleAll
.
on
(
'
change
'
,
this
.
toggleAll
);
this
.
$footer
.
on
(
'
click
'
,
'
#clear-completed
'
,
this
.
destroyCompleted
);
list
.
on
(
'
change
'
,
'
.toggle
'
,
this
.
toggle
);
list
.
on
(
'
dblclick
'
,
'
label
'
,
this
.
edit
);
list
.
on
(
'
keypress
'
,
'
.edit
'
,
this
.
blurOnEnter
);
list
.
on
(
'
blur
'
,
'
.edit
'
,
this
.
update
);
list
.
on
(
'
click
'
,
'
.destroy
'
,
this
.
destroy
);
},
render
:
function
()
{
this
.
$todoList
.
html
(
this
.
todoTemplate
(
this
.
todos
)
);
this
.
$main
.
toggle
(
!!
this
.
todos
.
length
);
this
.
$toggleAll
.
prop
(
'
checked
'
,
!
this
.
activeTodoCount
()
);
render
:
function
()
{
this
.
$todoList
.
html
(
this
.
todoTemplate
(
this
.
todos
)
);
this
.
$main
.
toggle
(
!!
this
.
todos
.
length
);
this
.
$toggleAll
.
prop
(
'
checked
'
,
!
this
.
activeTodoCount
()
);
this
.
renderFooter
();
Utils
.
store
(
'
todos-jquery
'
,
this
.
todos
);
Utils
.
store
(
'
todos-jquery
'
,
this
.
todos
);
},
renderFooter
:
function
()
{
renderFooter
:
function
()
{
var
todoCount
=
this
.
todos
.
length
,
activeTodoCount
=
this
.
activeTodoCount
(),
footer
=
{
activeTodoCount
:
activeTodoCount
,
activeTodoWord
:
Utils
.
pluralize
(
activeTodoCount
,
'
item
'
),
activeTodoWord
:
Utils
.
pluralize
(
activeTodoCount
,
'
item
'
),
completedTodos
:
todoCount
-
activeTodoCount
};
this
.
$footer
.
toggle
(
!!
todoCount
);
this
.
$footer
.
html
(
this
.
footerTemplate
(
footer
)
);
this
.
$footer
.
toggle
(
!!
todoCount
);
this
.
$footer
.
html
(
this
.
footerTemplate
(
footer
)
);
},
toggleAll
:
function
()
{
var
isChecked
=
$
(
this
).
prop
(
'
checked
'
);
$
.
each
(
App
.
todos
,
function
(
i
,
val
)
{
toggleAll
:
function
()
{
var
isChecked
=
$
(
this
).
prop
(
'
checked
'
);
$
.
each
(
App
.
todos
,
function
(
i
,
val
)
{
val
.
completed
=
isChecked
;
});
App
.
render
();
},
activeTodoCount
:
function
()
{
activeTodoCount
:
function
()
{
var
count
=
0
;
$
.
each
(
this
.
todos
,
function
(
i
,
val
)
{
if
(
!
val
.
completed
)
{
$
.
each
(
this
.
todos
,
function
(
i
,
val
)
{
if
(
!
val
.
completed
)
{
count
++
;
}
});
return
count
;
},
destroyCompleted
:
function
()
{
destroyCompleted
:
function
()
{
var
todos
=
App
.
todos
,
l
=
todos
.
length
;
while
(
l
--
)
{
if
(
todos
[
l
].
completed
)
{
todos
.
splice
(
l
,
1
);
while
(
l
--
)
{
if
(
todos
[
l
].
completed
)
{
todos
.
splice
(
l
,
1
);
}
}
App
.
render
();
},
// Accepts an element from inside the ".item" div and
// returns the corresponding todo in the todos array
getTodo
:
function
(
elem
,
callback
)
{
var
id
=
$
(
elem
).
closest
(
'
li
'
).
data
(
'
id
'
);
$
.
each
(
this
.
todos
,
function
(
i
,
val
)
{
if
(
val
.
id
===
id
)
{
callback
.
apply
(
App
,
arguments
);
getTodo
:
function
(
elem
,
callback
)
{
var
id
=
$
(
elem
).
closest
(
'
li
'
).
data
(
'
id
'
);
$
.
each
(
this
.
todos
,
function
(
i
,
val
)
{
if
(
val
.
id
===
id
)
{
callback
.
apply
(
App
,
arguments
);
return
false
;
}
});
},
create
:
function
(
e
)
{
create
:
function
(
e
)
{
var
$input
=
$
(
this
),
val
=
$
.
trim
(
$input
.
val
()
);
if
(
e
.
which
!==
App
.
ENTER_KEY
||
!
val
)
{
val
=
$
.
trim
(
$input
.
val
()
);
if
(
e
.
which
!==
App
.
ENTER_KEY
||
!
val
)
{
return
;
}
App
.
todos
.
push
({
...
...
@@ -119,34 +119,34 @@ jQuery(function( $ ) {
$input
.
val
(
''
);
App
.
render
();
},
toggle
:
function
()
{
App
.
getTodo
(
this
,
function
(
i
,
val
)
{
toggle
:
function
()
{
App
.
getTodo
(
this
,
function
(
i
,
val
)
{
val
.
completed
=
!
val
.
completed
;
});
App
.
render
();
},
edit
:
function
()
{
edit
:
function
()
{
$
(
this
).
closest
(
'
li
'
).
addClass
(
'
editing
'
).
find
(
'
.edit
'
).
focus
();
},
blurOnEnter
:
function
(
e
)
{
if
(
e
.
keyCode
===
App
.
ENTER_KEY
)
{
blurOnEnter
:
function
(
e
)
{
if
(
e
.
keyCode
===
App
.
ENTER_KEY
)
{
e
.
target
.
blur
();
}
},
update
:
function
()
{
var
val
=
$
.
trim
(
$
(
this
).
removeClass
(
'
editing
'
).
val
()
);
App
.
getTodo
(
this
,
function
(
i
)
{
if
(
val
)
{
this
.
todos
[
i
].
title
=
val
;
update
:
function
()
{
var
val
=
$
.
trim
(
$
(
this
).
removeClass
(
'
editing
'
).
val
()
);
App
.
getTodo
(
this
,
function
(
i
)
{
if
(
val
)
{
this
.
todos
[
i
].
title
=
val
;
}
else
{
this
.
todos
.
splice
(
i
,
1
);
this
.
todos
.
splice
(
i
,
1
);
}
this
.
render
();
});
},
destroy
:
function
()
{
App
.
getTodo
(
this
,
function
(
i
)
{
this
.
todos
.
splice
(
i
,
1
);
destroy
:
function
()
{
App
.
getTodo
(
this
,
function
(
i
)
{
this
.
todos
.
splice
(
i
,
1
);
this
.
render
();
});
}
...
...
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