This commit is contained in:
azivner 2017-08-29 22:25:58 -04:00
parent 0b5aeee0ce
commit e862ddae13
5 changed files with 23 additions and 47 deletions

View File

@ -48,7 +48,7 @@
<div style="clear: both; height: 0"></div> <div style="clear: both; height: 0"></div>
<div id="noteDetail" style="overflow: scroll; height: 100%;"> <div id="noteDetail" style="overflow: scroll; height: 100%;">
<p>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.</p> <p>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.</p>
<p>You can work with the tree using following keyboard shortcuts:</p> <p>You can work with the tree using following keyboard shortcuts:</p>

View File

@ -1,6 +1,4 @@
function html2notecase(contents, note) { function html2notecase(contents, note) {
//console.log("'" + contents + "'");
// remove any possible extra newlines which might be inserted - all relevant new lines should be only in <br> and <p> // remove any possible extra newlines which might be inserted - all relevant new lines should be only in <br> and <p>
contents = contents.replace(/(?:\r\n|\r|\n)/, ''); contents = contents.replace(/(?:\r\n|\r|\n)/, '');
@ -23,16 +21,16 @@ function html2notecase(contents, note) {
if (contents[index] === '<') { if (contents[index] === '<') {
let found = false; let found = false;
let endOfTag = curContent.indexOf('>'); const endOfTag = curContent.indexOf('>');
if (endOfTag === -1) { if (endOfTag === -1) {
console.log("Can't find the end of the tag"); 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) { for (tagId in tags) {
let tag = tags[tagId]; const tag = tags[tagId];
if (contents.substr(index, tag.length) === tag) { if (contents.substr(index, tag.length) === tag) {
found = true; found = true;
@ -67,9 +65,7 @@ function html2notecase(contents, note) {
let endOfDataPos = dataStart.indexOf('"'); let endOfDataPos = dataStart.indexOf('"');
if (endOfDataPos !== -1) { if (endOfDataPos !== -1) {
//console.log("Found the end of image data"); const imageData = dataStart.substr(0, endOfDataPos);
let imageData = dataStart.substr(0, endOfDataPos);
note.images.push({ note.images.push({
note_id: note.detail.note_id, note_id: note.detail.note_id,
@ -80,18 +76,16 @@ function html2notecase(contents, note) {
contents = contents.substr(0, index) + contents.substr(index + curTag.length); contents = contents.substr(0, index) + contents.substr(index + curTag.length);
//console.log("Parsed image: " + imageData.substr(0, 100));
found = true; found = true;
} }
} }
} }
let match = /^<a[^>]+?href="([^"]+?)"[^>]+?>([^<]+?)<\/a>/.exec(curContent); const linkMatch = /^<a[^>]+?href="([^"]+?)"[^>]+?>([^<]+?)<\/a>/.exec(curContent);
if (match !== null) { if (linkMatch !== null) {
const targetUrl = match[1]; const targetUrl = linkMatch[1];
const linkText = match[2]; const linkText = linkMatch[2];
const newLink = { const newLink = {
note_id: note.detail.note_id, note_id: note.detail.note_id,
@ -109,10 +103,8 @@ function html2notecase(contents, note) {
} }
note.links.push(newLink); 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; found = true;
} }
@ -125,9 +117,9 @@ function html2notecase(contents, note) {
let linkMatch = /^(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]/i.exec(curContent); let linkMatch = /^(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]/i.exec(curContent);
if (linkMatch !== null) { if (linkMatch !== null) {
let targetUrl = linkMatch[0]; const targetUrl = linkMatch[0];
let newLink = { const newLink = {
note_id: note.detail.note_id, note_id: note.detail.note_id,
note_offset: index, note_offset: index,
lnk_text: targetUrl lnk_text: targetUrl
@ -154,7 +146,5 @@ function html2notecase(contents, note) {
contents = contents.trim(); contents = contents.trim();
//console.log('"' + contents + '"');
note.detail.note_text = contents; note.detail.note_text = contents;
} }

View File

@ -1,4 +1,4 @@
let tags = { const tags = {
1: "<b>", 1: "<b>",
2: "</b>", 2: "</b>",
3: "<i>", 3: "<i>",
@ -85,19 +85,6 @@ $(document).ready(function() {
var globalNote; 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() { function createNewTopLevelNote() {
let rootNode = $("#tree").fancytree("getRootNode"); let rootNode = $("#tree").fancytree("getRootNode");

View File

@ -5,13 +5,12 @@ function notecase2html(note) {
note.links.forEach(el => el.type = 'link'); note.links.forEach(el => el.type = 'link');
note.images.forEach(el => el.type = 'image'); note.images.forEach(el => el.type = 'image');
let all = note.formatting.concat(note.links).concat(note.images); const allTags = note.formatting.concat(note.links).concat(note.images);
all.sort(function compare(a, b) { allTags.sort(function compare(a, b) {
return a.note_offset - b.note_offset; return a.note_offset - b.note_offset;
}); });
let offset = 0; let offset = 0;
let lastTag = null;
function inject(target, injected, position) { function inject(target, injected, position) {
offset += injected.length; offset += injected.length;
@ -19,7 +18,7 @@ function notecase2html(note) {
return noteText.substr(0, position) + injected + noteText.substr(position); return noteText.substr(0, position) + injected + noteText.substr(position);
} }
for (let el of all) { for (const el of allTags) {
if (el.type === 'formatting') { if (el.type === 'formatting') {
if (tags[el.fmt_tag]) { if (tags[el.fmt_tag]) {
noteText = inject(noteText, tags[el.fmt_tag], el.note_offset + offset); noteText = inject(noteText, tags[el.fmt_tag], el.note_offset + offset);
@ -35,7 +34,7 @@ function notecase2html(note) {
targetUrl = "app#" + el.target_note_id; targetUrl = "app#" + el.target_note_id;
} }
let linkHtml = '<a href="' + targetUrl + '">' + el.lnk_text + '</a>'; const linkHtml = '<a href="' + targetUrl + '">' + el.lnk_text + '</a>';
noteText = noteText.substr(0, el.note_offset + offset) + noteText.substr(el.note_offset + offset + el.lnk_text.length); 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; offset -= el.lnk_text.length;
} }
else if (el.type === 'image') { else if (el.type === 'image') {
let type = el.is_png ? "png" : "jpg"; const type = el.is_png ? "png" : "jpg";
let imgHtml = '<img alt="Embedded Image" src="data:image/' + type + ';base64,' + el.image_data + '" />'; const imgHtml = '<img alt="Embedded Image" src="data:image/' + type + ';base64,' + el.image_data + '" />';
noteText = inject(noteText, imgHtml, el.note_offset + offset); noteText = inject(noteText, imgHtml, el.note_offset + offset);
} }

View File

@ -114,7 +114,7 @@ $(function(){
} }
function copyTitle(notes) { function copyTitle(notes) {
for (let note of notes) { for (const note of notes) {
globalNoteNames[note.note_id] = note.note_title; globalNoteNames[note.note_id] = note.note_title;
note.title = note.note_title; note.title = note.note_title;
@ -185,7 +185,7 @@ $(function(){
}); });
$("input[name=search]").keyup(function (e) { $("input[name=search]").keyup(function (e) {
let match = $(this).val(); const match = $(this).val();
if (e && e.which === $.ui.keyCode.ESCAPE || $.trim(match) === "") { if (e && e.which === $.ui.keyCode.ESCAPE || $.trim(match) === "") {
$("button#btnResetSearch").click(); $("button#btnResetSearch").click();
@ -193,14 +193,14 @@ $("input[name=search]").keyup(function (e) {
} }
// Pass a string to perform case insensitive matching // Pass a string to perform case insensitive matching
let tree = $("#tree").fancytree("getTree"); const tree = $("#tree").fancytree("getTree");
tree.filterBranches(match); tree.filterBranches(match);
}).focus(); }).focus();
$("button#btnResetSearch").click(function () { $("button#btnResetSearch").click(function () {
$("input[name=search]").val(""); $("input[name=search]").val("");
let tree = $("#tree").fancytree("getTree"); const tree = $("#tree").fancytree("getTree");
tree.clearFilter(); tree.clearFilter();
}); });