- var link = document.createElement('a');
- if (respStatus === 200) {
- var response = JSON.parse(xhr.responseText);
- if (response.success) {
- link.textContent = response.files[0].url.replace(/.*?:\/\//g, '');
- link.href = response.files[0].url;
- url.appendChild(link);
- var copy = document.createElement('button');
- copy.className = 'upload-clipboard-btn';
- var glyph = document.createElement('img');
- glyph.src = 'img/glyphicons-512-copy.png';
- copy.appendChild(glyph);
- url.appendChild(copy);
- copy.addEventListener("click", function(event) {
- /* Why create an element? The text needs to be on screen to be
- selected and thus copied. The only text we have on-screen is the link
- without the http[s]:// part. So, this creates an element with the
- full link for a moment and then deletes it.
-
- See the "Complex Example: Copy to clipboard without displaying
- input" section at: https://stackoverflow.com/a/30810322 */
- var element = document.createElement('a');
- element.textContent = response.files[0].url;
- link.appendChild(element);
- var range = document.createRange();
- range.selectNode(element);
- window.getSelection().removeAllRanges();
- window.getSelection().addRange(range);
- document.execCommand("copy");
- link.removeChild(element);
- });
- } else {
- bar.innerHTML = 'Error: ' + response.description;
- }
- } else if (respStatus === 413) {
- link.textContent = 'File too big!';
- url.appendChild(link);
- } else if (respStatus === 415) {
- link.textContent = 'Filetype not allowed!';
- url.appendChild(link);
- } else {
- link.textContent = 'Server error!';
- url.appendChild(link);
+ var link = document.createElement('a');
+ if (respStatus === 200) {
+ var response = JSON.parse(xhr.responseText);
+ if (response.success) {
+ link.textContent = response.files[0].url.replace(/.*?:\/\//g, '');
+ link.href = response.files[0].url;
+ url.appendChild(link);
+ var copy = document.createElement('button');
+ copy.className = 'upload-clipboard-btn';
+ var glyph = document.createElement('img');
+ glyph.src = 'img/glyphicons-512-copy.png';
+ copy.appendChild(glyph);
+ url.appendChild(copy);
+ copy.addEventListener("click", function (event) {
+ /* Why create an element? The text needs to be on screen to be
+ selected and thus copied. The only text we have on-screen is the link
+ without the http[s]:// part. So, this creates an element with the
+ full link for a moment and then deletes it.
+
+ See the "Complex Example: Copy to clipboard without displaying
+ input" section at: https://stackoverflow.com/a/30810322 */
+ var element = document.createElement('a');
+ element.textContent = response.files[0].url;
+ link.appendChild(element);
+ var range = document.createRange();
+ range.selectNode(element);
+ window.getSelection().removeAllRanges();
+ window.getSelection().addRange(range);
+ document.execCommand("copy");
+ link.removeChild(element);
+ });
+ } else {
+ bar.innerHTML = 'Error: ' + response.description;
+ }
+ } else if (respStatus === 413) {
+ link.textContent = 'File too big!';
+ url.appendChild(link);
+ } else {
+ var response = JSON.parse(xhr.responseText);
+ link.textContent = response.description;
+ url.appendChild(link);
+ }