-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JS: count & input messages (broken icons)
- Loading branch information
Showing
2 changed files
with
78 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
function run() { | ||
var button = document.getElementsByClassName('btn-add')[0]; | ||
|
||
button.addEventListener('click', onAddButtonClick); | ||
updateCounter(); | ||
} | ||
|
||
function onAddButtonClick() { | ||
var message = document.getElementsByClassName('messageText')[0]; | ||
|
||
addMessage(message.value); | ||
message.value = ''; | ||
updateCounter(); | ||
} | ||
|
||
function addMessage(value) { | ||
if(!value){ | ||
return; | ||
} | ||
|
||
var table = document.getElementsByClassName('table')[0]; | ||
var row = table.insertRow(-1); | ||
createRowValues(row, value); | ||
|
||
updateCounter(); | ||
} | ||
|
||
/*<tr class="item"> | ||
<td class="col-time"><time>2015-02-26</time></td> | ||
<td class="col-message">Person 1: Message 1.</td> | ||
<td class="col-edit"><a class="btn-default" href="#"><i class="glyphicon glyphicon-edit"></i></a></td> | ||
<td class="col-delete"><a class="btn-default" href="#"><i class="glyphicon glyphicon-remove"></i></a></td> | ||
</tr>*/ | ||
|
||
function createRowValues(row, text){ | ||
var tdTime = document.createElement('td'); | ||
var tdMessage = document.createElement('td'); | ||
var tdEdit = document.createElement('td'); | ||
var tdRemove = document.createElement('td'); | ||
|
||
row.classList.add('item'); | ||
tdTime.classList.add('col-time'); | ||
tdMessage.classList.add('col-message'); | ||
tdEdit.classList.add('col-edit'); | ||
tdRemove.classList.add('col-delete'); | ||
|
||
tdTime.appendChild(document.createTextNode("2015-03-03")); | ||
tdMessage.appendChild(document.createTextNode(text)); | ||
tdEdit.innerHTML = "<a class="btn-default" href="#"><i class="glyphicon glyphicon-edit"></i></a>"; | ||
tdRemove.innerHTML = "<a class="btn-default" href="#"><i class="glyphicon glyphicon-remove"></i></a>"; | ||
|
||
row.appendChild(tdTime); | ||
row.appendChild(tdMessage); | ||
row.appendChild(tdEdit); | ||
row.appendChild(tdRemove); | ||
|
||
//return row; | ||
} | ||
|
||
function updateCounter(){ | ||
var counter = document.getElementsByClassName('counter-holder')[0]; | ||
var count = document.getElementsByClassName("items")[0].rows.length; | ||
|
||
counter.innerText = count.toString(); | ||
} |