From 61416e10b360add8201a7089e4965b0abd65c5f2 Mon Sep 17 00:00:00 2001 From: zombieFox Date: Sat, 13 Jun 2020 23:54:43 +0100 Subject: [PATCH] [refactor] improve link string handling --- src/js/bookmarks.js | 22 +++++++++++----------- src/js/layout.js | 2 +- src/js/link.js | 37 +++++++++++++++++++++++++++++-------- src/js/modal.js | 17 +++++++++++++++-- src/js/search.js | 5 +++-- 5 files changed, 59 insertions(+), 24 deletions(-) diff --git a/src/js/bookmarks.js b/src/js/bookmarks.js index 6c5873b9..adc35653 100644 --- a/src/js/bookmarks.js +++ b/src/js/bookmarks.js @@ -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", diff --git a/src/js/layout.js b/src/js/layout.js index 5581c739..94beb35d 100644 --- a/src/js/layout.js +++ b/src/js/layout.js @@ -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"; }; }; diff --git a/src/js/link.js b/src/js/link.js index 45fe7f72..05080353 100644 --- a/src/js/link.js +++ b/src/js/link.js @@ -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()); diff --git a/src/js/modal.js b/src/js/modal.js index 42cdaec5..cc999025 100644 --- a/src/js/modal.js +++ b/src/js/modal.js @@ -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 { diff --git a/src/js/search.js b/src/js/search.js index a5e1b03c..ef56fd53 100644 --- a/src/js/search.js +++ b/src/js/search.js @@ -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; };