From e862ddae137003d3603e5e77b4508864a754a82e Mon Sep 17 00:00:00 2001 From: azivner Date: Tue, 29 Aug 2017 22:25:58 -0400 Subject: [PATCH] cleanup --- src/templates/app.html | 2 +- static/js/html2notecase.js | 32 +++++++++++--------------------- static/js/note.js | 15 +-------------- static/js/notecase2html.js | 13 ++++++------- static/js/tree.js | 8 ++++---- 5 files changed, 23 insertions(+), 47 deletions(-) diff --git a/src/templates/app.html b/src/templates/app.html index 9c8f55d3b..0d7616732 100644 --- a/src/templates/app.html +++ b/src/templates/app.html @@ -48,7 +48,7 @@
-

This prototype version supports basic editing, including some formatting (bold, italic, strike-through, underscore), images (just paste it into editor) and links. To edit the note, just click on title or content and you can directly modify it. Changes are saved immediatelly.

+

This prototype version supports basic editing, including some formatting (bold, italic, strike-through, underscore), images (just paste it into editor) and links. To edit the note, just click on title or content and you can directly modify it. Changes are saved immediately.

You can work with the tree using following keyboard shortcuts:

diff --git a/static/js/html2notecase.js b/static/js/html2notecase.js index 4843922e1..3c161fce2 100644 --- a/static/js/html2notecase.js +++ b/static/js/html2notecase.js @@ -1,6 +1,4 @@ function html2notecase(contents, note) { - //console.log("'" + contents + "'"); - // remove any possible extra newlines which might be inserted - all relevant new lines should be only in
and

contents = contents.replace(/(?:\r\n|\r|\n)/, ''); @@ -23,16 +21,16 @@ function html2notecase(contents, note) { if (contents[index] === '<') { let found = false; - let endOfTag = curContent.indexOf('>'); + const endOfTag = curContent.indexOf('>'); if (endOfTag === -1) { console.log("Can't find the end of the tag"); } - let curTag = curContent.substr(0, endOfTag + 1); + const curTag = curContent.substr(0, endOfTag + 1); for (tagId in tags) { - let tag = tags[tagId]; + const tag = tags[tagId]; if (contents.substr(index, tag.length) === tag) { found = true; @@ -67,9 +65,7 @@ function html2notecase(contents, note) { let endOfDataPos = dataStart.indexOf('"'); if (endOfDataPos !== -1) { - //console.log("Found the end of image data"); - - let imageData = dataStart.substr(0, endOfDataPos); + const imageData = dataStart.substr(0, endOfDataPos); note.images.push({ note_id: note.detail.note_id, @@ -80,18 +76,16 @@ function html2notecase(contents, note) { contents = contents.substr(0, index) + contents.substr(index + curTag.length); - //console.log("Parsed image: " + imageData.substr(0, 100)); - found = true; } } } - let match = /^]+?href="([^"]+?)"[^>]+?>([^<]+?)<\/a>/.exec(curContent); + const linkMatch = /^]+?href="([^"]+?)"[^>]+?>([^<]+?)<\/a>/.exec(curContent); - if (match !== null) { - const targetUrl = match[1]; - const linkText = match[2]; + if (linkMatch !== null) { + const targetUrl = linkMatch[1]; + const linkText = linkMatch[2]; const newLink = { note_id: note.detail.note_id, @@ -109,10 +103,8 @@ function html2notecase(contents, note) { } note.links.push(newLink); - - //console.log("Found link with text: " + match[2] + ", targetting: " + match[1]); - contents = contents.substr(0, index) + linkText + contents.substr(index + match[0].length); + contents = contents.substr(0, index) + linkText + contents.substr(index + linkMatch[0].length); found = true; } @@ -125,9 +117,9 @@ function html2notecase(contents, note) { let linkMatch = /^(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]/i.exec(curContent); if (linkMatch !== null) { - let targetUrl = linkMatch[0]; + const targetUrl = linkMatch[0]; - let newLink = { + const newLink = { note_id: note.detail.note_id, note_offset: index, lnk_text: targetUrl @@ -154,7 +146,5 @@ function html2notecase(contents, note) { contents = contents.trim(); - //console.log('"' + contents + '"'); - note.detail.note_text = contents; } \ No newline at end of file diff --git a/static/js/note.js b/static/js/note.js index a1c32f8cc..0db981077 100644 --- a/static/js/note.js +++ b/static/js/note.js @@ -1,4 +1,4 @@ -let tags = { +const tags = { 1: "", 2: "", 3: "", @@ -85,19 +85,6 @@ $(document).ready(function() { var globalNote; -function setParent(noteId, newParentKey, successCallback) { - let newNoteName = "new note"; - - $.ajax({ - url: baseUrl + 'notes/' + nodeId + '/setParent/' + newParentKey, - type: 'PUT', - contentType: "application/json", - success: function(result) { - successCallback(); - } - }); -} - function createNewTopLevelNote() { let rootNode = $("#tree").fancytree("getRootNode"); diff --git a/static/js/notecase2html.js b/static/js/notecase2html.js index fcd3c2020..d9cc07ce8 100644 --- a/static/js/notecase2html.js +++ b/static/js/notecase2html.js @@ -5,13 +5,12 @@ function notecase2html(note) { note.links.forEach(el => el.type = 'link'); note.images.forEach(el => el.type = 'image'); - let all = note.formatting.concat(note.links).concat(note.images); - all.sort(function compare(a, b) { + const allTags = note.formatting.concat(note.links).concat(note.images); + allTags.sort(function compare(a, b) { return a.note_offset - b.note_offset; }); let offset = 0; - let lastTag = null; function inject(target, injected, position) { offset += injected.length; @@ -19,7 +18,7 @@ function notecase2html(note) { return noteText.substr(0, position) + injected + noteText.substr(position); } - for (let el of all) { + for (const el of allTags) { if (el.type === 'formatting') { if (tags[el.fmt_tag]) { noteText = inject(noteText, tags[el.fmt_tag], el.note_offset + offset); @@ -35,7 +34,7 @@ function notecase2html(note) { targetUrl = "app#" + el.target_note_id; } - let linkHtml = '' + el.lnk_text + ''; + const linkHtml = '' + el.lnk_text + ''; noteText = noteText.substr(0, el.note_offset + offset) + noteText.substr(el.note_offset + offset + el.lnk_text.length); @@ -44,9 +43,9 @@ function notecase2html(note) { offset -= el.lnk_text.length; } else if (el.type === 'image') { - let type = el.is_png ? "png" : "jpg"; + const type = el.is_png ? "png" : "jpg"; - let imgHtml = 'Embedded Image'; + const imgHtml = 'Embedded Image'; noteText = inject(noteText, imgHtml, el.note_offset + offset); } diff --git a/static/js/tree.js b/static/js/tree.js index 3da823f3b..0e9e08def 100644 --- a/static/js/tree.js +++ b/static/js/tree.js @@ -114,7 +114,7 @@ $(function(){ } function copyTitle(notes) { - for (let note of notes) { + for (const note of notes) { globalNoteNames[note.note_id] = note.note_title; note.title = note.note_title; @@ -185,7 +185,7 @@ $(function(){ }); $("input[name=search]").keyup(function (e) { - let match = $(this).val(); + const match = $(this).val(); if (e && e.which === $.ui.keyCode.ESCAPE || $.trim(match) === "") { $("button#btnResetSearch").click(); @@ -193,14 +193,14 @@ $("input[name=search]").keyup(function (e) { } // Pass a string to perform case insensitive matching - let tree = $("#tree").fancytree("getTree"); + const tree = $("#tree").fancytree("getTree"); tree.filterBranches(match); }).focus(); $("button#btnResetSearch").click(function () { $("input[name=search]").val(""); - let tree = $("#tree").fancytree("getTree"); + const tree = $("#tree").fancytree("getTree"); tree.clearFilter(); });