Move some of the util functions to util.js

This commit is contained in:
Dan Sosedoff
2017-09-16 14:03:42 -05:00
parent 81af2a9a27
commit 28b0840e69
3 changed files with 20 additions and 19 deletions

View File

@@ -1,3 +1,13 @@
if (!Array.prototype.forEach) {
// Simplified iterator for browsers without forEach support
Array.prototype.forEach = function(cb) {
if (typeof this.length != 'number') return;
if (typeof callback != 'function') return;
for (var i = 0; i < this.length; i++) cb(this[i]);
}
}
function copyToClipboard(text) {
const element = document.createElement("textarea");
element.style.display = "none;"
@@ -10,3 +20,9 @@ function copyToClipboard(text) {
document.execCommand("copy");
document.body.removeChild(element);
}
function guid() {
function s4() { return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1); }
return [s4(), s4(), "-", s4(), "-", s4(), "-", s4(), "-", s4(), s4(), s4()].join("");
}