mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-07-03 18:42:50 +00:00
TiddlyFox now saves with TiddlyWiki5 as well as TiddlyWiki Classic
This commit is contained in:
parent
ce1509f940
commit
68f7072c94
59
core/modules/savers/tiddlyfox.js
Normal file
59
core/modules/savers/tiddlyfox.js
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/*\
|
||||||
|
title: $:/core/modules/savers/tiddlyfox.js
|
||||||
|
type: application/javascript
|
||||||
|
module-type: saver
|
||||||
|
|
||||||
|
Handles saving changes via the TiddlyFox file extension
|
||||||
|
|
||||||
|
\*/
|
||||||
|
(function(){
|
||||||
|
|
||||||
|
/*jslint node: true, browser: true */
|
||||||
|
/*global $tw: false, netscape: false, Components: false */
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var TiddlyFoxSaver = function(wiki) {
|
||||||
|
};
|
||||||
|
|
||||||
|
TiddlyFoxSaver.prototype.save = function(text) {
|
||||||
|
var messageBox = document.getElementById("tiddlyfox-message-box");
|
||||||
|
console.log("messageBox",messageBox);
|
||||||
|
if(messageBox) {
|
||||||
|
// Create the message element and put it in the message box
|
||||||
|
var message = document.createElement("div");
|
||||||
|
message.setAttribute("tiddlyfox-path",document.location.pathname);
|
||||||
|
message.setAttribute("tiddlyfox-content",text);
|
||||||
|
messageBox.appendChild(message);
|
||||||
|
// Create and dispatch the custom event to the extension
|
||||||
|
var event = document.createEvent("Events");
|
||||||
|
event.initEvent("tiddlyfox-save-file",true,false);
|
||||||
|
message.dispatchEvent(event);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Information about this saver
|
||||||
|
*/
|
||||||
|
TiddlyFoxSaver.prototype.info = {
|
||||||
|
name: "tiddlyfox",
|
||||||
|
priority: 1500
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Static method that returns true if this saver is capable of working
|
||||||
|
*/
|
||||||
|
exports.canSave = function(wiki) {
|
||||||
|
return (window.location.protocol === "file:");
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Create an instance of this saver
|
||||||
|
*/
|
||||||
|
exports.create = function(wiki) {
|
||||||
|
return new TiddlyFoxSaver(wiki);
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
@ -20,22 +20,21 @@ var TiddlyFox = {
|
|||||||
// Get the document and window
|
// Get the document and window
|
||||||
var doc = event.originalTarget,
|
var doc = event.originalTarget,
|
||||||
win = doc.defaultView;
|
win = doc.defaultView;
|
||||||
// If it is a TiddlyWiki
|
// If it is a TiddlyWiki classic
|
||||||
if(TiddlyFox.isTiddlyWiki(doc,win)) {
|
if(TiddlyFox.isTiddlyWikiClassic(doc,win)) {
|
||||||
if(confirm("TiddlyFox: Enabling TiddlyWiki file saving capability")) {
|
if(confirm("TiddlyFox: Enabling TiddlyWiki file saving capability")) {
|
||||||
TiddlyFox.injectPage(doc);
|
TiddlyFox.injectScript(doc);
|
||||||
|
TiddlyFox.injectMessageBox(doc);
|
||||||
|
}
|
||||||
|
// If it is a TiddlyWiki5
|
||||||
|
} else if(TiddlyFox.isTiddlyWiki5(doc,win)) {
|
||||||
|
if(confirm("TiddlyFox: Enabling TiddlyWiki5 file saving capability")) {
|
||||||
|
TiddlyFox.injectMessageBox(doc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
injectPage: function(doc) {
|
injectScript: function(doc) {
|
||||||
// Inject the message box
|
|
||||||
var messageBox = doc.createElement("div");
|
|
||||||
messageBox.id = "tiddlyfox-message-box";
|
|
||||||
messageBox.style.display = "none";
|
|
||||||
doc.body.appendChild(messageBox);
|
|
||||||
// Attach the event handler to the message box
|
|
||||||
messageBox.addEventListener("tiddlyfox-save-file",TiddlyFox.onSaveFile,false);
|
|
||||||
// Load the script text
|
// Load the script text
|
||||||
var xhReq = new XMLHttpRequest();
|
var xhReq = new XMLHttpRequest();
|
||||||
xhReq.open("GET","chrome://tiddlyfox/content/inject.js",false);
|
xhReq.open("GET","chrome://tiddlyfox/content/inject.js",false);
|
||||||
@ -49,6 +48,19 @@ var TiddlyFox = {
|
|||||||
doc.getElementsByTagName("head")[0].appendChild(scr)
|
doc.getElementsByTagName("head")[0].appendChild(scr)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
injectMessageBox: function(doc) {
|
||||||
|
// Inject the message box
|
||||||
|
var messageBox = doc.getElementById("tiddlyfox-message-box");
|
||||||
|
if(!messageBox) {
|
||||||
|
messageBox = doc.createElement("div");
|
||||||
|
messageBox.id = "tiddlyfox-message-box";
|
||||||
|
messageBox.style.display = "none";
|
||||||
|
doc.body.appendChild(messageBox);
|
||||||
|
}
|
||||||
|
// Attach the event handler to the message box
|
||||||
|
messageBox.addEventListener("tiddlyfox-save-file",TiddlyFox.onSaveFile,false);
|
||||||
|
},
|
||||||
|
|
||||||
saveFile: function(filePath,content) {
|
saveFile: function(filePath,content) {
|
||||||
try {
|
try {
|
||||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||||
@ -84,10 +96,22 @@ var TiddlyFox = {
|
|||||||
window.open("chrome://tiddlyfox/content/hello.xul", "", "chrome");
|
window.open("chrome://tiddlyfox/content/hello.xul", "", "chrome");
|
||||||
},
|
},
|
||||||
|
|
||||||
isTiddlyWiki: function(doc,win) {
|
isTiddlyWikiClassic: function(doc,win) {
|
||||||
// Test whether the document is a TiddlyWiki (we don't have access to JS objects in it)
|
// Test whether the document is a TiddlyWiki (we don't have access to JS objects in it)
|
||||||
return (doc.location.protocol === "file:") &&
|
return (doc.location.protocol === "file:") &&
|
||||||
(doc.scripts[0].id === "versionArea");
|
(doc.scripts[0].id === "versionArea");
|
||||||
|
},
|
||||||
|
|
||||||
|
isTiddlyWiki5: function(doc,win) {
|
||||||
|
// Test whether the document is a TiddlyWiki5 (we don't have access to JS objects in it)
|
||||||
|
var metaTags = doc.getElementsByTagName("meta"),
|
||||||
|
generator = false;
|
||||||
|
for(var t=0; t<metaTags.length; t++) {
|
||||||
|
if(metaTags[t].name === "application-name" && metaTags[t].content === "TiddlyWiki") {
|
||||||
|
generator = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (doc.location.protocol === "file:") && generator;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user