From 1fd59a4bd312ead20251da80dd7bceb52f9c2bb0 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Mon, 19 Aug 2013 13:55:40 +0100 Subject: [PATCH] First pass at a saver for the AndTidWiki app on Android --- core/modules/savers/andtidwiki.js | 63 +++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 core/modules/savers/andtidwiki.js diff --git a/core/modules/savers/andtidwiki.js b/core/modules/savers/andtidwiki.js new file mode 100644 index 000000000..e165a0b1b --- /dev/null +++ b/core/modules/savers/andtidwiki.js @@ -0,0 +1,63 @@ +/*\ +title: $:/core/modules/savers/andtidwiki.js +type: application/javascript +module-type: saver + +Handles saving changes via the AndTidWiki Android app + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false, netscape: false, Components: false */ +"use strict"; + +var AndTidWiki = function(wiki) { +}; + +AndTidWiki.prototype.save = function(text,callback) { + // Get the pathname of this document + var pathname = decodeURIComponent(document.location.toString()); + // 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) + // Call the callback + callback(null); + return true; +}; + +/* +Information about this saver +*/ +AndTidWiki.prototype.info = { + name: "andtidwiki", + priority: 1600 +}; + +/* +Static method that returns true if this saver is capable of working +*/ +exports.canSave = function(wiki) { + return !!window.twi && !!window.twi.saveFile; +}; + +/* +Create an instance of this saver +*/ +exports.create = function(wiki) { + return new AndTidWiki(wiki); +}; + +})();