Merge branch 'button-in-button-fix' into dynamic-max-widget-tree-depth

This commit is contained in:
pmario 2024-04-18 09:13:25 +02:00
commit ee8249d6a2
2 changed files with 17 additions and 3 deletions

View File

@ -283,7 +283,7 @@ exports.httpRequest = function(options) {
// Set up the state change handler
request.onreadystatechange = function() {
if(this.readyState === 4) {
if(this.status === 200 || this.status === 201 || this.status === 204) {
if(this.status >= 200 && this.status < 300) {
// Success!
options.callback(null,this[returnProp],this);
return;

View File

@ -29,6 +29,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 +57,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) {