1/** @enum AlertType */ 2const AlertType = { 3 INFO: "INFO", 4 WARNING: "WARNING", 5 ERROR: "ERROR" 6}; 7 8/** 9 * Swap global alert messaging through frontend when applicable e.g. custom client side 10 * form validation that may require messaging to notify the user. 11 * @param message {string} the message to display 12 * @param type {AlertType} the message type 13 */ 14function swapMessaging(message, type) { 15 let typeCss; 16 switch (type) { 17 case AlertType.WARNING: 18 typeCss = "alert-warning"; 19 break; 20 case AlertType.ERROR: 21 typeCss = "alert-danger"; 22 break; 23 default: 24 typeCss = "alert-info"; 25 break; 26 } 27 28 const template = document.getElementById("alert-message"); 29 const clone = template.content.cloneNode(true); 30 clone.querySelector(".alert").classList.add(typeCss); 31 clone.querySelector("span").textContent = message; 32 33 const content = clone.children[0].getHTML(); 34 const afterSwapCallback = () => document.getElementById("global-alerts").classList.remove("hidden"); 35 htmx.swap("#global-alerts", content, { swapStyle: 'innerHTML' }, { afterSwapCallback }); 36} 37 38export { 39 AlertType, 40 swapMessaging 41};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.