2
0

notify.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. var notify_bar;
  2. $(document).ready(function () {
  3. notify_bar = notify_init(1, "bar");
  4. });
  5. function notify_init(lines = 5, style = "dialog") {
  6. let divNotify = document.createElement("div");
  7. var typ = document.createAttribute("class");
  8. switch (style) {
  9. case "dialog":
  10. typ.nodeValue = "pcd_notify";
  11. break;
  12. case "bar":
  13. typ.nodeValue = "pcd_notify_bar";
  14. break;
  15. default:
  16. typ.nodeValue = "pcd_notify";
  17. break;
  18. }
  19. divNotify.attributes.setNamedItem(typ);
  20. let typId = document.createAttribute("id");
  21. let id = "notify_" + com_uuid();
  22. typId.nodeValue = id;
  23. divNotify.attributes.setNamedItem(typId);
  24. let body = document.getElementsByTagName("body")[0];
  25. body.appendChild(divNotify);
  26. divNotify.style.display = "none";
  27. var objNotify = new Object();
  28. objNotify.id = id;
  29. objNotify.top = "3.5em";
  30. objNotify.style = style;
  31. if (style == "bar") {
  32. objNotify.max_msg_line = 1;
  33. } else {
  34. objNotify.max_msg_line = lines;
  35. }
  36. objNotify.msg_list = new Array();
  37. objNotify.timeout = 8;
  38. objNotify.show = function (msg) {
  39. if (this.msg_list.length < this.max_msg_line) {
  40. this.msg_list.push(msg);
  41. } else {
  42. for (let i = 1; i < this.msg_list.length; i++) {
  43. this.msg_list[i - 1] = this.msg_list[i];
  44. }
  45. this.msg_list[this.msg_list.length - 1] = msg;
  46. }
  47. let divNotify = document.getElementById(this.id);
  48. if (divNotify) {
  49. let strHtml = "";
  50. for (const strMsg of this.msg_list) {
  51. strHtml += "<div class='ntf_msg_div'>";
  52. strHtml += strMsg;
  53. strHtml += "</div>";
  54. }
  55. if (this.style == "dialog") {
  56. strHtml +=
  57. "<button onclick='ntf_hide()' style='margin-left: 70%;white-space: nowrap;'>" +
  58. gLocal.gui.I_know +
  59. "</button>";
  60. }
  61. divNotify.innerHTML = strHtml;
  62. divNotify.style.display = "block";
  63. if (this.style == "dialog") {
  64. setTimeout(this.hide, this.timeout * 1000);
  65. }
  66. }
  67. };
  68. objNotify.hide = function () {
  69. document.getElementById(this.id).style.display = "none";
  70. };
  71. return objNotify;
  72. }