Skip to content

Commit

Permalink
TinyMCE/Sketch: Popup does not close
Browse files Browse the repository at this point in the history
  • Loading branch information
toanlamt committed Nov 5, 2024
1 parent 9fc6479 commit 68a4c0e
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion miniPaint/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ $(document).ready(function() {
}
}
// Close window.
$(".modal .close", top.document).click();
findAndCloseModal(top);
}, 200);
});
}, 200);
Expand Down Expand Up @@ -73,3 +73,37 @@ function open_image(image){
};
Layers.insert(new_layer);
}

/**
* This function is designed to search for a close button within a modal dialog present in the current window
* and any nested iframes. If the button is found, it programmatically triggers a click event on it to close the modal.
*
* @param currentWindow The window object from which to start the search
* @return {boolean}
*/
function findAndCloseModal(currentWindow) {
// Check if the current window's document contains the close button.
const closeButton = $(currentWindow.document).find('.modal .close, .modal .btn-close');

if (closeButton.length) {
// If the close button is found, trigger the click event.
closeButton.trigger('click');
return true;
}

// If the close button is not found, check the iframes.
const iframes = currentWindow.document.getElementsByTagName('iframe');

for (let i = 0; i < iframes.length; i++) {
// Get the content window of the iframe.
const iframeWindow = iframes[i].contentWindow;

// Recursively call the function on the iframe window.
if (findAndCloseModal(iframeWindow)) {
// If the button was found in the iframe, stop searching.
return true;
}
}

return false;
}

0 comments on commit 68a4c0e

Please sign in to comment.