From 14d7d5ea597ee32d1c0e197f878a80595901b750 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Tue, 29 Oct 2013 14:51:35 +0000 Subject: [PATCH] Use the new wiki.makeWidget() method where we can --- core/modules/commands/new_rendertiddlers.js | 13 +----------- .../parsers/wikiparser/rules/typedblock.js | 8 ++----- core/modules/startup.js | 7 +------ core/modules/utils/dom/modal.js | 21 +++---------------- core/modules/utils/dom/notifier.js | 7 +------ 5 files changed, 8 insertions(+), 48 deletions(-) diff --git a/core/modules/commands/new_rendertiddlers.js b/core/modules/commands/new_rendertiddlers.js index 291b3840b..26362f39d 100644 --- a/core/modules/commands/new_rendertiddlers.js +++ b/core/modules/commands/new_rendertiddlers.js @@ -41,18 +41,7 @@ Command.prototype.execute = function() { tiddlers = wiki.filterTiddlers(filter); $tw.utils.each(tiddlers,function(title) { var parser = wiki.new_parseTiddler(template), - parseTreeNode = parser ? {type: "widget", children: [{ - type: "setvariable", - attributes: { - name: {type: "string", value: "currentTiddler"}, - value: {type: "string", value: title} - }, - children: parser.tree - }]} : undefined, - widgetNode = new widget.widget(parseTreeNode,{ - wiki: wiki, - document: $tw.document - }); + widgetNode = wiki.makeWidget(parser,{variables: {currentTiddler: title}}); var container = $tw.document.createElement("div"); widgetNode.render(container,null); var text = type === "text/html" ? container.innerHTML : container.textContent; diff --git a/core/modules/parsers/wikiparser/rules/typedblock.js b/core/modules/parsers/wikiparser/rules/typedblock.js index 3ee3b5e35..ac4891043 100644 --- a/core/modules/parsers/wikiparser/rules/typedblock.js +++ b/core/modules/parsers/wikiparser/rules/typedblock.js @@ -65,12 +65,8 @@ exports.parse = function() { return parser.tree; } else { // Otherwise, render to the rendertype and return in a
 tag
-		var parseTreeNode = parser ? {type: "widget", children: parser.tree} : undefined,
-			widgetNode = new widget.widget(parseTreeNode,{
-				wiki: $tw.wiki,
-				document: $tw.document
-			});
-		var container = $tw.document.createElement("div");
+		var widgetNode = this.parser.wiki.makeWidget(parser),
+			container = $tw.document.createElement("div");
 		widgetNode.render(container,null);
 		var text = renderType === "text/html" ? container.innerHTML : container.textContent;
 		return [{
diff --git a/core/modules/startup.js b/core/modules/startup.js
index c20b42198..eab58379a 100755
--- a/core/modules/startup.js
+++ b/core/modules/startup.js
@@ -105,12 +105,7 @@ exports.startup = function() {
 		// Display the PageTemplate
 		var templateTitle = "$:/core/ui/PageTemplate",
 			parser = $tw.wiki.new_parseTiddler(templateTitle),
-			parseTreeNode = parser ? {type: "widget", children: parser.tree} : undefined,
-			widgetNode = new widget.widget(parseTreeNode,{
-				wiki: $tw.wiki,
-				parentWidget: $tw.rootWidget,
-				document: document
-			});
+			widgetNode = $tw.wiki.makeWidget(parser,{document: document, parentWidget: $tw.rootWidget});
 		$tw.new_pageContainer = document.createElement("div");
 		$tw.utils.addClass($tw.new_pageContainer,"tw-page-container");
 		document.body.insertBefore($tw.new_pageContainer,document.body.firstChild);
diff --git a/core/modules/utils/dom/modal.js b/core/modules/utils/dom/modal.js
index 641f68938..76cb2f5f3 100644
--- a/core/modules/utils/dom/modal.js
+++ b/core/modules/utils/dom/modal.js
@@ -74,24 +74,14 @@ Modal.prototype.display = function(title,options) {
 		titleText = title;
 	}
 	var headerParser = this.wiki.new_parseText("text/vnd.tiddlywiki",titleText,{parseAsInline: true}),
-		headerParseTreeNode = headerParser ? {type: "widget", children: headerParser.tree} : undefined,
-		headerWidgetNode = new widget.widget(headerParseTreeNode,{
-			wiki: this.wiki,
-			parentWidget: $tw.rootWidget,
-			document: document
-		});
+		headerWidgetNode = this.wiki.makeWidget(headerParser,{parentWidget: $tw.rootWidget, document: document});
 	headerWidgetNode.render(modalHeader,null);
 	this.wiki.addEventListener("change",function(changes) {
 		headerWidgetNode.refresh(changes,modalHeader,null);
 	});
 	// Render the body of the message
 	var bodyParser = this.wiki.new_parseTiddler(title),
-		bodyParseTreeNode = bodyParser ? {type: "widget", children: bodyParser.tree} : undefined,
-		bodyWidgetNode = new widget.widget(bodyParseTreeNode,{
-			wiki: this.wiki,
-			parentWidget: $tw.rootWidget,
-			document: document
-		});
+		bodyWidgetNode = this.wiki.makeWidget(bodyParser,{parentWidget: $tw.rootWidget, document: document});
 	bodyWidgetNode.render(modalBody,null);
 	this.wiki.addEventListener("change",function(changes) {
 		bodyWidgetNode.refresh(changes,modalBody,null);
@@ -118,12 +108,7 @@ Modal.prototype.display = function(title,options) {
 		footerText = '<$button message="tw-close-tiddler" class="btn btn-primary">Close';
 	}
 	var footerParser = this.wiki.new_parseText("text/vnd.tiddlywiki",footerText,{parseAsInline: true}),
-		footerParseTreeNode = footerParser ? {type: "widget", children: footerParser.tree} : undefined,
-		footerWidgetNode = new widget.widget(footerParseTreeNode,{
-			wiki: this.wiki,
-			parentWidget: $tw.rootWidget,
-			document: document
-		});
+		footerWidgetNode = this.wiki.makeWidget(footerParser,{parentWidget: $tw.rootWidget, document: document});
 	footerWidgetNode.render(modalFooterButtons,null);
 	this.wiki.addEventListener("change",function(changes) {
 		footerWidgetNode.refresh(changes,modalFooterButtons,null);
diff --git a/core/modules/utils/dom/notifier.js b/core/modules/utils/dom/notifier.js
index ad9aab86e..caf355944 100644
--- a/core/modules/utils/dom/notifier.js
+++ b/core/modules/utils/dom/notifier.js
@@ -38,12 +38,7 @@ Notifier.prototype.display = function(title,options) {
 	$tw.utils.addClass(notification,"tw-notification");
 	// Render the body of the notification
 	var parser = this.wiki.new_parseTiddler(title),
-		parseTreeNode = parser ? {type: "widget", children: parser.tree} : undefined,
-		widgetNode = new widget.widget(parseTreeNode,{
-			wiki: this.wiki,
-			parentWidget: $tw.rootWidget,
-			document: document
-		});
+		widgetNode = this.wiki.makeWidget(parser,{parentWidget: $tw.rootWidget, document: document});
 	widgetNode.render(notification,null);
 	this.wiki.addEventListener("change",function(changes) {
 		widgetNode.refresh(changes,notification,null);