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
f22ebe10
Commit
f22ebe10
authored
Feb 16, 2013
by
Sindre Sorhus
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #456 from passy/agility-jshint
AgilityJS: Style update
parents
1058c813
2f1923dc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
63 deletions
+62
-63
architecture-examples/agilityjs/js/app.js
architecture-examples/agilityjs/js/app.js
+48
-48
architecture-examples/agilityjs/js/localstorage.js
architecture-examples/agilityjs/js/localstorage.js
+14
-15
No files found.
architecture-examples/agilityjs/js/app.js
View file @
f22ebe10
(
function
(
$
,
$$
)
{
(
function
(
$
,
$$
)
{
'
use strict
'
;
var
ENTER_KEY
=
13
;
// Hack of taking out html elements from DOM so that agility's view can use it.
// We need 'outerhtml' also, as agilityjs will append DOM, so removing it.
var
drawHtml
=
function
(
selector
)
{
var
drawHtml
=
function
(
selector
)
{
return
$
(
selector
).
remove
().
wrap
(
'
<div>
'
).
parent
().
html
();
};
// Simple Two layer composition:
// individual 'todoitem' and 'app'lication which holds multiple todoitems.
$
(
function
()
{
$
(
function
()
{
// todo item
var
todoitem
=
$$
({
model
:
{
...
...
@@ -22,39 +22,39 @@
style
:
'
.hidden { display: none }
'
},
controller
:
{
'
change:completed
'
:
function
()
{
this
.
view
.
$
().
toggleClass
(
'
completed
'
,
this
.
model
.
get
(
'
completed
'
)
);
'
change:completed
'
:
function
()
{
this
.
view
.
$
().
toggleClass
(
'
completed
'
,
this
.
model
.
get
(
'
completed
'
)
);
app
.
updateStatus
();
},
'
dblclick &
'
:
function
()
{
'
dblclick &
'
:
function
()
{
this
.
view
.
$
().
addClass
(
'
editing
'
);
this
.
view
.
$
(
'
.edit
'
).
focus
();
},
'
click .destroy
'
:
function
()
{
'
click .destroy
'
:
function
()
{
this
.
destroy
();
},
'
create
'
:
function
()
{
this
.
view
.
$
().
toggleClass
(
'
completed
'
,
this
.
model
.
get
(
'
completed
'
)
);
'
create
'
:
function
()
{
this
.
view
.
$
().
toggleClass
(
'
completed
'
,
this
.
model
.
get
(
'
completed
'
)
);
},
'
change
'
:
function
()
{
'
change
'
:
function
()
{
this
.
save
();
},
'
destroy
'
:
function
()
{
'
destroy
'
:
function
()
{
this
.
erase
();
},
'
blur input
'
:
function
()
{
'
blur input
'
:
function
()
{
this
.
updateTitle
();
},
'
keyup input
'
:
function
()
{
if
(
event
.
which
===
ENTER_KEY
)
{
'
keyup input
'
:
function
()
{
if
(
event
.
which
===
ENTER_KEY
)
{
this
.
updateTitle
();
}
}
},
updateTitle
:
function
()
{
updateTitle
:
function
()
{
this
.
view
.
$
().
removeClass
(
'
editing
'
);
var
title
=
this
.
model
.
get
(
'
title
'
).
trim
();
if
(
title
)
{
if
(
title
)
{
this
.
model
.
set
({
title
:
title
});
...
...
@@ -62,7 +62,7 @@
this
.
destroy
();
}
}
}).
persist
(
$$
.
adapter
.
localStorage
,
{
}).
persist
(
$$
.
adapter
.
localStorage
,
{
collection
:
'
todos-agilityjs
'
});
...
...
@@ -81,45 +81,45 @@
style
:
'
.hidden { display: none }
'
},
controller
:
{
'
remove
'
:
function
()
{
'
remove
'
:
function
()
{
this
.
updateStatus
();
},
'
append
'
:
function
()
{
'
append
'
:
function
()
{
this
.
updateStatus
();
},
'
keyup #new-todo
'
:
function
(
event
)
{
'
keyup #new-todo
'
:
function
(
event
)
{
var
title
=
$
(
'
#new-todo
'
).
val
().
trim
();
if
(
event
.
which
===
ENTER_KEY
&&
title
)
{
var
item
=
$$
(
todoitem
,
{
if
(
event
.
which
===
ENTER_KEY
&&
title
)
{
var
item
=
$$
(
todoitem
,
{
title
:
title
}).
save
();
this
.
append
(
item
,
'
#todo-list
'
);
this
.
append
(
item
,
'
#todo-list
'
);
event
.
target
.
value
=
''
;
// clear input field
}
},
'
click #toggle-all
'
:
function
()
{
'
click #toggle-all
'
:
function
()
{
var
ischecked
=
this
.
view
.
$
(
'
#toggle-all
'
).
prop
(
'
checked
'
);
this
.
each
(
function
(
id
,
item
)
{
this
.
each
(
function
(
id
,
item
)
{
item
.
model
.
set
({
completed
:
ischecked
});
});
},
'
click #clear-completed
'
:
function
()
{
this
.
each
(
function
(
id
,
item
)
{
if
(
item
.
model
.
get
(
'
completed
'
)
)
{
'
click #clear-completed
'
:
function
()
{
this
.
each
(
function
(
id
,
item
)
{
if
(
item
.
model
.
get
(
'
completed
'
)
)
{
item
.
destroy
();
}
});
}
},
// utility functions
updateStatus
:
function
()
{
updateStatus
:
function
()
{
// update counts
var
count
=
this
.
size
(),
completedCount
=
0
;
this
.
each
(
function
(
id
,
item
)
{
if
(
item
.
model
.
get
(
'
completed
'
)
)
{
this
.
each
(
function
(
id
,
item
)
{
if
(
item
.
model
.
get
(
'
completed
'
)
)
{
completedCount
++
;
}
});
...
...
@@ -131,51 +131,51 @@
clearBtnStyle
:
(
completedCount
===
0
?
'
hidden
'
:
''
)
});
// update toggle-all checked status
$
(
'
#toggle-all
'
).
prop
(
'
checked
'
,
completedCount
===
count
);
$
(
'
#toggle-all
'
).
prop
(
'
checked
'
,
completedCount
===
count
);
// update the view according to the current filter.
this
.
applyFilter
();
},
// filter handler
filters
:
{
'
#/
'
:
function
(
item
)
{
'
#/
'
:
function
(
)
{
return
true
;
},
'
#/active
'
:
function
(
item
)
{
'
#/active
'
:
function
(
item
)
{
return
!
item
.
model
.
get
(
'
completed
'
);
},
'
#/completed
'
:
function
(
item
)
{
'
#/completed
'
:
function
(
item
)
{
return
item
.
model
.
get
(
'
completed
'
);
}
},
applyFilter
:
function
(
hash
)
{
applyFilter
:
function
(
hash
)
{
var
isVisible
=
this
.
filters
[
hash
||
location
.
hash
];
if
(
isVisible
)
{
this
.
each
(
function
(
id
,
item
)
{
item
.
view
.
$
().
toggleClass
(
'
hidden
'
,
!
isVisible
(
item
)
);
if
(
isVisible
)
{
this
.
each
(
function
(
id
,
item
)
{
item
.
view
.
$
().
toggleClass
(
'
hidden
'
,
!
isVisible
(
item
)
);
});
}
}
}).
persist
();
$$
.
document
.
prepend
(
app
);
$$
.
document
.
prepend
(
app
);
// load from localStorage
app
.
gather
(
todoitem
,
'
append
'
,
'
#todo-list
'
).
updateStatus
();
app
.
gather
(
todoitem
,
'
append
'
,
'
#todo-list
'
).
updateStatus
();
// manual routing (not supported by agilityjs)
$
(
window
).
on
(
'
hashchange
'
,
function
()
{
$
(
window
).
on
(
'
hashchange
'
,
function
()
{
var
hash
=
location
.
hash
;
app
.
applyFilter
(
hash
);
$
(
'
#filters a
'
).
each
(
function
()
{
if
(
hash
===
$
(
this
).
attr
(
'
href
'
)
)
{
app
.
applyFilter
(
hash
);
$
(
'
#filters a
'
).
each
(
function
()
{
if
(
hash
===
$
(
this
).
attr
(
'
href
'
)
)
{
$
(
this
).
addClass
(
'
selected
'
);
}
else
{
$
(
this
).
removeClass
(
'
selected
'
);
}
});
}
);
if
(
location
.
hash
)
{
});
if
(
location
.
hash
)
{
$
(
window
).
trigger
(
'
hashchange
'
);
}
});
})(
window
.
jQuery
,
window
.
agility
);
})(
window
.
jQuery
,
window
.
agility
);
architecture-examples/agilityjs/js/localstorage.js
View file @
f22ebe10
// custom agilityjs adapter for localstorage
(
function
(
$$
,
undefined
)
{
(
function
(
$$
,
undefined
)
{
'
use strict
'
;
$$
.
adapter
.
localStorage
=
function
(
_params
)
{
$$
.
adapter
.
localStorage
=
function
(
_params
)
{
var
storageKey
=
(
this
.
_data
.
persist
.
baseUrl
||
''
)
+
this
.
_data
.
persist
.
collection
,
storageStr
=
localStorage
[
storageKey
],
items
=
(
storageStr
?
JSON
.
parse
(
storageStr
)
:
{});
items
=
(
storageStr
?
JSON
.
parse
(
storageStr
)
:
{});
//
if
(
_params
.
type
===
'
GET
'
)
{
if
(
_params
.
id
!==
undefined
)
{
// normal get
if
(
typeof
items
[
_params
.
id
]
===
'
object
'
)
{
_params
.
success
(
items
[
_params
.
id
]
);
if
(
_params
.
type
===
'
GET
'
)
{
if
(
_params
.
id
!==
undefined
)
{
// normal get
if
(
typeof
items
[
_params
.
id
]
===
'
object
'
)
{
_params
.
success
(
items
[
_params
.
id
]
);
}
else
{
_params
.
error
();
}
}
else
{
// gather call
_params
.
success
(
items
);
_params
.
success
(
items
);
}
}
else
if
(
_params
.
type
===
'
DELETE
'
)
{
}
else
if
(
_params
.
type
===
'
DELETE
'
)
{
delete
items
[
_params
.
id
];
localStorage
[
storageKey
]
=
JSON
.
stringify
(
items
);
}
else
if
(
_params
.
type
===
'
PUT
'
||
_params
.
type
===
'
POST
'
)
{
if
(
_params
.
id
===
undefined
)
{
localStorage
[
storageKey
]
=
JSON
.
stringify
(
items
);
}
else
if
(
_params
.
type
===
'
PUT
'
||
_params
.
type
===
'
POST
'
)
{
if
(
_params
.
id
===
undefined
)
{
_params
.
id
=
(
new
Date
()).
getTime
();
_params
.
data
.
id
=
_params
.
id
;
}
items
[
_params
.
id
]
=
_params
.
data
;
localStorage
[
storageKey
]
=
JSON
.
stringify
(
items
);
localStorage
[
storageKey
]
=
JSON
.
stringify
(
items
);
}
else
{
_params
.
error
();
}
_params
.
complete
();
};
})(
window
.
agility
);
})(
window
.
agility
);
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