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:
parent
d96e0073ac
commit
2124dd1ac1
@ -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 + "'");
|
||||||
]);
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
41
core/modules/widgets/error.js
Normal file
41
core/modules/widgets/error.js
Normal 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;
|
||||||
|
|
||||||
|
})();
|
@ -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;
|
||||||
|
@ -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">
|
||||||
|
|
||||||
|
@ -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 {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user