Revize 6c9cb54a
Přidáno uživatelem Jan Pašek před asi 4 roky(ů)
static/js/utilities.js | ||
---|---|---|
1 |
/** |
|
2 |
* Generate a file to be downloaded by the browser |
|
3 |
* @param filename name of the file to be downloaded |
|
4 |
* @param text content of the downloaded file |
|
5 |
*/ |
|
1 | 6 |
function download(filename, text) { |
2 |
var element = document.createElement('a'); |
|
3 |
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); |
|
4 |
element.setAttribute('download', filename); |
|
7 |
// first a hidden <a> element is created and download content is assigned |
|
8 |
var element = document.createElement('a'); |
|
9 |
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); |
|
10 |
element.setAttribute('download', filename); |
|
5 | 11 |
|
6 |
element.style.display = 'none'; |
|
7 |
document.body.appendChild(element); |
|
12 |
element.style.display = 'none';
|
|
13 |
document.body.appendChild(element);
|
|
8 | 14 |
|
9 |
element.click(); |
|
15 |
// generate artificial click event to download the file |
|
16 |
element.click(); |
|
10 | 17 |
|
11 |
document.body.removeChild(element); |
|
18 |
// remove the download link from the webpage |
|
19 |
document.body.removeChild(element); |
|
12 | 20 |
} |
13 | 21 |
|
22 |
// Adds toDateInputValue() method to Date object |
|
23 |
// toDateInputValue() produces date in YYYY-MM-DD format |
|
14 | 24 |
Date.prototype.toDateInputValue = (function() { |
15 | 25 |
var local = new Date(this); |
16 | 26 |
local.setMinutes(this.getMinutes() - this.getTimezoneOffset()); |
Také k dispozici: Unified diff
Re #8475 - Added code comments