2012-07-10 22:18:44 +00:00
|
|
|
/*\
|
|
|
|
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
|
|
|
|
*/
|
2012-07-12 15:58:49 +00:00
|
|
|
var DownloadSaver = function(wiki) {
|
2012-07-10 22:18:44 +00:00
|
|
|
};
|
|
|
|
|
2012-07-12 12:13:48 +00:00
|
|
|
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();
|
2012-07-12 15:58:49 +00:00
|
|
|
return true;
|
2012-07-10 22:18:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Information about this saver
|
|
|
|
*/
|
|
|
|
DownloadSaver.prototype.info = {
|
|
|
|
name: "download",
|
|
|
|
priority: 0
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Static method that returns true if this saver is capable of working
|
|
|
|
*/
|
2012-07-13 12:03:38 +00:00
|
|
|
exports.canSave = function(wiki) {
|
2012-07-10 22:18:44 +00:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Create an instance of this saver
|
|
|
|
*/
|
2012-07-13 12:03:38 +00:00
|
|
|
exports.create = function(wiki) {
|
|
|
|
return new DownloadSaver(wiki);
|
2012-07-10 22:18:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
})();
|