notify.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. var ntf_msg_list = new Array();
  2. var ntf_max_msg_line = 2;
  3. function ntf_init(lines = 5) {
  4. ntf_max_msg_line = lines;
  5. var divNotify = document.createElement("div");
  6. var typ = document.createAttribute("class");
  7. typ.nodeValue = "pcd_notify";
  8. divNotify.attributes.setNamedItem(typ);
  9. var typId = document.createAttribute("id");
  10. typId.nodeValue = "id_pcd_notify";
  11. divNotify.attributes.setNamedItem(typId);
  12. var body = document.getElementsByTagName("body")[0];
  13. body.appendChild(divNotify);
  14. divNotify.style.display = "none";
  15. }
  16. var time_out_func
  17. function ntf_show(msg, timeout = 8) {
  18. if (ntf_msg_list.length < ntf_max_msg_line) {
  19. ntf_msg_list.push(msg);
  20. } else {
  21. for (let i = 1; i < ntf_msg_list.length; i++) {
  22. ntf_msg_list[i - 1] = ntf_msg_list[i];
  23. }
  24. ntf_msg_list[ntf_msg_list.length - 1] = msg;
  25. }
  26. let divNotify = document.getElementById("id_pcd_notify");
  27. if (divNotify) {
  28. let strHtml = "";
  29. for (const strMsg of ntf_msg_list) {
  30. strHtml += "<div class='ntf_msg_div'>";
  31. strHtml += strMsg;
  32. strHtml += "</div>";
  33. }
  34. strHtml += "<button onclick='ntf_hide()' style='margin-left: 70%;white-space: nowrap;'>" + gLocal.gui.I_know + "</button>"
  35. divNotify.innerHTML = strHtml;
  36. divNotify.style.display = "block";
  37. setTimeout("ntf_hide()", timeout * 1000);
  38. }
  39. }
  40. function ntf_hide() {
  41. document.getElementById("id_pcd_notify").style.display = "none";
  42. }