From 5d0305e8f284fe9ce0ec47325a6fd56508ce65f4 Mon Sep 17 00:00:00 2001 From: nanalelfe Date: Sun, 28 Aug 2016 01:50:33 -0400 Subject: Integrated socketst.io and setup the notification function --- assets/js/script.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'assets/js/script.js') diff --git a/assets/js/script.js b/assets/js/script.js index 7a4c21f..a49ff45 100644 --- a/assets/js/script.js +++ b/assets/js/script.js @@ -1,4 +1,29 @@ function main(){ + + var socket = io('http://localhost:3000'); + socket.on('alert', function (data) { + console.log(data); + socket.emit('my other event', { my: 'data' }); + }); + + socket.on('new_solution', function (data) { + console.log("new solution: "); + console.log(data); + + var $notification_menu = $(".notification-dropdown-menu"); + //$notification_menu.remove($('li a.generic-notification')); + + var $li = $('
  • '); + var $a = $('').text(data.author + " has added a solution to an exam."); + $li.append($a); + $notification_menu.append($li); + + socket.emit('add_notification', data); + + // emit back to the server to save it as a notification in the database + // update badge + }); + // --- nav scripts --- $("input").keyup( function(event) { if(event.keyCode == 13){ @@ -7,7 +32,7 @@ function main(){ }); $(".dropdown").hover(function(){ - $(".dropdown-toggle", this).trigger("click"); + //$(".dropdown-toggle", this).trigger("click"); }); $(".dropdown-toggle").click(function() { -- cgit v1.2.3