From 413e03f10099d7c341bd76337b6892e0893ae445 Mon Sep 17 00:00:00 2001
From: weru <fromweru@gmail.com>
Date: Sun, 27 Dec 2020 16:56:34 +0000
Subject: [PATCH] add helpers
---
assets/js/functions.js | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 44 insertions(+), 0 deletions(-)
diff --git a/assets/js/functions.js b/assets/js/functions.js
index 33a15e9..d5bba50 100644
--- a/assets/js/functions.js
+++ b/assets/js/functions.js
@@ -151,4 +151,48 @@
link.href = href;
});
}
+}
+
+function parseBoolean(string) {
+ let bool;
+ string = string.trim().toLowerCase();
+ switch (string) {
+ case 'true':
+ return true;
+ case 'false':
+ return false;
+ default:
+ return undefined;
+ }
+};
+
+function loadSvg(file, parent, path = 'icons/') {
+ const link = `${parentURL}${path}${file}.svg`;
+ fetch(link)
+ .then((response) => {
+ return response.text();
+ })
+ .then((data) => {
+ parent.innerHTML = data;
+ });
+}
+
+function copyToClipboard(str) {
+ let copy, selection, selected;
+ copy = createEl('textarea');
+ copy.value = str;
+ copy.setAttribute('readonly', '');
+ copy.style.position = 'absolute';
+ copy.style.left = '-9999px';
+ selection = document.getSelection();
+ doc.appendChild(copy);
+ // check if there is any selected content
+ selected = selection.rangeCount > 0 ? selection.getRangeAt(0) : false;
+ copy.select();
+ document.execCommand('copy');
+ doc.removeChild(copy);
+ if (selected) { // if a selection existed before copying
+ selection.removeAllRanges(); // unselect existing selection
+ selection.addRange(selected); // restore the original selection
+ }
}
\ No newline at end of file
--
Gitblit v1.10.0