mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-02-08 23:39:32 +00:00
[MIRROR] Add replace_html to tgwindows (for real this time) [MDB IGNORE] (#13740)
* Add replace_html to tgwindows (for real this time) (#67137) adds the ability to realtime inject HTML into TGWindow instances, just as you can create TGWindow instances with inline_html at initialization. Co-authored-by: Aleksej Komarov <stylemistake@ gmail.com> * Add replace_html to tgwindows (for real this time) Co-authored-by: magatsuchi <88991542+magatsuchi@users.noreply.github.com> Co-authored-by: Aleksej Komarov <stylemistake@ gmail.com>
This commit is contained in:
@@ -291,6 +291,18 @@
|
||||
: "[id].browser:update")
|
||||
message_queue = null
|
||||
|
||||
/**
|
||||
* public
|
||||
*
|
||||
* Replaces the inline HTML content.
|
||||
*
|
||||
* required inline_html string HTML to inject
|
||||
*/
|
||||
/datum/tgui_window/proc/replace_html(inline_html = "")
|
||||
client << output(url_encode(inline_html), is_browser \
|
||||
? "[id]:replaceHtml" \
|
||||
: "[id].browser:replaceHtml")
|
||||
|
||||
/**
|
||||
* private
|
||||
*
|
||||
|
||||
@@ -470,6 +470,26 @@ window.update.flushQueue = function (listener) {
|
||||
}
|
||||
};
|
||||
|
||||
window.replaceHtml = function (inline_html) {
|
||||
var children = document.body.childNodes;
|
||||
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
if (children[i].nodeValue == " tgui:inline-html-start ") {
|
||||
while (children[i].nodeValue != " tgui:inline-html-end ") {
|
||||
children[i].remove();
|
||||
}
|
||||
children[i].remove();
|
||||
}
|
||||
}
|
||||
|
||||
document.body.insertAdjacentHTML(
|
||||
"afterbegin",
|
||||
"<!-- tgui:inline-html-start -->"
|
||||
+ inline_html
|
||||
+ "<!-- tgui:inline-html-end -->"
|
||||
);
|
||||
};
|
||||
|
||||
// Signal tgui that we're ready to receive updates
|
||||
Byond.sendMessage('ready');
|
||||
</script>
|
||||
@@ -577,7 +597,9 @@ blink {
|
||||
|
||||
<!-- tgui:inline-polyfill -->
|
||||
<!-- tgui:assets -->
|
||||
<!-- tgui:inline-html-start -->
|
||||
<!-- tgui:inline-html -->
|
||||
<!-- tgui:inline-html-end -->
|
||||
<!-- tgui:inline-js -->
|
||||
|
||||
<!-- Root element for tgui interfaces -->
|
||||
|
||||
Reference in New Issue
Block a user