From bd6d69d7a70451a9a587c9ee54b6025d1b27f4ce Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Wed, 12 Oct 2016 17:47:25 +0800 Subject: [PATCH 1/4] Fix to handle checkAllNotesRevision might return null notes --- app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.js b/app.js index b877bc8..b8034ad 100644 --- a/app.js +++ b/app.js @@ -512,7 +512,7 @@ process.on('SIGINT', function () { if (history.isReady() && realtime.isReady()) { models.Revision.checkAllNotesRevision(function (err, notes) { if (err) throw new Error(err); - if (notes.length <= 0) { + if (!notes || notes.length <= 0) { clearInterval(checkCleanTimer); return process.exit(0); } From 12b7646f247f2325c8d4593480571868b0783612 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Wed, 12 Oct 2016 17:48:28 +0800 Subject: [PATCH 2/4] Fix to handle name or color might get undefined error --- public/js/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/public/js/index.js b/public/js/index.js index 30d9e4e..06be2f7 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -2792,14 +2792,14 @@ function sortOnlineUserList(list) { else if (usera.idle && !userb.idle) return 1; else { - if (usera.name.toLowerCase() < userb.name.toLowerCase()) { + if (usera.name && usera.name.toLowerCase() < userb.name.toLowerCase()) { return -1; - } else if (usera.name.toLowerCase() > userb.name.toLowerCase()) { + } else if (usera.name && usera.name.toLowerCase() > userb.name.toLowerCase()) { return 1; } else { - if (usera.color.toLowerCase() < userb.color.toLowerCase()) + if (usera.color && usera.color.toLowerCase() < userb.color.toLowerCase()) return -1; - else if (usera.color.toLowerCase() > userb.color.toLowerCase()) + else if (usera.color && usera.color.toLowerCase() > userb.color.toLowerCase()) return 1; else return 0; From f3d4b55856e1d7f043831c5d8fcf92bc74395605 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Wed, 12 Oct 2016 17:50:01 +0800 Subject: [PATCH 3/4] Fix getCaretPosition in text complete might get undefined position error --- .../jquery.textcomplete.js | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/public/vendor/jquery-textcomplete/jquery.textcomplete.js b/public/vendor/jquery-textcomplete/jquery.textcomplete.js index e1d90d0..cd2f863 100755 --- a/public/vendor/jquery-textcomplete/jquery.textcomplete.js +++ b/public/vendor/jquery-textcomplete/jquery.textcomplete.js @@ -863,16 +863,31 @@ if (typeof jQuery === 'undefined') { // // FIXME: Calculate the left top corner of `this.option.appendTo` element. getCaretPosition: function () { - //var position = this._getCaretRelativePosition(); - //var offset = this.$el.offset(); - //var offset = $('.CodeMirror-cursor').offset(); - var position = $('.CodeMirror-cursor').position(); - var menu = $('.cursor-menu .dropdown-menu'); - var offsetLeft = parseFloat(menu.attr('data-offset-left')); - var offsetTop = parseFloat(menu.attr('data-offset-top')); - position.left += offsetLeft; - position.top += offsetTop; - return position; + if ($('.CodeMirror-cursor').length > 0) { + var position = $('.CodeMirror-cursor').position(); + var menu = $('.cursor-menu .dropdown-menu'); + var offsetLeft = parseFloat(menu.attr('data-offset-left')); + var offsetTop = parseFloat(menu.attr('data-offset-top')); + position.left += offsetLeft; + position.top += offsetTop; + return position; + } else { + var position = this._getCaretRelativePosition(); + var offset = this.$el.offset(); + + // Calculate the left top corner of `this.option.appendTo` element. + var $parent = this.option.appendTo; + if ($parent) { + if (!($parent instanceof $)) { $parent = $($parent); } + var parentOffset = $parent.offsetParent().offset(); + offset.top -= parentOffset.top; + offset.left -= parentOffset.left; + } + + position.top += offset.top; + position.left += offset.left; + return position; + } }, // Focus on the element. From c98d2639286344188f50045ab2e28a157df7ddf7 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Wed, 12 Oct 2016 17:50:36 +0800 Subject: [PATCH 4/4] Fix to handle undefined document on update history --- lib/realtime.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/realtime.js b/lib/realtime.js index ea3735a..d069a48 100644 --- a/lib/realtime.js +++ b/lib/realtime.js @@ -396,7 +396,7 @@ function finishConnection(socket, note, user) { // update user note history setTimeout(function () { var noteId = note.alias ? note.alias : LZString.compressToBase64(note.id); - history.updateHistory(user.userid, noteId, note.server.document); + if (note.server) history.updateHistory(user.userid, noteId, note.server.document); }, 0); emitOnlineUsers(socket); @@ -669,7 +669,7 @@ function operationCallback(socket, operation) { // update user note history setTimeout(function() { var noteId = note.alias ? note.alias : LZString.compressToBase64(note.id); - history.updateHistory(userId, noteId, note.server.document); + if (note.server) history.updateHistory(userId, noteId, note.server.document); }, 0); }