From 5b9c1946efb03af3fb517fa7e85d1876d7ea2e43 Mon Sep 17 00:00:00 2001 From: bbaer <bbaer@math.uzh.ch> Date: Thu, 22 Mar 2018 17:30:38 +0100 Subject: [PATCH] added a JSON request for a text variable --- javascript/src/Clipboard.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/javascript/src/Clipboard.js b/javascript/src/Clipboard.js index 7e5d7ca33..1c48a9cfe 100644 --- a/javascript/src/Clipboard.js +++ b/javascript/src/Clipboard.js @@ -11,7 +11,24 @@ var QfqNS = QfqNs || {}; (function (n) { n.Clipboard = function (data) { - this.copyTextToClipboardAsync(data.text); + if(data.text) { + this.copyTextToClipboardAsync(data.text); + return; + } + if(data.url) { + this.getDataFromUri(data.uri); + } + }; + + n.Clipboard.prototype.getDataFromUri = function(uri) { + var that = this; + $.getJSON(uri, function(data) { + if (data.text) { + that.copyTextToClipboardAsync(data.text); + } else { + that.buildError("JSON Response didn't include a variable called 'text'"); + } + }); }; n.Clipboard.prototype.copyTextToClipboard = function(text) { @@ -39,7 +56,7 @@ var QfqNS = QfqNs || {}; */ n.Clipboard.prototype.copyTextToClipboardAsync = function(text) { if (!navigator.clipboard) { - this.fallbackCopyTextToClipboard(text); + this.copyTextToClipboard(text); return; } -- GitLab