Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dojo-javascript
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Daniel González Peña
dojo-javascript
Commits
bbb4b4ce
Commit
bbb4b4ce
authored
Apr 05, 2017
by
Daniel González Peña
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit
parents
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
282 additions
and
0 deletions
+282
-0
README.md
README.md
+4
-0
index.html
todo-list-handlebars/index.html
+61
-0
todocontroller.js
todo-list-handlebars/todocontroller.js
+66
-0
index.html
todo-list-vanilla/index.html
+50
-0
todocontroller.js
todo-list-vanilla/todocontroller.js
+101
-0
No files found.
README.md
0 → 100644
View file @
bbb4b4ce
# Dojo-Javascript
A todo list without model-view binding frameworks
todo-list-handlebars/index.html
0 → 100644
View file @
bbb4b4ce
<!DOCTYPE html>
<html>
<head>
<script
src=
"todocontroller.js"
></script>
<script
src=
"https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.6/handlebars.min.js"
></script>
<style>
#todos
{
list-style-type
:
none
;
}
.todo-item
{
padding-top
:
10px
;
padding-bottom
:
10px
;
vertical-align
:
middle
;
}
.todo-item
span
{
cursor
:
pointer
;
}
.todo-item
input
{
float
:
right
;
}
.todo-item.done
{
background-color
:
lightgrey
;
}
.hidden
{
display
:
none
;
}
</style>
<script
id=
"todo-list-template"
type=
"text/x-handlebars-template"
>
{{
#
each
this
}}
<
li
id
=
"todo-item-{{@index}}"
class
=
"todo-item {{#if done}}done{{/if}}"
>
<
span
class
=
"name"
>
{{
name
}}
<
/span
>
<
input
value
=
"{{#if done}}Reopen{{else}}Close{{/if}}"
id
=
"done-item-{{@index}}"
type
=
"button"
>
<
div
class
=
"description hidden"
>
{{
description
}}
<
/div
>
<
/li
>
{{
/
each
}}
</script>
</head>
<body
onload=
"todocontroller.init()"
>
<h1>
Todo List
</h1>
<ul
id=
"todos"
>
</ul>
<form>
Name:
<input
type=
"text"
id=
"todo-name"
><br>
Description:
<br>
<textarea
id=
"todo-description"
></textarea><br>
<input
type=
"button"
id=
"add-button"
value=
"Add"
></input>
</form>
</body>
</html>
\ No newline at end of file
todo-list-handlebars/todocontroller.js
0 → 100644
View file @
bbb4b4ce
class
TodoController
{
constructor
()
{
this
.
todos
=
[{
name
:
'lunch'
,
description
:
'13.00h, A Palleira Restaurant'
},
{
name
:
'dojo'
,
description
:
'17.00h. Create a todo list!'
},
];
}
init
()
{
this
.
updateTodos
();
this
.
createAddButtonListener
();
}
updateTodos
()
{
// <---- full render!!
var
render
=
Handlebars
.
compile
(
document
.
getElementById
(
'todo-list-template'
).
innerHTML
);
var
html
=
render
(
this
.
todos
);
document
.
getElementById
(
'todos'
).
innerHTML
=
html
;
// <--- DOM Destroyed
this
.
createTodoListeners
();
}
toggleDoneItem
(
todo
)
{
return
()
=>
{
console
.
log
(
'closing item'
);
todo
.
done
=
!
todo
.
done
;
this
.
updateTodos
();
// <---- force re-render
}
}
createAddButtonListener
()
{
document
.
getElementById
(
'add-button'
).
addEventListener
(
'click'
,
()
=>
{
var
newTodoName
=
document
.
getElementById
(
'todo-name'
).
value
;
var
newTodoDescription
=
document
.
getElementById
(
'todo-description'
).
value
;
this
.
todos
.
push
({
name
:
newTodoName
,
description
:
newTodoDescription
});
this
.
updateTodos
();
// <--- force re-render
});
}
createTodoListeners
()
{
this
.
todos
.
forEach
((
todo
,
index
)
=>
{
document
.
getElementById
(
'done-item-'
+
index
).
addEventListener
(
'click'
,
this
.
toggleDoneItem
(
todo
));
document
.
getElementById
(
'todo-item-'
+
index
)
.
getElementsByClassName
(
'name'
)[
0
].
addEventListener
(
'click'
,
(
event
)
=>
{
event
.
target
.
parentNode
.
getElementsByClassName
(
'description'
)[
0
]
.
classList
.
toggle
(
'hidden'
);
})
});
}
}
var
todocontroller
=
new
TodoController
();
\ No newline at end of file
todo-list-vanilla/index.html
0 → 100644
View file @
bbb4b4ce
<!DOCTYPE html>
<html>
<head>
<script
src=
"todocontroller.js"
></script>
<style>
#todos
{
list-style-type
:
none
;
}
.todo-item
{
padding-top
:
10px
;
padding-bottom
:
10px
;
vertical-align
:
middle
;
}
.todo-item
span
{
cursor
:
pointer
;
}
.todo-item
input
{
float
:
right
;
}
.todo-item.done
{
background-color
:
lightgrey
;
}
.hidden
{
display
:
none
;
}
</style>
</head>
<body
onload=
"todocontroller.init()"
>
<h1>
Todo List
</h1>
<ul
id=
"todos"
>
</ul>
<form>
Name:
<input
type=
"text"
id=
"todo-name"
><br>
Description:
<br>
<textarea
id=
"todo-description"
></textarea><br>
<input
type=
"button"
id=
"add-button"
value=
"Add"
></input>
</form>
</body>
</html>
\ No newline at end of file
todo-list-vanilla/todocontroller.js
0 → 100644
View file @
bbb4b4ce
class
TodoController
{
constructor
()
{
this
.
todos
=
[{
name
:
'lunch'
,
description
:
'13.00h, A Palleira Restaurant'
},
{
name
:
'dojo'
,
description
:
'17.00h. Create a todo list!'
},
];
}
init
()
{
this
.
updateTodos
();
this
.
createAddButtonListener
();
}
updateTodos
()
{
// <---- full render!!
var
todosListElement
=
document
.
getElementById
(
'todos'
);
todosListElement
.
innerHTML
=
''
;
// <--- DOM destroyed!
this
.
todos
.
forEach
((
todo
,
index
)
=>
{
var
todoItemElement
=
document
.
createElement
(
'li'
);
todoItemElement
.
id
=
'todo-item-'
+
index
;
var
todoItemLabelElement
=
document
.
createElement
(
'span'
);
todoItemLabelElement
.
classList
.
add
(
'name'
);
todoItemLabelElement
.
innerHTML
=
todo
.
name
;
var
todoItemDescriptionElement
=
document
.
createElement
(
'div'
);
todoItemDescriptionElement
.
innerHTML
=
todo
.
description
;
todoItemDescriptionElement
.
classList
.
add
(
'description'
);
todoItemDescriptionElement
.
classList
.
add
(
'hidden'
);
todoItemElement
.
classList
.
add
(
'todo-item'
);
if
(
todo
.
done
)
{
todoItemElement
.
classList
.
add
(
'done'
);
}
todoItemElement
.
appendChild
(
todoItemLabelElement
);
var
todoItemDoneButton
=
document
.
createElement
(
'input'
);
todoItemDoneButton
.
type
=
'button'
;
todoItemDoneButton
.
value
=
todo
.
done
?
'Reopen'
:
'Done'
;
todoItemDoneButton
.
id
=
'done-item-'
+
index
;
todoItemElement
.
appendChild
(
todoItemDoneButton
);
todoItemElement
.
appendChild
(
todoItemDescriptionElement
);
todosListElement
.
appendChild
(
todoItemElement
);
});
this
.
createTodoListeners
();
}
toggleDoneItem
(
todo
)
{
return
()
=>
{
console
.
log
(
'closing item'
);
todo
.
done
=
!
todo
.
done
;
this
.
updateTodos
();
// <---- force re-render
}
}
createAddButtonListener
()
{
document
.
getElementById
(
'add-button'
).
addEventListener
(
'click'
,
()
=>
{
var
newTodoName
=
document
.
getElementById
(
'todo-name'
).
value
;
var
newTodoDescription
=
document
.
getElementById
(
'todo-description'
).
value
;
this
.
todos
.
push
({
name
:
newTodoName
,
description
:
newTodoDescription
});
this
.
updateTodos
();
// <--- force re-render
});
}
createTodoListeners
()
{
this
.
todos
.
forEach
((
todo
,
index
)
=>
{
document
.
getElementById
(
'done-item-'
+
index
).
addEventListener
(
'click'
,
this
.
toggleDoneItem
(
todo
));
document
.
getElementById
(
'todo-item-'
+
index
)
.
getElementsByClassName
(
'name'
)[
0
].
addEventListener
(
'click'
,
(
event
)
=>
{
event
.
target
.
parentNode
.
getElementsByClassName
(
'description'
)[
0
]
.
classList
.
toggle
(
'hidden'
);
})
});
}
}
var
todocontroller
=
new
TodoController
();
\ No newline at end of file
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