From 67638b1d4c36e48b93f7044254842afbed4f10dd Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sat, 3 Apr 2021 09:29:00 +0100 Subject: [PATCH] Slight refactor --- src/components/Item.vue | 31 ++++++++++++++++++------------- src/views/Home.vue | 21 ++++++++++++--------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/components/Item.vue b/src/components/Item.vue index 1f06e795..77db4422 100644 --- a/src/components/Item.vue +++ b/src/components/Item.vue @@ -50,9 +50,7 @@ export default { }; }, methods: { - itemOpened() { - this.$emit('itemClicked'); - }, + /* Returns true if a string is in URL format. Used to identify tile icon source */ isUrl(str) { const pattern = new RegExp(/(http|https):\/\/(\w+:{0,1}\w*)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%!\-/]))?/); return pattern.test(str); @@ -91,18 +89,25 @@ export default { } return imgType; }, + /* Called when an item is opened, so that search field can be reset */ + itemOpened() { + this.$emit('itemClicked'); + }, + /** + * Detects overflowing text, shows ellipse, and allows is to marguee on hover + * The below code is horifically bad, it is embarassing that I wrote it... + */ + manageTitleEllipse() { + const tileElem = document.getElementById(`tile-${this.getId}`); + if (tileElem) { + const isOverflowing = tileElem.scrollHeight > tileElem.clientHeight + || tileElem.scrollWidth > tileElem.clientWidth; + if (isOverflowing) tileElem.className += ' is-overflowing'; + } // Note from present me to past me: WTF?! + }, }, mounted() { - // Detects overflowing text, and allows is to marguee on hover - // The below code is horifically bad, it is embarassing that I wrote it... - const tileElem = document.getElementById(`tile-${this.getId}`); - if (tileElem) { - const isOverflowing = tileElem.scrollHeight > tileElem.clientHeight - || tileElem.scrollWidth > tileElem.clientWidth; - if (isOverflowing) { - tileElem.className += ' is-overflowing'; - } - } // Note from present me to past me: WTF?! + this.manageTitleEllipse(); }, }; diff --git a/src/views/Home.vue b/src/views/Home.vue index 52ed8181..f4b20648 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -1,11 +1,14 @@