Skip to content
Snippets Groups Projects
Commit 661bca20 authored by brickode's avatar brickode
Browse files

Added JSDoc

parent 110adadd
No related branches found
No related tags found
1 merge request!7964JSDoc update and misc fixes
...@@ -178,6 +178,29 @@ App.UI.DOM.replace = function(selector, newContent) { ...@@ -178,6 +178,29 @@ App.UI.DOM.replace = function(selector, newContent) {
$(selector).empty().append(newContent); $(selector).empty().append(newContent);
}; };
/**
* Refreshes a given element with the given text or node.
*
* @param {HTMLElement|DocumentFragment} el The element to be refreshed.
* @param {string|HTMLElement|DocumentFragment|function():HTMLElement} replacement The text or node to refresh with. Can be a function returning a node.
*
* @example
* const div = document.createElement("div");
* const text = `Any text, including template literals`;
* div.append(App.UI.DOM.link("Link text", () => { // this link will be replaced with the given text
* App.UI.DOM.refresh(div, text);
* }));
*
* function test() {
* const div = document.createElement("div");
* div.append(App.UI.DOM.link("Link text", () => {
* App.UI.DOM.refresh(div, test); // if function returns a DocumentFragment, use refresh(div, test());
* }));
* return div;
* }
*
* @see For more examples, see killSlave.js and pit.js
*/
App.UI.DOM.refresh = function(el, replacement) { App.UI.DOM.refresh = function(el, replacement) {
if (typeof replacement === 'function') { if (typeof replacement === 'function') {
$(el).empty().append(replacement()); $(el).empty().append(replacement());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment