1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-04-21 18:23:13 +00:00

tidy up nested button detection

This commit is contained in:
pmario 2024-04-18 09:07:27 +02:00
parent 474905828f
commit 9f4f76d4c8

View File

@ -18,10 +18,6 @@ var Popup = require("$:/core/modules/utils/dom/popup.js");
var ButtonWidget = function(parseTreeNode,options) {
this.initialise(parseTreeNode,options);
// Check if any parent is a button. Custom recursion detection for buttons in buttons
if(!this.hasVariable("tv-is-button","yes")) {
this.setVariable("tv-is-button", "yes");
}
};
/*
@ -29,6 +25,20 @@ Inherit from the base widget class
*/
ButtonWidget.prototype = new Widget();
/*
Detect nested buttons
*/
ButtonWidget.prototype.isNestedButton = function() {
var pointer = this.parentWidget;
while(pointer) {
if(pointer instanceof ButtonWidget) {
return true;
}
pointer = pointer.parentWidget;
}
return false;
}
/*
Render this widget into the DOM
*/
@ -43,14 +53,14 @@ ButtonWidget.prototype.render = function(parent,nextSibling) {
this.execute();
// Check "button in button". Return early with an error message
// This check also prevents fatal recursion errors using the transclusion widget
if(this.parentWidget && this.parentWidget.hasVariable("tv-is-button","yes")) {
if(this.isNestedButton()) {
var domNode = this.document.createElement("span");
var textNode = this.document.createTextNode($tw.language.getString("Error/RecursiveButton"));
domNode.appendChild(textNode);
domNode.className = "tc-error";
parent.insertBefore(domNode,nextSibling);
this.domNodes.push(domNode);
return;
return; // an error message
}
// Create element
if(this.buttonTag && $tw.config.htmlUnsafeElements.indexOf(this.buttonTag) === -1) {