auto linkification (plus some refactorings to silent pycharm warnings)

This commit is contained in:
azivner 2017-08-21 21:31:23 -04:00
parent 5469b58cb7
commit 1aeb0eec59
4 changed files with 44 additions and 25 deletions

View file

@ -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) == "<img") {
if (curTag.substr(0, 4) === "<img") {
//console.log("Found img tag");
let dataImagePos = curTag.indexOf('data:image/');
if (dataImagePos != -1) {
if (dataImagePos !== -1) {
let imageType = curTag.substr(dataImagePos + 11, 3);
//console.log("image type: " + imageType);
@ -66,7 +66,7 @@ function html2notecase(contents, note) {
let endOfDataPos = dataStart.indexOf('"');
if (endOfDataPos != -1) {
if (endOfDataPos !== -1) {
//console.log("Found the end of image data");
let imageData = dataStart.substr(0, endOfDataPos);
@ -74,7 +74,7 @@ function html2notecase(contents, note) {
note.images.push({
note_id: note.detail.note_id,
note_offset: index,
is_png: imageType == "png",
is_png: imageType === "png",
image_data: imageData
});
@ -89,7 +89,7 @@ function html2notecase(contents, note) {
let match = /^<a[^>]+?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++;
}
}
}

View file

@ -124,7 +124,7 @@ function createNote(node, parentKey, target) {
newNoteCreated = true;
if (target == 'after') {
if (target === 'after') {
node.appendSibling(newNode).setActive(true);
}
else {

View file

@ -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',

View file

@ -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);
}