diff --git a/static/js/html2notecase.js b/static/js/html2notecase.js index b20775d37..19f0a1e1b 100644 --- a/static/js/html2notecase.js +++ b/static/js/html2notecase.js @@ -12,13 +12,13 @@ function html2notecase(contents, note) { note.images = []; while (index < contents.length) { - if (contents[index] == '<') { - let found = false; + let curContent = contents.substr(index); - let curContent = contents.substr(index); + if (contents[index] === '<') { + let found = false; let endOfTag = curContent.indexOf('>'); - if (endOfTag == -1) { + if (endOfTag === -1) { console.log("Can't find the end of the tag"); } @@ -29,7 +29,7 @@ function html2notecase(contents, note) { for (tagId in tags) { let tag = tags[tagId]; - if (contents.substr(index, tag.length) == tag) { + if (contents.substr(index, tag.length) === tag) { found = true; // if (tagMap.get(index) == undefined) { // tagMap.get(index) = []; @@ -52,12 +52,12 @@ function html2notecase(contents, note) { } } - if (curTag.substr(0, 4) == "]+?href="([^"]+?)"[^>]+?>([^<]+?)<\/a>/.exec(curContent); - if (match != null) { + if (match !== null) { note.links.push({ note_id: note.detail.note_id, note_offset: index, @@ -120,7 +120,22 @@ function html2notecase(contents, note) { } } else { - index++; + let linkMatch = /^((https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/i.exec(curContent); + + if (linkMatch !== null) { + note.links.push({ + note_id: note.detail.note_id, + note_offset: index, + target_url: linkMatch[1], + lnk_text: linkMatch[1] + }); + + found = true; + index += linkMatch[1].length; + } + else { + index++; + } } } diff --git a/static/js/note.js b/static/js/note.js index 3685af85a..8202f18c3 100644 --- a/static/js/note.js +++ b/static/js/note.js @@ -124,7 +124,7 @@ function createNote(node, parentKey, target) { newNoteCreated = true; - if (target == 'after') { + if (target === 'after') { node.appendSibling(newNode).setActive(true); } else { diff --git a/static/js/tree.js b/static/js/tree.js index 5459a4d52..c42b2cb00 100644 --- a/static/js/tree.js +++ b/static/js/tree.js @@ -50,7 +50,7 @@ $(function(){ hotkeys: { keydown: { "insert": function(node) { - let parentKey = (node.getParent() == null || node.getParent().key == "root_1") ? "root" : node.getParent().key; + let parentKey = (node.getParent() === null || node.getParent().key === "root_1") ? "root" : node.getParent().key; createNote(node, parentKey, 'after'); }, @@ -63,7 +63,7 @@ $(function(){ url: baseUrl + 'notes/' + node.key, type: 'DELETE', success: function(result) { - if (node.getParent() != null && node.getParent().getChildren().length <= 1) { + if (node.getParent() !== null && node.getParent().getChildren().length <= 1) { node.getParent().folder = false; node.getParent().renderTitle(); } @@ -74,7 +74,7 @@ $(function(){ } }, "shift+up": function(node) { - if (node.getPrevSibling() != null) { + if (node.getPrevSibling() !== null) { $.ajax({ url: baseUrl + 'notes/' + node.key + '/moveBefore/' + node.getPrevSibling().key, type: 'PUT', @@ -86,7 +86,7 @@ $(function(){ } }, "shift+down": function(node) { - if (node.getNextSibling() != null) { + if (node.getNextSibling() !== null) { $.ajax({ url: baseUrl + 'notes/' + node.key + '/moveAfter/' + node.getNextSibling().key, type: 'PUT', @@ -98,13 +98,13 @@ $(function(){ } }, "shift+left": function(node) { - if (node.getParent() != null) { + if (node.getParent() !== null) { $.ajax({ url: baseUrl + 'notes/' + node.key + '/moveAfter/' + node.getParent().key, type: 'PUT', contentType: "application/json", success: function(result) { - if (node.getParent() != null && node.getParent().getChildren().length <= 1) { + if (node.getParent() !== null && node.getParent().getChildren().length <= 1) { node.getParent().folder = false; node.getParent().renderTitle(); } @@ -117,7 +117,7 @@ $(function(){ "shift+right": function(node) { let prevSibling = node.getPrevSibling(); - if (prevSibling != null) { + if (prevSibling !== null) { $.ajax({ url: baseUrl + 'notes/' + node.key + '/moveTo/' + prevSibling.key, type: 'PUT', diff --git a/static/js/utils.js b/static/js/utils.js index d9108d2be..516902d0f 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -1,11 +1,15 @@ function message(str) { - $("#top-message").fadeIn(1500); - $("#top-message").html(str); - $("#top-message").fadeOut(1500); + const top = $("#top-message"); + + top.fadeIn(1500); + top.html(str); + top.fadeOut(1500); } function error(str) { - $("#error-message").show(); - $("#error-message").html(str); - $("#error-message").fadeOut(10000); + const error = $("#error-message"); + + error.show(); + error.html(str); + error.fadeOut(10000); } \ No newline at end of file