1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-07 20:44:23 +00:00
TiddlyWiki5/core/modules/savers/download.js
Jeremy Ruston 5e11de719c Added HTTP upload saver
Now we can save changes to TiddlySpot
2012-07-13 13:03:38 +01:00

57 lines
1.1 KiB
JavaScript

/*\
title: $:/core/modules/savers/download.js
type: application/javascript
module-type: saver
Handles saving changes via HTML5's download APIs
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Select the appropriate saver module and set it up
*/
var DownloadSaver = function(wiki) {
};
DownloadSaver.prototype.save = function(text) {
// Set up the link
var link = document.createElement("a");
link.setAttribute("target","_blank");
link.setAttribute("href","data:text/html," + encodeURIComponent(text));
// Use the download attribute to download it if it is supported
if(link.download !== undefined) {
link.setAttribute("download","tiddlywiki.html");
}
link.click();
return true;
};
/*
Information about this saver
*/
DownloadSaver.prototype.info = {
name: "download",
priority: 0
};
/*
Static method that returns true if this saver is capable of working
*/
exports.canSave = function(wiki) {
return true;
};
/*
Create an instance of this saver
*/
exports.create = function(wiki) {
return new DownloadSaver(wiki);
};
})();