From b54b3cbe6957b46d3b689b0108b0b767b7da261b Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 20:48:56 +0800 Subject: [PATCH] Add more comments in the code and remove unused code file --- lib/realtime.js | 3 +++ public/js/unused.js | 45 --------------------------------------------- 2 files changed, 3 insertions(+), 45 deletions(-) delete mode 100644 public/js/unused.js diff --git a/lib/realtime.js b/lib/realtime.js index ae624c2..c9c6543 100644 --- a/lib/realtime.js +++ b/lib/realtime.js @@ -518,13 +518,16 @@ function disconnect(socket) { var noteId = socket.noteId; var note = notes[noteId]; if (note) { + // delete user in users delete note.users[socket.id]; + // remove sockets in the note socks do { var index = note.socks.indexOf(socket); if (index != -1) { note.socks.splice(index, 1); } } while (index != -1); + // remove note in notes if no user inside if (Object.keys(note.users).length <= 0) { if (note.server.isDirty) { updateNote(note, function (err, _note) { diff --git a/public/js/unused.js b/public/js/unused.js deleted file mode 100644 index 4ff5b28..0000000 --- a/public/js/unused.js +++ /dev/null @@ -1,45 +0,0 @@ - - //parse Youtube - result.find(".youtube").each(function (key, value) { - if (!$(value).attr('videoid')) return; - setSizebyAttr(this, this); - var icon = ''; - $(this).append(icon); - var videoid = $(value).attr('videoid'); - var thumbnail_src = '//img.youtube.com/vi/' + videoid + '/hqdefault.jpg'; - $(value).css('background-image', 'url(' + thumbnail_src + ')'); - $(this).click(function () { - imgPlayiframe(this, '//www.youtube.com/embed/'); - }); - }); - //parse vimeo - result.find(".vimeo").each(function (key, value) { - if (!$(value).attr('videoid')) return; - setSizebyAttr(this, this); - var icon = ''; - $(this).append(icon); - var videoid = $(value).attr('videoid'); - $.ajax({ - type: 'GET', - url: 'http://vimeo.com/api/v2/video/' + videoid + '.json', - jsonp: 'callback', - dataType: 'jsonp', - success: function (data) { - var thumbnail_src = data[0].thumbnail_large; - $(value).css('background-image', 'url(' + thumbnail_src + ')'); - } - }); - $(this).click(function () { - imgPlayiframe(this, '//player.vimeo.com/video/'); - }); - }); - //todo list - var lis = result[0].getElementsByTagName('li'); - for (var i = 0; i < lis.length; i++) { - var html = lis[i].innerHTML; - if (/^\s*\[[x ]\]\s*/.test(html)) { - lis[i].innerHTML = html.replace(/^\s*\[ \]\s*/, '') - .replace(/^\s*\[x\]\s*/, ''); - lis[i].setAttribute('class', 'task-list-item'); - } - } \ No newline at end of file