1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-04-12 13:53:13 +00:00

Merge 49208cf056602df57d62fcff454562b799d2df41 into 961e74f73d230d0028efb586db07699120eac888

This commit is contained in:
Mario Pietsch 2025-04-04 15:00:28 +02:00 committed by GitHub
commit e336f675ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 60 additions and 1 deletions

View File

@ -37,6 +37,7 @@ Error/NetworkErrorAlert: `<h2>''Network Error''</h2>It looks like the connection
Error/PutEditConflict: File changed on server
Error/PutForbidden: Permission denied
Error/PutUnauthorized: Authentication required
Error/RecursiveButton: Possible Recursive Error: Button in button is not allowed
Error/RecursiveTransclusion: Recursive transclusion error in transclude widget
Error/RetrievingSkinny: Error retrieving skinny tiddler list
Error/SavingToTWEdit: Error saving to TWEdit

View File

@ -22,6 +22,23 @@ Inherit from the base widget class
*/
ButtonWidget.prototype = new Widget();
/*
Detect nested buttons
*/
ButtonWidget.prototype.isNestedButton = function() {
var pointer = this.parentWidget,
depth = 0;
while(pointer) {
if(pointer instanceof ButtonWidget) {
// we allow 1 nested button
if(depth > 1) return true;
depth += 1;
}
pointer = pointer.parentWidget;
}
return false;
}
/*
Render this widget into the DOM
*/
@ -34,6 +51,17 @@ ButtonWidget.prototype.render = function(parent,nextSibling) {
// Compute attributes and execute state
this.computeAttributes();
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.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; // an error message
}
// Create element
if(this.buttonTag && $tw.config.htmlUnsafeElements.indexOf(this.buttonTag) === -1) {
tag = this.buttonTag;
@ -71,7 +99,7 @@ ButtonWidget.prototype.render = function(parent,nextSibling) {
if(this["aria-label"]) {
domNode.setAttribute("aria-label",this["aria-label"]);
}
if (this.role) {
if(this.role) {
domNode.setAttribute("role", this.role);
}
if(this.popup || this.popupTitle) {

View File

@ -0,0 +1,15 @@
title: Transclude/Recursion/Button
description: Transclusion recursion inside a button
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\whitespace trim
<$button>
<$transclude/>
</$button>
+
title: ExpectedResult
<p><button class=""><button class=""><button class=""><span class="tc-error">Possible Recursive Error: Button in button is not allowed</span></button></button></button></p>

View File

@ -0,0 +1,15 @@
title: Transclude/Recursion/ButtonInButton
description: Button in Button
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\whitespace trim
<$button>Test Button
<$button>Second button
</$button>
+
title: ExpectedResult
<p><button class="">Test Button<button class="">Second button</button></button></p>