[refactor] improve link string handling

This commit is contained in:
zombieFox 2020-06-13 23:54:43 +01:00
parent 40a1303bb9
commit 61416e10b3
5 changed files with 59 additions and 24 deletions

View File

@ -14,7 +14,7 @@ var bookmarks = (function() {
visual: {
display: "icon",
letter: "AS",
image: null,
image: "",
icon: {
name: "dice-d20",
prefix: "fas",
@ -56,7 +56,7 @@ var bookmarks = (function() {
visual: {
display: "letter",
letter: "AZ",
image: null,
image: "",
icon: {
name: "amazon",
prefix: "fab",
@ -98,7 +98,7 @@ var bookmarks = (function() {
visual: {
display: "letter",
letter: "GM",
image: null,
image: "",
icon: {
name: "envelope",
prefix: "fas",
@ -140,7 +140,7 @@ var bookmarks = (function() {
visual: {
display: "icon",
letter: "R",
image: null,
image: "",
icon: {
name: "reddit-alien",
prefix: "fab",
@ -182,7 +182,7 @@ var bookmarks = (function() {
visual: {
display: "icon",
letter: "N",
image: null,
image: "",
icon: {
name: "film",
prefix: "fas",
@ -224,11 +224,11 @@ var bookmarks = (function() {
visual: {
display: "letter",
letter: "DR",
image: null,
image: "",
icon: {
name: null,
prefix: null,
label: null
name: "",
prefix: "",
label: ""
}
},
name: "Drive",
@ -275,7 +275,7 @@ var bookmarks = (function() {
visual: {
display: "icon",
letter: "DEV",
image: null,
image: "",
icon: {
name: "code",
prefix: "fas",
@ -317,7 +317,7 @@ var bookmarks = (function() {
visual: {
display: "icon",
letter: "GIT",
image: null,
image: "",
icon: {
name: "github",
prefix: "fab",

View File

@ -27,7 +27,7 @@ var layout = (function() {
if (helper.checkIfValidString(state.get.current().layout.title)) {
title.textContent = helper.trimString(state.get.current().layout.title);
} else {
title.textContent = "New tab";
title.textContent = "New Tab";
};
};

View File

@ -978,16 +978,39 @@ var link = (function() {
var linkDisplayImage = null;
if (stagedLink.link.visual.display == "letter" && helper.checkIfValidString(stagedLink.link.visual.letter)) {
linkDisplayLetter = helper.node("p:" + helper.trimString(stagedLink.link.visual.letter) + "|class:link-display-letter");
linkDisplayLetter = helper.makeNode({
tag: "p",
text: helper.trimString(stagedLink.link.visual.letter),
attr: [{
key: "class",
value: "link-display-letter"
}]
});
} else if (stagedLink.link.visual.display == "icon" && helper.checkIfValidString(stagedLink.link.visual.icon.prefix) && helper.checkIfValidString(stagedLink.link.visual.icon.name)) {
linkDisplayIcon = helper.node("div|class:link-display-icon " + stagedLink.link.visual.icon.prefix + " fa-" + stagedLink.link.visual.icon.name);
} else if (stagedLink.link.visual.display == "image" && helper.checkIfValidString(stagedLink.link.visual.image)) {
linkDisplayImage = helper.node("div|class:link-display-image,style:--link-display-image-url: url(" + helper.trimString(stagedLink.link.visual.image) + ")");
linkDisplayImage = helper.makeNode({
tag: "div",
attr: [{
key: "class",
value: "link-display-image"
}, {
key: "style",
value: "--link-display-image-url: url(" + helper.trimString(stagedLink.link.visual.image) + ")"
}]
});
};
var linkDisplayName;
if (helper.checkIfValidString(stagedLink.link.name)) {
linkDisplayName = helper.node("p:" + helper.trimString(stagedLink.link.name) + "|class:link-display-name");
linkDisplayName = helper.makeNode({
tag: "p",
text: helper.trimString(stagedLink.link.name),
attr: [{
key: "class",
value: "link-display-name"
}]
});
} else {
linkDisplayName = helper.node("p|class:link-display-name");
};
@ -2089,9 +2112,9 @@ var link = (function() {
stagedLink.link.url = this.value;
}, false);
displayIconFormGroupClear.addEventListener("click", function(event) {
stagedLink.link.visual.icon.name = null;
stagedLink.link.visual.icon.prefix = null;
stagedLink.link.visual.icon.label = null;
stagedLink.link.visual.icon.name = "";
stagedLink.link.visual.icon.prefix = "";
stagedLink.link.visual.icon.label = "";
var existingIcon = helper.e(".link-form-icon");
if (existingIcon) {
existingIcon.remove();
@ -2527,8 +2550,6 @@ var link = (function() {
stagedLink.link = JSON.parse(JSON.stringify(arrayItem));
stagedLink.position.origin.item = index;
stagedLink.position.destination.item = index;
stagedLink.position.group.new = null;
stagedLink.position.group.name.text = null;
if (state.get.current().search) {
if (stagedLink.link.searchMatch) {
group.querySelector(".group-body").appendChild(render.item.link());

View File

@ -107,13 +107,26 @@ var modal = (function() {
modalControls.appendChild(cancelButton);
modalControls.appendChild(actionButton);
if (options.heading != null) {
var modalHeading = helper.node("h1:" + options.heading + "|class:modal-heading,tabindex:1");
var modalHeading = helper.makeNode({
tag: "h1",
text: options.heading,
attr: [{
key: "class",
value: "modal-heading"
}, {
key: "tabindex",
value: 1
}]
});
modalBody.appendChild(modalHeading);
};
if (options.content) {
if (typeof options.content == "string") {
var container = helper.node("div|class:container");
var para = helper.node("p:" + options.content);
var para = helper.makeNode({
tag: "p",
text: options.content
});
container.appendChild(para);
modalBody.appendChild(container);
} else {

View File

@ -44,12 +44,13 @@ var search = (function() {
get: function() {
var searchInput = helper.e(".search-input");
var string = helper.trimString(searchInput.value).toLowerCase();
console.log(string);
if (state.get.current().search) {
bookmarks.get().forEach(function(arrayItem, index) {
arrayItem.items.forEach(function(arrayItem, index) {
arrayItem.searchMatch = false;
var matchUrl = helper.checkIfValidString(arrayItem.url) && (arrayItem.url.toLowerCase().includes(string));
var matchName = helper.checkIfValidString(arrayItem.name) && (helper.trimString(arrayItem.name).toLowerCase().includes(string));
var matchUrl = helper.checkIfValidString(arrayItem.url) && arrayItem.url.toLowerCase().includes(string);
var matchName = helper.checkIfValidString(arrayItem.name) && helper.trimString(arrayItem.name).toLowerCase().includes(string);
if (matchUrl || matchName) {
arrayItem.searchMatch = true;
};