1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-09-29 15:30:47 +00:00

Add a better error message for unknown widgets

This commit is contained in:
Jeremy Ruston 2013-01-01 18:00:02 +00:00
parent d96e0073ac
commit 2124dd1ac1
5 changed files with 59 additions and 6 deletions

View File

@ -32,10 +32,10 @@ var WidgetRenderer = function(renderTree,renderContext,parseTreeNode) {
if(WidgetClass) { if(WidgetClass) {
this.widget = new WidgetClass(this); this.widget = new WidgetClass(this);
} else { } else {
// Error if we couldn't find the widget WidgetClass = this.widgetClasses.error;
this.children = this.renderTree.createRenderers(this.renderContext,[ if(WidgetClass) {
{type: "text", text: "Unknown widget type '" + this.parseTreeNode.tag + "'"} this.widget = new WidgetClass(this,"Unknown widget '" + this.parseTreeNode.tag + "'");
]); }
} }
}; };

View File

@ -0,0 +1,41 @@
/*\
title: $:/core/modules/widgets/error.js
type: application/javascript
module-type: widget
The error widget displays an error message.
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var ErrorWidget = function(renderer,errorMessage) {
// Save state
this.renderer = renderer;
this.errorMessage = errorMessage;
// Generate child nodes
this.generateChildNodes();
};
ErrorWidget.prototype.generateChildNodes = function() {
// Create the wrapper node
var node = {
type: "element",
tag: "span",
children: [{
type: "text",
text: this.errorMessage
}]
};
// Set up the attributes for the wrapper element
$tw.utils.addClassToParseTreeNode(node,"tw-error-widget");
// Create the renderers for the wrapper and the children
this.children = this.renderer.renderTree.createRenderers(this.renderer.renderContext,[node]);
};
exports.error = ErrorWidget;
})();

View File

@ -6079,6 +6079,13 @@ a.tw-tiddlylink-missing {
box-shadow: inset 1px 1px 4px 1px rgba(0, 0, 0, 0.15); box-shadow: inset 1px 1px 4px 1px rgba(0, 0, 0, 0.15);
} }
.tw-error-widget {
padding: 5px 5px 5px 5px;
margin: 15px 15px 15px 15px;
color: white;
background-color: red;
}
.tw-scrollable .tw-tiddler-frame { .tw-scrollable .tw-tiddler-frame {
width: 400px; width: 400px;
padding: 30px 30px 30px 30px; padding: 30px 30px 30px 30px;

View File

@ -1,7 +1,5 @@
title: $:/templates/PageTemplate title: $:/templates/PageTemplate
<$nosuchwidget />
<!-- The navigator catches navigation events and updates the story and history tiddlers --> <!-- The navigator catches navigation events and updates the story and history tiddlers -->
<$navigator story="$:/StoryList" history="$:/HistoryList"> <$navigator story="$:/StoryList" history="$:/HistoryList">

View File

@ -181,6 +181,13 @@ a.tw-tiddlylink-missing {
background: #ccc; background: #ccc;
} }
.tw-error-widget {
background-color: red;
color: white;
padding: 5px 5px 5px 5px;
margin: 15px 15px 15px 15px;
}
.tw-scrollable-outer { .tw-scrollable-outer {
} }