mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-25 16:36:52 +00:00
Switch to using $tw.fakeDocument
for the fakedom document object
So that we can free us `$tw.document` to be the actual DOM document
This commit is contained in:
parent
839361d54f
commit
2c790d982f
@ -42,7 +42,7 @@ Command.prototype.execute = function() {
|
|||||||
$tw.utils.each(tiddlers,function(title) {
|
$tw.utils.each(tiddlers,function(title) {
|
||||||
var parser = wiki.parseTiddler(template),
|
var parser = wiki.parseTiddler(template),
|
||||||
widgetNode = wiki.makeWidget(parser,{variables: {currentTiddler: title}});
|
widgetNode = wiki.makeWidget(parser,{variables: {currentTiddler: title}});
|
||||||
var container = $tw.document.createElement("div");
|
var container = $tw.fakeDocument.createElement("div");
|
||||||
widgetNode.render(container,null);
|
widgetNode.render(container,null);
|
||||||
var text = type === "text/html" ? container.innerHTML : container.textContent;
|
var text = type === "text/html" ? container.innerHTML : container.textContent;
|
||||||
fs.writeFileSync(path.resolve(pathname,encodeURIComponent(title) + extension),text,"utf8");
|
fs.writeFileSync(path.resolve(pathname,encodeURIComponent(title) + extension),text,"utf8");
|
||||||
|
@ -66,7 +66,7 @@ exports.parse = function() {
|
|||||||
} else {
|
} else {
|
||||||
// Otherwise, render to the rendertype and return in a <PRE> tag
|
// Otherwise, render to the rendertype and return in a <PRE> tag
|
||||||
var widgetNode = this.parser.wiki.makeWidget(parser),
|
var widgetNode = this.parser.wiki.makeWidget(parser),
|
||||||
container = $tw.document.createElement("div");
|
container = $tw.fakeDocument.createElement("div");
|
||||||
widgetNode.render(container,null);
|
widgetNode.render(container,null);
|
||||||
var text = renderType === "text/html" ? container.innerHTML : container.textContent;
|
var text = renderType === "text/html" ? container.innerHTML : container.textContent;
|
||||||
return [{
|
return [{
|
||||||
|
@ -130,8 +130,8 @@ exports.startup = function() {
|
|||||||
// Set up the styles
|
// Set up the styles
|
||||||
var styleTemplateTitle = "$:/core/ui/PageStylesheet",
|
var styleTemplateTitle = "$:/core/ui/PageStylesheet",
|
||||||
styleParser = $tw.wiki.parseTiddler(styleTemplateTitle);
|
styleParser = $tw.wiki.parseTiddler(styleTemplateTitle);
|
||||||
$tw.styleWidgetNode = $tw.wiki.makeWidget(styleParser,{document: $tw.document});
|
$tw.styleWidgetNode = $tw.wiki.makeWidget(styleParser,{document: $tw.fakeDocument});
|
||||||
$tw.styleContainer = $tw.document.createElement("style");
|
$tw.styleContainer = $tw.fakeDocument.createElement("style");
|
||||||
$tw.styleWidgetNode.render($tw.styleContainer,null);
|
$tw.styleWidgetNode.render($tw.styleContainer,null);
|
||||||
$tw.styleElement = document.createElement("style");
|
$tw.styleElement = document.createElement("style");
|
||||||
$tw.styleElement.innerHTML = $tw.styleContainer.textContent;
|
$tw.styleElement.innerHTML = $tw.styleContainer.textContent;
|
||||||
|
@ -182,6 +182,6 @@ var document = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.document = document;
|
exports.fakeDocument = document;
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -821,7 +821,7 @@ exports.makeWidget = function(parser,options) {
|
|||||||
// Create the widget
|
// Create the widget
|
||||||
return new widget.widget(widgetNode,{
|
return new widget.widget(widgetNode,{
|
||||||
wiki: this,
|
wiki: this,
|
||||||
document: options.document || $tw.document,
|
document: options.document || $tw.fakeDocument,
|
||||||
parentWidget: options.parentWidget
|
parentWidget: options.parentWidget
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -840,7 +840,7 @@ exports.renderText = function(outputType,textType,text,options) {
|
|||||||
options = options || {};
|
options = options || {};
|
||||||
var parser = this.parseText(textType,text,options),
|
var parser = this.parseText(textType,text,options),
|
||||||
widgetNode = this.makeWidget(parser,options);
|
widgetNode = this.makeWidget(parser,options);
|
||||||
var container = $tw.document.createElement("div");
|
var container = $tw.fakeDocument.createElement("div");
|
||||||
widgetNode.render(container,null);
|
widgetNode.render(container,null);
|
||||||
return outputType === "text/html" ? container.innerHTML : container.textContent;
|
return outputType === "text/html" ? container.innerHTML : container.textContent;
|
||||||
};
|
};
|
||||||
@ -858,7 +858,7 @@ exports.renderTiddler = function(outputType,title,options) {
|
|||||||
options = options || {};
|
options = options || {};
|
||||||
var parser = this.parseTiddler(title),
|
var parser = this.parseTiddler(title),
|
||||||
widgetNode = this.makeWidget(parser,options);
|
widgetNode = this.makeWidget(parser,options);
|
||||||
var container = $tw.document.createElement("div");
|
var container = $tw.fakeDocument.createElement("div");
|
||||||
widgetNode.render(container,null);
|
widgetNode.render(container,null);
|
||||||
return outputType === "text/html" ? container.innerHTML : container.textContent;
|
return outputType === "text/html" ? container.innerHTML : container.textContent;
|
||||||
};
|
};
|
||||||
|
@ -19,7 +19,7 @@ describe("Widget module", function() {
|
|||||||
function createWidgetNode(parseTreeNode,wiki) {
|
function createWidgetNode(parseTreeNode,wiki) {
|
||||||
return new widget.widget(parseTreeNode,{
|
return new widget.widget(parseTreeNode,{
|
||||||
wiki: wiki,
|
wiki: wiki,
|
||||||
document: $tw.document
|
document: $tw.fakeDocument
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,8 +29,8 @@ describe("Widget module", function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderWidgetNode(widgetNode) {
|
function renderWidgetNode(widgetNode) {
|
||||||
$tw.document.setSequenceNumber(0);
|
$tw.fakeDocument.setSequenceNumber(0);
|
||||||
var wrapper = $tw.document.createElement("div");
|
var wrapper = $tw.fakeDocument.createElement("div");
|
||||||
widgetNode.render(wrapper,null);
|
widgetNode.render(wrapper,null);
|
||||||
// console.log(require("util").inspect(wrapper,{depth: 8}));
|
// console.log(require("util").inspect(wrapper,{depth: 8}));
|
||||||
return wrapper;
|
return wrapper;
|
||||||
|
@ -22,7 +22,7 @@ The following widget properties are defined by the core. The lifecycle of a widg
|
|||||||
|''wiki'' |Reference to the [[Wiki]] object associated with this widget |
|
|''wiki'' |Reference to the [[Wiki]] object associated with this widget |
|
||||||
|''variables'' |Hashmap of information about each [[widget variable|WidgetVariables]] (see below) |
|
|''variables'' |Hashmap of information about each [[widget variable|WidgetVariables]] (see below) |
|
||||||
|''parentWidget'' |Reference to the parent widget |
|
|''parentWidget'' |Reference to the parent widget |
|
||||||
|''document'' |Reference to the document object associated with this widget. Usually either the browser global `document` variable or a reference to the FakeDomMechanism's `$tw.document` |
|
|''document'' |Reference to the document object associated with this widget. Usually either the browser global `document` variable or a reference to the FakeDomMechanism's `$tw.fakeDocument` |
|
||||||
|''attributes'' |Hashmap of information about each attribute attached to this widget (see below) |
|
|''attributes'' |Hashmap of information about each attribute attached to this widget (see below) |
|
||||||
|''children'' |Array of child widgets |
|
|''children'' |Array of child widgets |
|
||||||
|''domNodes'' |For widgets that directly generate DOM nodes, an array of the generated nodes |
|
|''domNodes'' |For widgets that directly generate DOM nodes, an array of the generated nodes |
|
||||||
|
Loading…
Reference in New Issue
Block a user