Skip to content

Commit

Permalink
Merge branch 'button-in-button-fix' into dynamic-max-widget-tree-depth
Browse files Browse the repository at this point in the history
  • Loading branch information
pmario committed Apr 18, 2024
2 parents 9820dc0 + 9f4f76d commit ee8249d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/modules/utils/dom/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 16 additions & 2 deletions core/modules/widgets/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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) {
Expand Down

0 comments on commit ee8249d

Please sign in to comment.