@@ -82,8 +82,13 @@ function render_item (item) {
82
82
* @return {Object } <section> DOM Tree which containing the todo list <ul>, etc.
83
83
*/
84
84
function render_main ( model ) {
85
+
86
+ // Requirement #1 - No Todos, should hide #footer and #main
87
+ var display = "style=display:"
88
+ + ( model . todos . length > 0 ? + "block" : "none" ) ;
89
+
85
90
return (
86
- section ( [ "class=main" , "style=display: block;" ] , [
91
+ section ( [ "class=main" , "id=main" , display ] , [ // hide if no todo items.
87
92
input ( [ "id=toggle-all" , "class=toggle-all" , "type=checkbox" ] , [ ] ) ,
88
93
label ( [ "for=toggle-all" ] , [ text ( "Mark all as complete" ) ] ) ,
89
94
ul ( [ "class=todo-list" ] ,
@@ -104,15 +109,23 @@ function render_main (model) {
104
109
* var DOM = render_footer(model);
105
110
*/
106
111
function render_footer ( model ) {
107
- var count = model . todos . filter (
108
- function ( i ) { return i . done === false }
109
- ) . length . toString ( ) ;
112
+
113
+ // Requirement #1 - No Todos, should hide #footer and #main
114
+ var display = "style=display:"
115
+ + ( model . todos . length > 0 ? + "block" : "none" ) ;
116
+
117
+ // count how many "active" (not yet done) items by filtering done === false:
118
+ var count = model . todos . filter ( function ( i ) { return ! i . done ; } ) . length ;
119
+
120
+ // number of completed items:
121
+ var done = model . todos . length - count ;
122
+ var display_clear_complete = "style=display:"
123
+ + ( model . todos . length > 0 ? + "block" : "none" ) ;
110
124
// pluarisation of number of items:
111
- var left = ( " item" +
112
- ( model . todos . length > 1 || model . todos . length === 0 ? 's' : '' ) + " left" ) ;
125
+ var left = ( " item" + ( count > 1 || count === 0 ? 's' : '' ) + " left" ) ;
113
126
114
127
return (
115
- footer ( [ "class=footer" , "style=display: block;" ] , [
128
+ footer ( [ "class=footer" , "id=footer" , display ] , [
116
129
span ( [ "class=todo-count" , "id=count" ] , [
117
130
strong ( count ) ,
118
131
text ( left )
@@ -128,7 +141,7 @@ function render_footer (model) {
128
141
a ( [ "href=#/completed" ] , [ text ( "Completed" ) ] )
129
142
] )
130
143
] ) , // </ul>
131
- button ( [ "class=clear-completed" , "style=display:block;" ] ,
144
+ button ( [ "class=clear-completed" , display_clear_complete ] ,
132
145
[ text ( "Clear completed" ) ]
133
146
)
134
147
] )
0 commit comments