/*\ title: $:/plugins/tiddlywiki/tiddlyweb/tiddlywebadaptor.js type: application/javascript module-type: syncadaptor A sync adaptor module for synchronising with TiddlyWeb compatible servers \*/ (function(){ /*jslint node: true, browser: true */ /*global $tw: false */ "use strict"; var CONFIG_HOST_TIDDLER = "$:/config/tiddlyweb/host", DEFAULT_HOST_TIDDLER = "$protocol$//$host$/"; function TiddlyWebAdaptor(options) { this.wiki = options.wiki; this.host = this.getHost(); this.recipe = undefined; this.hasStatus = false; this.logger = new $tw.utils.Logger("TiddlyWebAdaptor"); this.isLoggedIn = false; this.isReadOnly = false; this.logoutIsAvailable = true; } TiddlyWebAdaptor.prototype.name = "tiddlyweb"; TiddlyWebAdaptor.prototype.supportsLazyLoading = true; TiddlyWebAdaptor.prototype.setLoggerSaveBuffer = function(loggerForSaving) { this.logger.setSaveBuffer(loggerForSaving); }; TiddlyWebAdaptor.prototype.isReady = function() { return this.hasStatus; }; TiddlyWebAdaptor.prototype.getHost = function() { var text = this.wiki.getTiddlerText(CONFIG_HOST_TIDDLER,DEFAULT_HOST_TIDDLER), substitutions = [ {name: "protocol", value: document.location.protocol}, {name: "host", value: document.location.host} ]; for(var t=0; t//<revision>:<hash> ``` */ TiddlyWebAdaptor.prototype.parseEtag = function(etag) { var firstSlash = etag.indexOf("/"), lastSlash = etag.lastIndexOf("/"), colon = etag.lastIndexOf(":"); if(firstSlash === -1 || lastSlash === -1 || colon === -1) { return null; } else { return { bag: $tw.utils.decodeURIComponentSafe(etag.substring(1,firstSlash)), title: $tw.utils.decodeURIComponentSafe(etag.substring(firstSlash + 1,lastSlash)), revision: etag.substring(lastSlash + 1,colon) }; } }; if($tw.browser && document.location.protocol.substr(0,4) === "http" ) { exports.adaptorClass = TiddlyWebAdaptor; } })();