From 5077419b689dd54da8d20371a1f800e13333b708 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 13 May 2021 00:20:51 +0200 Subject: [PATCH] fewer js-functions --- .../static/script/inventree/inventree.js | 55 ++++++++----------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/InvenTree/InvenTree/static/script/inventree/inventree.js b/InvenTree/InvenTree/static/script/inventree/inventree.js index afc2a80755..4b43b342af 100644 --- a/InvenTree/InvenTree/static/script/inventree/inventree.js +++ b/InvenTree/InvenTree/static/script/inventree/inventree.js @@ -1,40 +1,31 @@ -function attachClipboard(selector) { +function attachClipboard(selector, containerselector, textElement) { + // set container + if (containerselector){ + containerselector = document.getElementById(containerselector); + } else { + containerselector = document.body; + } - var cis = new ClipboardJS(selector, { - text: function(trigger) { - var content = trigger.parentElement.parentElement.textContent; - - return content.trim(); + // set text-function + if (textElement){ + text = function() { + return document.getElementById(textElement).textContent; } + } else { + text = function() { + var content = trigger.parentElement.parentElement.textContent;return content.trim(); + } + } + + // create Clipboard + var cis = new ClipboardJS(selector, { + text: text, + container: containerselector }); console.log(cis); } -function attachmodalClipboard(selector) { - - new ClipboardJS(selector, { - text: function(trigger) { - var content = trigger.parentElement.parentElement.textContent; - return content.trim(); - }, - container: document.getElementById('modal-about') - }); -} - - -function AboutClipboard(selector) { - - new ClipboardJS(selector, { - text: function() { - console.log('about'); - return document.getElementById('about-copy-text').textContent; - }, - container: document.getElementById('modal-about') - }); -} - - function inventreeDocReady() { /* Run this function when the HTML document is loaded. * This will be called for every page that extends "base.html" @@ -88,8 +79,8 @@ function inventreeDocReady() { // Initialize clipboard-buttons attachClipboard('.clip-btn'); - attachmodalClipboard('.clip-btn'); - AboutClipboard('.clip-btn-version'); + attachClipboard('.clip-btn', 'modal-about'); // modals + attachClipboard('.clip-btn-version', 'modal-about', 'about-copy-text'); // version-text }