2
0

notify.js 1.5 KB

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