diff --git a/chatto/src/main/resources/static/js/chat.js b/chatto/src/main/resources/static/js/chat.js index 11a9e40..971e0c7 100644 --- a/chatto/src/main/resources/static/js/chat.js +++ b/chatto/src/main/resources/static/js/chat.js @@ -35,6 +35,34 @@ var msgContainerSendTemplate = Handlebars.compile(source); var chatAreaNew = document.getElementById('chat_area_new'); +var userBoxes = document.getElementsByName('user-box'); + +// Loop through the buttons and add the active class to the current/clicked button +// for (var i = 0; i < btns.length; i++) { +// btns[i].addEventListener("click", function() { +// var current = document.getElementsByClassName("active"); + +// // If there's no active class +// if (current.length > 0) { +// current[0].className = current[0].className.replace(" active", ""); +// } + +// // Add the active class to the current/clicked button +// this.className += " active"; +// }); +// } + +for (let i = 0; i < userBoxes.length; i++) { + userBoxes[i].addEventListener('click', function() { + let current = document.getElementsByClassName('user-box active'); + if (current.length > 0) { + current[0].className = current[0].className.replace(" active", ""); + } + // Add the active class to the current/clicked button + this.className += " active"; + }) +} + // var lastMessageTimeStamp; // console.log(authToken); @@ -220,12 +248,7 @@ parent.addDelegatedListener("click", "input[type='radio']", function(event) { let messageLog = []; let messageLogNew = []; let lastMessageTimeStamp; - // console.log("Json length = " + json.length); - // - // if(json.length == 0) - // { - // console.log("JSON LENGTH IS 0") - // } + if (json.length > 0) { json.forEach(function(obj) { // console.log(obj.toUser); @@ -316,7 +339,7 @@ parent.addDelegatedListener("click", "input[type='radio']", function(event) { }) sessionStorage.setItem(this.value + '-time', lastMessageTimeStamp); sessionStorage.setItem(this.value, JSON.stringify(storedMessages)); - sessionStorage.setItem(this.value+'new', JSON.stringify(storedMessagesNew)); + sessionStorage.setItem(this.value + 'new', JSON.stringify(storedMessagesNew)); console.log("this value stored" + sessionStorage.getItem(this.value)) console.log("last message time stamp = " + lastMessageTimeStamp); console.log(sessionStorage.getItem(this.value + '-time')); diff --git a/chatto/src/main/resources/templates/chat.html b/chatto/src/main/resources/templates/chat.html index 50fe2d4..71dce53 100644 --- a/chatto/src/main/resources/templates/chat.html +++ b/chatto/src/main/resources/templates/chat.html @@ -72,7 +72,7 @@ -
  • +
  • @@ -80,7 +80,7 @@