From bf4c6d021c353f9f6779ba813dab8d44b17addbf Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 16:25:51 +0800 Subject: Extract config.js from common.js to make client setting file clean and also make upgrade easier --- public/js/common.js | 85 ++++++++++++++++++++++++++++++++++++++++ public/js/common.js.example | 95 --------------------------------------------- public/js/config.js.example | 10 +++++ 3 files changed, 95 insertions(+), 95 deletions(-) create mode 100644 public/js/common.js delete mode 100644 public/js/common.js.example create mode 100644 public/js/config.js.example (limited to 'public/js') diff --git a/public/js/common.js b/public/js/common.js new file mode 100644 index 00000000..a14e6fc9 --- /dev/null +++ b/public/js/common.js @@ -0,0 +1,85 @@ +//common +var port = window.location.port; +var serverurl = window.location.protocol + '//' + (domain ? domain : window.location.hostname) + (port ? ':' + port : '') + (urlpath ? '/' + urlpath : ''); +var noteid = urlpath ? window.location.pathname.slice(urlpath.length + 1, window.location.pathname.length).split('/')[1] : window.location.pathname.split('/')[1]; +var noteurl = serverurl + '/' + noteid; + +var version = '0.4.4'; + +var checkAuth = false; +var profile = null; +var lastLoginState = getLoginState(); +var lastUserId = getUserId(); +var loginStateChangeEvent = null; + +function resetCheckAuth() { + checkAuth = false; +} + +function setLoginState(bool, id) { + Cookies.set('loginstate', bool, { + expires: 365 + }); + if (id) { + Cookies.set('userid', id, { + expires: 365 + }); + } else { + Cookies.remove('userid'); + } + lastLoginState = bool; + lastUserId = id; + checkLoginStateChanged(); +} + +function checkLoginStateChanged() { + if (getLoginState() != lastLoginState || getUserId() != lastUserId) { + if(loginStateChangeEvent) + loginStateChangeEvent(); + return true; + } else { + return false; + } +} + +function getLoginState() { + var state = Cookies.get('loginstate'); + return state === "true" || state === true; +} + +function getUserId() { + return Cookies.get('userid'); +} + +function clearLoginState() { + Cookies.remove('loginstate'); +} + +function checkIfAuth(yesCallback, noCallback) { + var cookieLoginState = getLoginState(); + if (checkLoginStateChanged()) + checkAuth = false; + if (!checkAuth || typeof cookieLoginState == 'undefined') { + $.get(serverurl + '/me') + .done(function (data) { + if (data && data.status == 'ok') { + profile = data; + yesCallback(profile); + setLoginState(true, data.id); + } else { + noCallback(); + setLoginState(false); + } + }) + .fail(function () { + noCallback(); + }) + .always(function () { + checkAuth = true; + }); + } else if (cookieLoginState) { + yesCallback(profile); + } else { + noCallback(); + } +} \ No newline at end of file diff --git a/public/js/common.js.example b/public/js/common.js.example deleted file mode 100644 index 11c32acc..00000000 --- a/public/js/common.js.example +++ /dev/null @@ -1,95 +0,0 @@ -//common -var domain = ''; // domain name -var urlpath = ''; // sub url path, like: www.example.com/ -//settings -var debug = false; - -var GOOGLE_API_KEY = ''; -var GOOGLE_CLIENT_ID = ''; - -var DROPBOX_APP_KEY = ''; - -var port = window.location.port; -var serverurl = window.location.protocol + '//' + (domain ? domain : window.location.hostname) + (port ? ':' + port : '') + (urlpath ? '/' + urlpath : ''); -var noteid = urlpath ? window.location.pathname.slice(urlpath.length + 1, window.location.pathname.length).split('/')[1] : window.location.pathname.split('/')[1]; -var noteurl = serverurl + '/' + noteid; - -var version = '0.4.4'; - -var checkAuth = false; -var profile = null; -var lastLoginState = getLoginState(); -var lastUserId = getUserId(); -var loginStateChangeEvent = null; - -function resetCheckAuth() { - checkAuth = false; -} - -function setLoginState(bool, id) { - Cookies.set('loginstate', bool, { - expires: 365 - }); - if (id) { - Cookies.set('userid', id, { - expires: 365 - }); - } else { - Cookies.remove('userid'); - } - lastLoginState = bool; - lastUserId = id; - checkLoginStateChanged(); -} - -function checkLoginStateChanged() { - if (getLoginState() != lastLoginState || getUserId() != lastUserId) { - if(loginStateChangeEvent) - loginStateChangeEvent(); - return true; - } else { - return false; - } -} - -function getLoginState() { - var state = Cookies.get('loginstate'); - return state === "true" || state === true; -} - -function getUserId() { - return Cookies.get('userid'); -} - -function clearLoginState() { - Cookies.remove('loginstate'); -} - -function checkIfAuth(yesCallback, noCallback) { - var cookieLoginState = getLoginState(); - if (checkLoginStateChanged()) - checkAuth = false; - if (!checkAuth || typeof cookieLoginState == 'undefined') { - $.get(serverurl + '/me') - .done(function (data) { - if (data && data.status == 'ok') { - profile = data; - yesCallback(profile); - setLoginState(true, data.id); - } else { - noCallback(); - setLoginState(false); - } - }) - .fail(function () { - noCallback(); - }) - .always(function () { - checkAuth = true; - }); - } else if (cookieLoginState) { - yesCallback(profile); - } else { - noCallback(); - } -} \ No newline at end of file diff --git a/public/js/config.js.example b/public/js/config.js.example new file mode 100644 index 00000000..197d18f2 --- /dev/null +++ b/public/js/config.js.example @@ -0,0 +1,10 @@ +//config +var domain = ''; // domain name +var urlpath = ''; // sub url path, like: www.example.com/ +//settings +var debug = false; + +var GOOGLE_API_KEY = ''; +var GOOGLE_CLIENT_ID = ''; + +var DROPBOX_APP_KEY = ''; \ No newline at end of file -- cgit v1.2.3 From 7a85d62b774ed6f26d0cfd772b4adf312c85f0ce Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 20:26:12 +0800 Subject: Remove unused code --- public/js/index.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index 03729de4..4b8ae715 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -2489,7 +2489,6 @@ socket.on('permission', function (data) { updatePermission(data.permission); }); var docmaxlength = null; -var otk = null; var owner = null; var permission = null; socket.on('refresh', function (data) { @@ -2498,7 +2497,6 @@ socket.on('refresh', function (data) { //console.log(data); docmaxlength = data.docmaxlength; editor.setOption("maxLength", docmaxlength); - otk = data.otk; owner = data.owner; updatePermission(data.permission); updateLastInfo(data); -- cgit v1.2.3 From 3175616573a9346f8ae2731a8a963b28c42224c3 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 20:32:20 +0800 Subject: Update to support showing owner on the infobar --- public/js/extra.js | 18 ++++++++++++++++++ public/js/index.js | 14 +++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) (limited to 'public/js') diff --git a/public/js/extra.js b/public/js/extra.js index 77f298f9..6c2e2d4a 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -7,6 +7,7 @@ var lastchangeui = { user: $(".ui-lastchangeuser"), nouser: $(".ui-no-lastchangeuser") } +var ownerui = $(".ui-owner"); function updateLastChange() { if (!lastchangeui) return; @@ -41,6 +42,23 @@ function updateLastChangeUser() { } } +var owner = null; +var ownerprofile = null; +function updateOwner() { + if (ownerui) { + if (owner && ownerprofile && owner !== lastchangeuser) { + var icon = ownerui.children('i'); + icon.attr('title', ownerprofile.name).tooltip('fixTitle'); + var styleString = 'background-image:url(' + ownerprofile.photo + ')'; + if (ownerprofile.photo && icon.attr('style') !== styleString) + icon.attr('style', styleString); + ownerui.show(); + } else { + ownerui.hide(); + } + } +} + //get title function getTitle(view) { var title = ""; diff --git a/public/js/index.js b/public/js/index.js index 4b8ae715..5681dcf3 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -2255,7 +2255,7 @@ var authorship = []; var authorshipMarks = {}; var authorMarks = {}; // temp variable var addTextMarkers = []; // temp variable -function updateLastInfo(data) { +function updateInfo(data) { //console.log(data); if (data.hasOwnProperty('createtime') && createtime !== data.createtime) { createtime = data.createtime; @@ -2265,10 +2265,16 @@ function updateLastInfo(data) { lastchangetime = data.updatetime; updateLastChange(); } + if (data.hasOwnProperty('owner') && owner !== data.owner) { + owner = data.owner; + ownerprofile = data.ownerprofile; + updateOwner(); + } if (data.hasOwnProperty('lastchangeuser') && lastchangeuser !== data.lastchangeuser) { lastchangeuser = data.lastchangeuser; lastchangeuserprofile = data.lastchangeuserprofile; updateLastChangeUser(); + updateOwner(); } if (data.hasOwnProperty('authors') && authors !== data.authors) { authors = data.authors; @@ -2483,13 +2489,12 @@ socket.on('check', function (data) { data = LZString.decompressFromUTF16(data); data = JSON.parse(data); //console.log(data); - updateLastInfo(data); + updateInfo(data); }); socket.on('permission', function (data) { updatePermission(data.permission); }); var docmaxlength = null; -var owner = null; var permission = null; socket.on('refresh', function (data) { data = LZString.decompressFromUTF16(data); @@ -2497,9 +2502,8 @@ socket.on('refresh', function (data) { //console.log(data); docmaxlength = data.docmaxlength; editor.setOption("maxLength", docmaxlength); - owner = data.owner; + updateInfo(data); updatePermission(data.permission); - updateLastInfo(data); if (!loaded) { // auto change mode if no content detected var nocontent = editor.getValue().length <= 0; -- cgit v1.2.3 From 72d7ba0f313eb1c72d11f5a8406acb41aa844588 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 20:33:17 +0800 Subject: Update to remind note max length limit on the status bar length div --- public/js/index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index 5681dcf3..57658d69 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -677,7 +677,18 @@ function updateStatusBar() { statusCursor.text(cursorText); var fileText = ' — ' + editor.lineCount() + ' Lines'; statusFile.text(fileText); - statusLength.text('Length ' + editor.getValue().length); + var docLength = editor.getValue().length; + statusLength.text('Length ' + docLength); + if (docLength > (docmaxlength * 0.95)) { + statusLength.css('color', 'red'); + statusLength.attr('title', 'Your almost reach note max length limit.'); + } else if (docLength > (docmaxlength * 0.8)) { + statusLength.css('color', 'orange'); + statusLength.attr('title', 'You nearly fill the note, consider to make more pieces.'); + } else { + statusLength.css('color', 'white'); + statusLength.attr('title', 'You could write up to ' + docmaxlength + ' characters in this note.'); + } } //ui vars -- cgit v1.2.3 From c9f5cd49b0946b116a86fdd9cb4938a03fc96e1a Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 20:42:40 +0800 Subject: Fix potential error --- public/js/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index 57658d69..323da283 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -2335,7 +2335,7 @@ var addStyleRule = (function () { }()); function updateAuthorshipInner() { // ignore when ot not synced yet - if (Object.keys(cmClient.state).length > 0) return; + if (cmClient && Object.keys(cmClient.state).length > 0) return; authorMarks = {}; for (var i = 0; i < authorship.length; i++) { var atom = authorship[i]; -- cgit v1.2.3 From 521f76f7add074c4bbd200dc270cefc57e38f806 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 20:44:45 +0800 Subject: Update to make OT error, client reconnect handling better and refactor client "doc" event --- public/js/index.js | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index 323da283..575baca2 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -2219,6 +2219,7 @@ socket.on('error', function (data) { var retryOnDisconnect = false; var retryTimer = null; socket.on('maintenance', function () { + cmClient.revision = -1; retryOnDisconnect = true; }); socket.on('disconnect', function (data) { @@ -2557,16 +2558,14 @@ socket.on('doc', function (obj) { obj = LZString.decompressFromUTF16(obj); obj = JSON.parse(obj); var body = obj.str; - var bodyMismatch = (editor.getValue() != body); + var bodyMismatch = editor.getValue() !== body; + var setDoc = !cmClient || (cmClient && cmClient.revision === -1) || obj.force; saveInfo(); - if (bodyMismatch) { - if (cmClient) - cmClient.editorAdapter.ignoreNextChange = true; - if (body) - editor.setValue(body); - else - editor.setValue(""); + if (setDoc && bodyMismatch) { + if (cmClient) cmClient.editorAdapter.ignoreNextChange = true; + if (body) editor.setValue(body); + else editor.setValue(""); } if (!loaded) { @@ -2575,12 +2574,8 @@ socket.on('doc', function (obj) { ui.content.fadeIn(); } else { //if current doc is equal to the doc before disconnect - if (bodyMismatch) - editor.clearHistory(); - else { - if (lastInfo.history) - editor.setHistory(lastInfo.history); - } + if (setDoc && bodyMismatch) editor.clearHistory(); + else if (lastInfo.history) editor.setHistory(lastInfo.history); lastInfo.history = null; } @@ -2589,7 +2584,7 @@ socket.on('doc', function (obj) { obj.revision, obj.clients, new SocketIOAdapter(socket), new CodeMirrorAdapter(editor) ); - } else { + } else if (setDoc) { if (bodyMismatch) { cmClient.undoManager.undoStack.length = 0; cmClient.undoManager.redoStack.length = 0; @@ -2600,7 +2595,7 @@ socket.on('doc', function (obj) { cmClient.initializeClients(obj.clients); } - if (bodyMismatch) { + if (setDoc && bodyMismatch) { isDirty = true; updateView(); } -- cgit v1.2.3 From 1d1eedce7ee8c2bd776b45afc2ccb5d626394db4 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 20:45:49 +0800 Subject: Improve syntax highlighting performance by moving it to finish view --- public/js/extra.js | 45 +++++++++++++++++++++++++++++++-------------- public/js/syncscroll.js | 2 +- 2 files changed, 32 insertions(+), 15 deletions(-) (limited to 'public/js') diff --git a/public/js/extra.js b/public/js/extra.js index 6c2e2d4a..4a6c4a67 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -435,6 +435,33 @@ function finishView(view) { height: '400px' }); }); + //syntax highlighting + view.find("pre.raw").removeClass("raw") + .each(function (key, value) { + var langDiv = $(value).find('code.hljs'); + if (langDiv.length > 0) { + var reallang = langDiv[0].className.replace('hljs', '').trim(); + var codeDiv = $(value).find('.code'); + var code = ""; + if (codeDiv.length > 0) code = codeDiv.html(); + else code = langDiv.html(); + code = md.utils.unescapeAll(code); + if (reallang == "tiddlywiki" || reallang == "mediawiki") { + var result = { + value: Prism.highlight(code, Prism.languages.wiki) + }; + } else { + var languages = hljs.listLanguages(); + if (languages.indexOf(reallang) == -1) { + var result = hljs.highlightAuto(code); + } else { + var result = hljs.highlight(reallang, code); + } + } + if (codeDiv.length > 0) codeDiv.html(result.value); + else langDiv.html(result.value); + } + }); //render title document.title = renderTitle(view); } @@ -772,19 +799,9 @@ function highlightRender(code, lang) { } else if (lang == 'mermaid') { return '
' + code + '
'; } - var reallang = lang.replace(/\=$|\=\d+$|\=\+$/, ''); - if (reallang == "tiddlywiki" || reallang == "mediawiki") { - var result = { - value: Prism.highlight(code, Prism.languages.wiki) - }; - } else { - var languages = hljs.listLanguages(); - if (languages.indexOf(reallang) == -1) { - var result = hljs.highlightAuto(code); - } else { - var result = hljs.highlight(reallang, code); - } - } + var result = { + value: code + }; var showlinenumbers = /\=$|\=\d+$|\=\+$/.test(lang); if (showlinenumbers) { var startnumber = 1; @@ -878,7 +895,7 @@ md.renderer.rules.fence = function (tokens, idx, options, env, self) { return highlighted + '\n'; } - return '
'
+    return  '
'
         + highlighted
         + '
