From 16739684bb7ca55d71c22cbd103ca8c058c33ecc Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Fri, 15 Mar 2024 11:15:53 +0100 Subject: things: provide a simple way to follow links MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- app/javascript/controllers/thing_controller.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 app/javascript/controllers/thing_controller.js (limited to 'app/javascript') diff --git a/app/javascript/controllers/thing_controller.js b/app/javascript/controllers/thing_controller.js new file mode 100644 index 0000000..1518216 --- /dev/null +++ b/app/javascript/controllers/thing_controller.js @@ -0,0 +1,17 @@ +import { Controller } from "@hotwired/stimulus" + +// Gathers all the methods that are relevant when manipulating things. +export default class extends Controller { + // Update the external link depending on the changed value. The link will also + // be hidden/shown depending if the current URL is empty or not. + updateLink() { + let cur = document.getElementById("thing_url").value.trim(); + + if (cur === "") { + document.getElementById("thing-external-url-id").classList.add('hidden'); + } else { + document.getElementById("thing-external-url-id").classList.remove('hidden'); + document.getElementById("thing-external-url-id").href = cur; + } + } +} -- cgit v1.2.3