From 6337432f0f19314c0698f4b3b89c060d8c41148e Mon Sep 17 00:00:00 2001 From: donmor Date: Fri, 27 Sep 2019 08:25:18 +0800 Subject: [PATCH 1/9] Create tiddloid.js --- core/modules/savers/tiddloid.js | 46 +++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 core/modules/savers/tiddloid.js diff --git a/core/modules/savers/tiddloid.js b/core/modules/savers/tiddloid.js new file mode 100644 index 00000000000..47bd8987b8d --- /dev/null +++ b/core/modules/savers/tiddloid.js @@ -0,0 +1,46 @@ +/*\ +title: $:/core/modules/savers/tiddloid.js +type: application/javascript +module-type: saver +Handles saving changes via the Tiddloid Android app +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false, netscape: false, Components: false */ +"use strict"; + +var Tiddloid = function(wiki) { +}; + +Tiddloid.prototype.save = function(text,method,callback) { + if (method === "download") window.twi.saveDownload(text); + else window.twi.saveWiki(text); + callback(null); + return true; +}; + +/* +Information about this saver +*/ +Tiddloid.prototype.info = { + name: "tiddloid", + priority: 1800, + capabilities: ["save", "autosave", "download"] +}; + +/* +Static method that returns true if this saver is capable of working +*/ +exports.canSave = function(wiki) { + return !!window.twi && !!window.twi.saveWiki; +}; + +/* +Create an instance of this saver +*/ +exports.create = function(wiki) { + return new Tiddloid(wiki); +}; + +})(); From e68e1163784ca32643fb4054d924b122ba639e58 Mon Sep 17 00:00:00 2001 From: donmor Date: Sat, 28 Sep 2019 01:06:03 +0800 Subject: [PATCH 2/9] Update andtidwiki.js --- core/modules/savers/andtidwiki.js | 42 ++++++++++++++++++------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/core/modules/savers/andtidwiki.js b/core/modules/savers/andtidwiki.js index 33e776977b3..edda3bdbbf9 100644 --- a/core/modules/savers/andtidwiki.js +++ b/core/modules/savers/andtidwiki.js @@ -16,23 +16,31 @@ var AndTidWiki = function(wiki) { }; AndTidWiki.prototype.save = function(text,method,callback) { - // Get the pathname of this document - var pathname = decodeURIComponent(document.location.toString().split("#")[0]); - // Strip the file:// - if(pathname.indexOf("file://") === 0) { - pathname = pathname.substr(7); + if (method === "download") { + // Support download + window.twi.saveDownload(text); + } else if (window.twi.saveWiki) { + // Direct save in Tiddloid + window.twi.saveWiki(text); + } else { + // Get the pathname of this document + var pathname = decodeURIComponent(document.location.toString().split("#")[0]); + // Strip the file:// + if(pathname.indexOf("file://") === 0) { + pathname = pathname.substr(7); + } + // Strip any query or location part + var p = pathname.indexOf("?"); + if(p !== -1) { + pathname = pathname.substr(0,p); + } + p = pathname.indexOf("#"); + if(p !== -1) { + pathname = pathname.substr(0,p); + } + // Save the file + window.twi.saveFile(pathname,text); } - // Strip any query or location part - var p = pathname.indexOf("?"); - if(p !== -1) { - pathname = pathname.substr(0,p); - } - p = pathname.indexOf("#"); - if(p !== -1) { - pathname = pathname.substr(0,p); - } - // Save the file - window.twi.saveFile(pathname,text); // Call the callback callback(null); return true; @@ -44,7 +52,7 @@ Information about this saver AndTidWiki.prototype.info = { name: "andtidwiki", priority: 1600, - capabilities: ["save", "autosave"] + capabilities: ["save", "autosave", "download"] }; /* From d92484796dcddd43aa0668667dc63ba5da9d8d95 Mon Sep 17 00:00:00 2001 From: donmor Date: Sat, 28 Sep 2019 01:07:10 +0800 Subject: [PATCH 3/9] Delete tiddloid.js --- core/modules/savers/tiddloid.js | 46 --------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 core/modules/savers/tiddloid.js diff --git a/core/modules/savers/tiddloid.js b/core/modules/savers/tiddloid.js deleted file mode 100644 index 47bd8987b8d..00000000000 --- a/core/modules/savers/tiddloid.js +++ /dev/null @@ -1,46 +0,0 @@ -/*\ -title: $:/core/modules/savers/tiddloid.js -type: application/javascript -module-type: saver -Handles saving changes via the Tiddloid Android app -\*/ -(function(){ - -/*jslint node: true, browser: true */ -/*global $tw: false, netscape: false, Components: false */ -"use strict"; - -var Tiddloid = function(wiki) { -}; - -Tiddloid.prototype.save = function(text,method,callback) { - if (method === "download") window.twi.saveDownload(text); - else window.twi.saveWiki(text); - callback(null); - return true; -}; - -/* -Information about this saver -*/ -Tiddloid.prototype.info = { - name: "tiddloid", - priority: 1800, - capabilities: ["save", "autosave", "download"] -}; - -/* -Static method that returns true if this saver is capable of working -*/ -exports.canSave = function(wiki) { - return !!window.twi && !!window.twi.saveWiki; -}; - -/* -Create an instance of this saver -*/ -exports.create = function(wiki) { - return new Tiddloid(wiki); -}; - -})(); From 0b2f5cb9f7218e37c912e9ebe22954c55271725b Mon Sep 17 00:00:00 2001 From: donmor Date: Sat, 28 Sep 2019 07:59:25 +0800 Subject: [PATCH 4/9] Update andtidwiki.js --- core/modules/savers/andtidwiki.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/modules/savers/andtidwiki.js b/core/modules/savers/andtidwiki.js index edda3bdbbf9..f429a6244c1 100644 --- a/core/modules/savers/andtidwiki.js +++ b/core/modules/savers/andtidwiki.js @@ -16,7 +16,7 @@ var AndTidWiki = function(wiki) { }; AndTidWiki.prototype.save = function(text,method,callback) { - if (method === "download") { + if (method === "download" && window.twi.saveDownload) { // Support download window.twi.saveDownload(text); } else if (window.twi.saveWiki) { From 12aa3b0f3fce24851a6ae3a908ac902acbe4bae7 Mon Sep 17 00:00:00 2001 From: donmor Date: Sun, 13 Oct 2019 20:59:54 +0800 Subject: [PATCH 5/9] Update andtidwiki.js --- core/modules/savers/andtidwiki.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/modules/savers/andtidwiki.js b/core/modules/savers/andtidwiki.js index f429a6244c1..bf23dddd8a2 100644 --- a/core/modules/savers/andtidwiki.js +++ b/core/modules/savers/andtidwiki.js @@ -16,9 +16,11 @@ var AndTidWiki = function(wiki) { }; AndTidWiki.prototype.save = function(text,method,callback) { - if (method === "download" && window.twi.saveDownload) { + if (method === "download") { // Support download - window.twi.saveDownload(text); + if (window.twi.saveDownload) { + window.twi.saveDownload(text); + } } else if (window.twi.saveWiki) { // Direct save in Tiddloid window.twi.saveWiki(text); From f6504ae3f98598cbf6489a90fdc706929e767289 Mon Sep 17 00:00:00 2001 From: donmor Date: Sun, 20 Oct 2019 01:21:45 +0800 Subject: [PATCH 6/9] Update andtidwiki.js --- core/modules/savers/andtidwiki.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/core/modules/savers/andtidwiki.js b/core/modules/savers/andtidwiki.js index bf23dddd8a2..128faa048bb 100644 --- a/core/modules/savers/andtidwiki.js +++ b/core/modules/savers/andtidwiki.js @@ -15,11 +15,28 @@ Handles saving changes via the AndTidWiki Android app var AndTidWiki = function(wiki) { }; -AndTidWiki.prototype.save = function(text,method,callback) { +AndTidWiki.prototype.save = function(text,method,callback,options) { + var filename = options && options.variables ? options.variables.filename : null; if (method === "download") { // Support download if (window.twi.saveDownload) { window.twi.saveDownload(text); + } else { + // Using broofa/node-mime, Licensed under https://raw.githubusercontent.com/broofa/node-mime/master/LICENSE + if (typeof(mimelite) === "undefined") { + var mime = document.createElement("script"); + mime.setAttribute("src","https://wzrd.in/standalone/mime%2flite@latest"); + document.body.appendChild(mime); + } + var link = document.createElement("a"); + var type = typeof(mimelite) === "object" ? mimelite.getType(filename) : "text/plain" ; + link.setAttribute("href","data:" + type + "," + encodeURIComponent(text)); + if (filename) { + link.setAttribute("download",filename); + } + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); } } else if (window.twi.saveWiki) { // Direct save in Tiddloid From b140b4c31c205af3936d3422df551a2921556aa9 Mon Sep 17 00:00:00 2001 From: donmor Date: Sun, 20 Oct 2019 01:57:44 +0800 Subject: [PATCH 7/9] Update andtidwiki.js --- core/modules/savers/andtidwiki.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/modules/savers/andtidwiki.js b/core/modules/savers/andtidwiki.js index 128faa048bb..ea88ec54244 100644 --- a/core/modules/savers/andtidwiki.js +++ b/core/modules/savers/andtidwiki.js @@ -20,7 +20,7 @@ AndTidWiki.prototype.save = function(text,method,callback,options) { if (method === "download") { // Support download if (window.twi.saveDownload) { - window.twi.saveDownload(text); + window.twi.saveDownload(text,filename); } else { // Using broofa/node-mime, Licensed under https://raw.githubusercontent.com/broofa/node-mime/master/LICENSE if (typeof(mimelite) === "undefined") { From 7cfa0785311526fcd653a6e79b75ed4d553d4ab2 Mon Sep 17 00:00:00 2001 From: donmor Date: Sun, 20 Oct 2019 04:16:25 +0800 Subject: [PATCH 8/9] Update andtidwiki.js --- core/modules/savers/andtidwiki.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/core/modules/savers/andtidwiki.js b/core/modules/savers/andtidwiki.js index ea88ec54244..c280905e981 100644 --- a/core/modules/savers/andtidwiki.js +++ b/core/modules/savers/andtidwiki.js @@ -22,15 +22,8 @@ AndTidWiki.prototype.save = function(text,method,callback,options) { if (window.twi.saveDownload) { window.twi.saveDownload(text,filename); } else { - // Using broofa/node-mime, Licensed under https://raw.githubusercontent.com/broofa/node-mime/master/LICENSE - if (typeof(mimelite) === "undefined") { - var mime = document.createElement("script"); - mime.setAttribute("src","https://wzrd.in/standalone/mime%2flite@latest"); - document.body.appendChild(mime); - } var link = document.createElement("a"); - var type = typeof(mimelite) === "object" ? mimelite.getType(filename) : "text/plain" ; - link.setAttribute("href","data:" + type + "," + encodeURIComponent(text)); + link.setAttribute("href","data:text/plain," + encodeURIComponent(text)); if (filename) { link.setAttribute("download",filename); } From 1c0b2f2a9bcd7477dd0c6f1ed03325a9ed79bca0 Mon Sep 17 00:00:00 2001 From: donmor Date: Sun, 20 Oct 2019 06:23:13 +0800 Subject: [PATCH 9/9] Update andtidwiki.js --- core/modules/savers/andtidwiki.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/modules/savers/andtidwiki.js b/core/modules/savers/andtidwiki.js index c280905e981..df2b0ceaa70 100644 --- a/core/modules/savers/andtidwiki.js +++ b/core/modules/savers/andtidwiki.js @@ -20,7 +20,13 @@ AndTidWiki.prototype.save = function(text,method,callback,options) { if (method === "download") { // Support download if (window.twi.saveDownload) { - window.twi.saveDownload(text,filename); + try { + window.twi.saveDownload(text,filename); + } catch(err) { + if (err.message === "Method not found") { + window.twi.saveDownload(text); + } + } } else { var link = document.createElement("a"); link.setAttribute("href","data:text/plain," + encodeURIComponent(text));