mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-10 11:59:58 +00:00
add override saver (#4908)
* add override saver * rename 'override' to 'custom' and use the global instead of introducing a new one
This commit is contained in:
parent
57ba4c8cba
commit
651619076a
60
core/modules/savers/custom.js
Normal file
60
core/modules/savers/custom.js
Normal file
@ -0,0 +1,60 @@
|
||||
/*\
|
||||
title: $:/core/modules/savers/custom.js
|
||||
type: application/javascript
|
||||
module-type: saver
|
||||
|
||||
Looks for `window.$tw.customSaver` first on the current window, then
|
||||
on the parent window (of an iframe). If present, the saver must define
|
||||
save: function(text,method,callback) { ... }
|
||||
and the saver may define
|
||||
priority: number
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
var findSaver = function(window) {
|
||||
try {
|
||||
return window && window.$tw && window.$tw.customSaver;
|
||||
} catch (err) {
|
||||
// Catching the exception is the most reliable way to detect cross-origin iframe errors.
|
||||
// For example, instead of saying that `window.parent.$tw` is undefined, Firefox will throw
|
||||
// Uncaught DOMException: Permission denied to access property "$tw" on cross-origin object
|
||||
console.log({ msg: "custom saver is disabled", reason: err });
|
||||
return null;
|
||||
}
|
||||
}
|
||||
var saver = findSaver(window) || findSaver(window.parent) || {};
|
||||
|
||||
var CustomSaver = function(wiki) {
|
||||
};
|
||||
|
||||
CustomSaver.prototype.save = function(text,method,callback) {
|
||||
return saver.save(text, method, callback);
|
||||
};
|
||||
|
||||
/*
|
||||
Information about this saver
|
||||
*/
|
||||
CustomSaver.prototype.info = {
|
||||
name: "custom",
|
||||
priority: saver.priority || 4000,
|
||||
capabilities: ["save","autosave"]
|
||||
};
|
||||
|
||||
/*
|
||||
Static method that returns true if this saver is capable of working
|
||||
*/
|
||||
exports.canSave = function(wiki) {
|
||||
return !!(saver.save);
|
||||
};
|
||||
|
||||
/*
|
||||
Create an instance of this saver
|
||||
*/
|
||||
exports.create = function(wiki) {
|
||||
return new CustomSaver(wiki);
|
||||
};
|
||||
})();
|
@ -415,3 +415,5 @@ Kamal Habash, @Kamal-Habash, 2020/08/28
|
||||
Florian Kohrt, @fkohrt, 2020/09/10
|
||||
|
||||
Gerald Liu, @gera2ld, 2020/09/25
|
||||
|
||||
Ryan Kramer, @default-kramer, 2020/10/24
|
||||
|
Loading…
Reference in New Issue
Block a user