\n'; }; diff --git a/public/js/syncscroll.js b/public/js/syncscroll.js index 96663f77..32d3f7a3 100644 --- a/public/js/syncscroll.js +++ b/public/js/syncscroll.js @@ -75,7 +75,7 @@ md.renderer.rules.fence = function (tokens, idx, options, env, self) { if (tokens[idx].map && tokens[idx].level === 0) { var startline = tokens[idx].map[0] + 1; var endline = tokens[idx].map[1]; - return '
'
+        return '
'
         + highlighted
         + '
\n'; } -- cgit v1.2.3 From 550746b70edb13fdd6eafecfe48af5c5b57db2ee Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 20:46:06 +0800 Subject: Update default indent to use spaces instead of tabs --- public/js/index.js | 1 - 1 file changed, 1 deletion(-) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index 575baca2..a50dacaa 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -369,7 +369,6 @@ var editor = CodeMirror.fromTextArea(textit, { showCursorWhenSelecting: true, highlightSelectionMatches: true, indentUnit: 4, - indentWithTabs: true, continueComments: "Enter", theme: "one-dark", inputStyle: "textarea", -- cgit v1.2.3 From e4b40d11a20c4d6ab0676f7fe82a2421f8bf0800 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 20:47:57 +0800 Subject: Update to make editor mode setting to a default variable --- public/js/index.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index a50dacaa..b5ebe954 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -1,6 +1,7 @@ var defaultTextHeight = 20; var viewportMargin = 20; var mac = CodeMirror.keyMap["default"] == CodeMirror.keyMap.macDefault; +var defaultEditorMode = 'gfm'; var defaultExtraKeys = { "F10": function (cm) { cm.setOption("fullScreen", !cm.getOption("fullScreen")); @@ -359,8 +360,8 @@ var fileTypes = { var textit = document.getElementById("textit"); if (!textit) throw new Error("There was no textit area!"); var editor = CodeMirror.fromTextArea(textit, { - mode: 'gfm', - backdrop: 'gfm', + mode: defaultEditorMode, + backdrop: defaultEditorMode, keyMap: "sublime", viewportMargin: viewportMargin, styleActiveLine: true, @@ -603,7 +604,7 @@ function setSpellcheck() { if (cookieSpellcheck === 'true' || cookieSpellcheck === true) { mode = 'spell-checker'; } else { - mode = 'gfm'; + mode = defaultEditorMode; } if (mode && mode !== editor.getOption('mode')) { editor.setOption('mode', mode); @@ -613,10 +614,10 @@ function setSpellcheck() { var spellcheckToggle = statusSpellcheck.find('.ui-spellcheck-toggle'); spellcheckToggle.click(function () { var mode = editor.getOption('mode'); - if (mode == "gfm") { + if (mode == defaultEditorMode) { mode = "spell-checker"; } else { - mode = "gfm"; + mode = defaultEditorMode; } if (mode && mode !== editor.getOption('mode')) { editor.setOption('mode', mode); @@ -628,7 +629,7 @@ function setSpellcheck() { }); function checkSpellcheck() { var mode = editor.getOption('mode'); - if (mode == "gfm") { + if (mode == defaultEditorMode) { spellcheckToggle.removeClass('active'); } else { spellcheckToggle.addClass('active'); @@ -1756,7 +1757,7 @@ function initRevisionViewer() { if (revisionViewer) return; var revisionViewerTextArea = document.getElementById("revisionViewer"); revisionViewer = CodeMirror.fromTextArea(revisionViewerTextArea, { - mode: 'gfm', + mode: defaultEditorMode, viewportMargin: viewportMargin, lineNumbers: true, lineWrapping: true, -- cgit v1.2.3 From b54b3cbe6957b46d3b689b0108b0b767b7da261b Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 20:48:56 +0800 Subject: Add more comments in the code and remove unused code file --- public/js/unused.js | 45 --------------------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 public/js/unused.js (limited to 'public/js') diff --git a/public/js/unused.js b/public/js/unused.js deleted file mode 100644 index 4ff5b280..00000000 --- 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 -- cgit v1.2.3 From b6e68b2d36c15b7cd91f8820b766f929c01721ad Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 20:49:42 +0800 Subject: Fix saveHistoryToStorage not correctly fallback to cookie --- public/js/history.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'public/js') diff --git a/public/js/history.js b/public/js/history.js index 0840580d..c974612b 100644 --- a/public/js/history.js +++ b/public/js/history.js @@ -47,7 +47,7 @@ function saveHistoryToStorage(notehistory) { if (store.enabled) store.set('notehistory', JSON.stringify(notehistory)); else - saveHistoryToStorage(notehistory); + saveHistoryToCookie(notehistory); } function saveHistoryToCookie(notehistory) { -- cgit v1.2.3 From dc343978eb29da741b7f52137e042996ab78b63a Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 20:50:01 +0800 Subject: Fix get or set history on server ajax should not fallback to browser storage to avoid some internet edge cases --- public/js/history.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'public/js') diff --git a/public/js/history.js b/public/js/history.js index c974612b..f9ce2267 100644 --- a/public/js/history.js +++ b/public/js/history.js @@ -165,8 +165,8 @@ function writeHistoryToServer(view) { var newnotehistory = generateHistory(view, notehistory); saveHistoryToServer(newnotehistory); }) - .fail(function () { - writeHistoryToStorage(view); + .fail(function (xhr, status, error) { + console.error(xhr.responseText); }); } @@ -286,8 +286,8 @@ function getServerHistory(callback) { callback(data.history); } }) - .fail(function () { - getStorageHistory(callback); + .fail(function (xhr, status, error) { + console.error(xhr.responseText); }); } @@ -327,8 +327,8 @@ function parseServerToHistory(list, callback) { parseToHistory(list, data.history, callback); } }) - .fail(function () { - parseStorageToHistory(list, callback); + .fail(function (xhr, status, error) { + console.error(xhr.responseText); }); } -- cgit v1.2.3 From 36a1900ce3496f2d71ae4c41609dc52d24636be2 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 20:55:33 +0800 Subject: Update to make note history count in server-side when user logged --- public/js/history.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'public/js') diff --git a/public/js/history.js b/public/js/history.js index f9ce2267..9be68104 100644 --- a/public/js/history.js +++ b/public/js/history.js @@ -139,7 +139,8 @@ function removeHistory(id, notehistory) { function writeHistory(view) { checkIfAuth( function () { - writeHistoryToServer(view); + // no need to do this anymore, this will count from server-side + // writeHistoryToServer(view); }, function () { writeHistoryToStorage(view); @@ -365,4 +366,29 @@ function parseToHistory(list, notehistory, callback) { } } callback(list, notehistory); +} + +function postHistoryToServer(noteId, data, callback) { + $.post(serverurl + '/history/' + noteId, data) + .done(function (result) { + return callback(null, result); + }) + .fail(function (xhr, status, error) { + console.error(xhr.responseText); + return callback(error, null); + }); +} + +function deleteServerHistory(noteId, callback) { + $.ajax({ + url: serverurl + '/history' + (noteId ? '/' + noteId : ""), + type: 'DELETE' + }) + .done(function (result) { + return callback(null, result); + }) + .fail(function (xhr, status, error) { + console.error(xhr.responseText); + return callback(error, null); + }); } \ No newline at end of file -- cgit v1.2.3 From 7a46c9fc5cd72ed66adedb7c451bc6c96d6c60d6 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 20:57:17 +0800 Subject: Fix some incorrect redirects --- public/js/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index b5ebe954..b139ad2a 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -2201,20 +2201,20 @@ socket.on('info', function (data) { console.error(data); switch (data.code) { case 403: - location.href = "./403"; + location.href = serverurl + "/403"; break; case 404: - location.href = "./404"; + location.href = serverurl + "/404"; break; case 500: - location.href = "./500"; + location.href = serverurl + "/500"; break; } }); socket.on('error', function (data) { console.error(data); if (data.message && data.message.indexOf('AUTH failed') === 0) - location.href = "./403"; + location.href = serverurl + "/403"; }); var retryOnDisconnect = false; var retryTimer = null; -- cgit v1.2.3 From 68457ed3a26012e9e72e7ca95bfd7b9c101cdd8b Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 21:00:07 +0800 Subject: Update to make history delete and pin function call to new APIs --- public/js/cover.js | 86 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 28 deletions(-) (limited to 'public/js') diff --git a/public/js/cover.js b/public/js/cover.js index f3533826..429925a0 100644 --- a/public/js/cover.js +++ b/public/js/cover.js @@ -166,19 +166,32 @@ function parseHistoryCallback(list, notehistory) { pinned = false; item._values.pinned = false; } - getHistory(function (notehistory) { - for(var i = 0; i < notehistory.length; i++) { - if (notehistory[i].id == id) { - notehistory[i].pinned = pinned; - break; - } - } - saveHistory(notehistory); - if (pinned) - $this.addClass('active'); - else - $this.removeClass('active'); - }); + checkIfAuth(function () { + postHistoryToServer(id, { + pinned: pinned + }, function (err, result) { + if (!err) { + if (pinned) + $this.addClass('active'); + else + $this.removeClass('active'); + } + }); + }, function () { + getHistory(function (notehistory) { + for(var i = 0; i < notehistory.length; i++) { + if (notehistory[i].id == id) { + notehistory[i].pinned = pinned; + break; + } + } + saveHistory(notehistory); + if (pinned) + $this.addClass('active'); + else + $this.removeClass('active'); + }); + }) }); buildTagsFilter(filtertags); } @@ -199,23 +212,40 @@ var clearHistory = false; var deleteId = null; function deleteHistory() { - if (clearHistory) { - saveHistory([]); - historyList.clear(); - checkHistoryList(); - deleteId = null; - } else { - if (!deleteId) return; - getHistory(function (notehistory) { - var newnotehistory = removeHistory(deleteId, notehistory); - saveHistory(newnotehistory); - historyList.remove('id', deleteId); - checkHistoryList(); + checkIfAuth(function () { + deleteServerHistory(deleteId, function (err, result) { + if (!err) { + if (clearHistory) { + historyList.clear(); + checkHistoryList(); + } else { + historyList.remove('id', deleteId); + checkHistoryList(); + } + } + $('.delete-modal').modal('hide'); deleteId = null; + clearHistory = false; }); - } - $('.delete-modal').modal('hide'); - clearHistory = false; + }, function () { + if (clearHistory) { + saveHistory([]); + historyList.clear(); + checkHistoryList(); + deleteId = null; + } else { + if (!deleteId) return; + getHistory(function (notehistory) { + var newnotehistory = removeHistory(deleteId, notehistory); + saveHistory(newnotehistory); + historyList.remove('id', deleteId); + checkHistoryList(); + deleteId = null; + }); + } + $('.delete-modal').modal('hide'); + clearHistory = false; + }); } $(".ui-delete-modal-confirm").click(function () { -- cgit v1.2.3 From 12d5ed43a7376e0ca361160698f07066218d6ed2 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 21:04:24 +0800 Subject: Update to support delete note --- public/js/index.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index b139ad2a..63d7f3db 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -740,7 +740,8 @@ var ui = { editable: $(".ui-permission-editable"), locked: $(".ui-permission-locked"), private: $(".ui-permission-private") - } + }, + delete: $(".ui-delete-note") }, toc: { toc: $('.ui-toc'), @@ -2115,6 +2116,13 @@ ui.infobar.permission.locked.click(function () { ui.infobar.permission.private.click(function () { emitPermission("private"); }); +// delete note +ui.infobar.delete.click(function () { + $('.delete-modal').modal('show'); +}); +$('.ui-delete-modal-confirm').click(function () { + socket.emit('delete'); +}); function emitPermission(_permission) { if (_permission != permission) { @@ -2216,6 +2224,11 @@ socket.on('error', function (data) { if (data.message && data.message.indexOf('AUTH failed') === 0) location.href = serverurl + "/403"; }); +socket.on('delete', function () { + deleteServerHistory(noteid, function (err, data) { + if (!err) location.href = serverurl; + }); +}); var retryOnDisconnect = false; var retryTimer = null; socket.on('maintenance', function () { -- cgit v1.2.3 From e60ee6886d63bb4aa08165f63c13176cca5d6965 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 21:04:42 +0800 Subject: Cancel update history on page unload --- public/js/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index 63d7f3db..6b7efa68 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -930,7 +930,7 @@ $(window).resize(function () { }); //when page unload $(window).on('unload', function () { - updateHistoryInner(); + //updateHistoryInner(); }); $(window).on('error', function () { //setNeedRefresh(); -- cgit v1.2.3 From fb5d7e43592c1a14831067e28def9c4b9e2a97ca Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 21:14:28 +0800 Subject: Update npm and bower dependencies with related patch --- public/js/index.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index 6b7efa68..eb89d9f8 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -2262,8 +2262,6 @@ socket.on('connect', function (data) { personalInfo['id'] = socket.id; showStatus(statusType.connected); socket.emit('version'); - if (socket.id.indexOf('/') == -1) - socket.id = socket.nsp + '#' + socket.id; }); socket.on('version', function (data) { if (version != data.version) { -- cgit v1.2.3 From 795ea21191486a80437d7c535defc503962c5968 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Mon, 10 Oct 2016 21:15:29 +0800 Subject: Update CodeMirror to 5.19.0 and rename jade to pug --- public/js/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'public/js') diff --git a/public/js/index.js b/public/js/index.js index eb89d9f8..30d9e4e1 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -144,7 +144,7 @@ var cursorMenuThrottle = 50; var cursorActivityDebounce = 50; var cursorAnimatePeriod = 100; var supportContainers = ['success', 'info', 'warning', 'danger']; -var supportCodeModes = ['javascript', 'htmlmixed', 'htmlembedded', 'css', 'xml', 'clike', 'clojure', 'ruby', 'python', 'shell', 'php', 'sql', 'coffeescript', 'yaml', 'jade', 'lua', 'cmake', 'nginx', 'perl', 'sass', 'r', 'dockerfile', 'tiddlywiki', 'mediawiki']; +var supportCodeModes = ['javascript', 'htmlmixed', 'htmlembedded', 'css', 'xml', 'clike', 'clojure', 'ruby', 'python', 'shell', 'php', 'sql', 'coffeescript', 'yaml', 'pug', 'lua', 'cmake', 'nginx', 'perl', 'sass', 'r', 'dockerfile', 'tiddlywiki', 'mediawiki']; var supportCharts = ['sequence', 'flow', 'graphviz', 'mermaid']; var supportHeaders = [ { -- cgit v1.2.3 From 9a15cad42de2112c9c433b3199f39aca440f1581 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Tue, 11 Oct 2016 11:01:05 +0800 Subject: Mark as 0.4.5 --- public/js/common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'public/js') diff --git a/public/js/common.js b/public/js/common.js index a14e6fc9..047df8af 100644 --- a/public/js/common.js +++ b/public/js/common.js @@ -4,7 +4,7 @@ var serverurl = window.location.protocol + '//' + (domain ? domain : window.loca var noteid = urlpath ? window.location.pathname.slice(urlpath.length + 1, window.location.pathname.length).split('/')[1] : window.location.pathname.split('/')[1]; var noteurl = serverurl + '/' + noteid; -var version = '0.4.4'; +var version = '0.4.5'; var checkAuth = false; var profile = null; -- cgit v1.2.3 From c06b2f483898669b224321728321b7a3a8e9e37c Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Tue, 11 Oct 2016 16:46:50 +0800 Subject: Fix history time should save in UNIX timestamp to avoid time offset issue --- public/js/history.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'public/js') diff --git a/public/js/history.js b/public/js/history.js index 9be68104..324a9da2 100644 --- a/public/js/history.js +++ b/public/js/history.js @@ -96,8 +96,8 @@ function clearDuplicatedHistory(notehistory) { var id = notehistory[i].id.replace(/\=+$/, ''); var newId = newnotehistory[j].id.replace(/\=+$/, ''); if (id == newId || notehistory[i].id == newnotehistory[j].id || !notehistory[i].id || !newnotehistory[j].id) { - var time = moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a'); - var newTime = moment(newnotehistory[j].time, 'MMMM Do YYYY, h:mm:ss a'); + var time = (typeof notehistory[i].time === 'number' ? moment(notehistory[i].time) : moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a')); + var newTime = (typeof newnotehistory[i].time === 'number' ? moment(newnotehistory[i].time) : moment(newnotehistory[i].time, 'MMMM Do YYYY, h:mm:ss a')); if(time >= newTime) { newnotehistory[j] = notehistory[i]; } @@ -247,7 +247,7 @@ function renderHistory(view) { return { id: id, text: title, - time: moment().format('MMMM Do YYYY, h:mm:ss a'), + time: moment().valueOf(), tags: tags }; } @@ -358,9 +358,10 @@ function parseToHistory(list, notehistory, callback) { else if (notehistory && notehistory.length > 0) { for (var i = 0; i < notehistory.length; i++) { //parse time to timestamp and fromNow - notehistory[i].timestamp = moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a').valueOf(); - notehistory[i].fromNow = moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a').fromNow(); - notehistory[i].time = moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a').format('llll'); + var timestamp = (typeof notehistory[i].time === 'number' ? moment(notehistory[i].time) : moment(notehistory[i].time, 'MMMM Do YYYY, h:mm:ss a')); + notehistory[i].timestamp = timestamp.valueOf(); + notehistory[i].fromNow = timestamp.fromNow(); + notehistory[i].time = timestamp.format('llll'); if (notehistory[i].id && list.get('id', notehistory[i].id).length == 0) list.add(notehistory[i]); } -- cgit v1.2.3 From cd9f8fe36b707ff5a9f8f7be4d55145ddee97f3a Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Tue, 11 Oct 2016 16:48:42 +0800 Subject: Update to support pagination for history list --- public/js/cover.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'public/js') diff --git a/public/js/cover.js b/public/js/cover.js index 429925a0..25434ed9 100644 --- a/public/js/cover.js +++ b/public/js/cover.js @@ -18,7 +18,11 @@ var options = { \ \ \ - ' + ', + page: 18, + plugins: [ + ListPagination({}) + ] }; var historyList = new List('history', options); -- cgit v1.2.3