notify.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. function ntf_show(msg, timeout = 8) {
  17. if (ntf_msg_list.length < ntf_max_msg_line) {
  18. ntf_msg_list.push(msg);
  19. } else {
  20. for (let i = 1; i < ntf_msg_list.length; i++) {
  21. ntf_msg_list[i - 1] = ntf_msg_list[i];
  22. }
  23. ntf_msg_list[ntf_msg_list.length - 1] = msg;
  24. }
  25. let divNotify = document.getElementById("id_pcd_notify");
  26. if (divNotify) {
  27. let strHtml = "";
  28. for (const strMsg of ntf_msg_list) {
  29. strHtml += "<div class='ntf_msg_div'>";
  30. strHtml += strMsg;
  31. strHtml += "</div>";
  32. }
  33. divNotify.innerHTML = strHtml;
  34. divNotify.style.display = "block";
  35. setTimeout("ntf_hide()", timeout * 1000);
  36. }
  37. }
  38. function ntf_hide() {
  39. document.getElementById("id_pcd_notify").style.display = "none";
  40. }