notify.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. var ntf_msg_list = new Array();
  2. var ntf_max_msg_line = 5;
  3. function ntf_init(){
  4. var divNotify=document.createElement("div");
  5. var typ=document.createAttribute("class");
  6. typ.nodeValue="pcd_notify";
  7. divNotify.attributes.setNamedItem(typ);
  8. var typId=document.createAttribute("id");
  9. typId.nodeValue="id_pcd_notify";
  10. divNotify.attributes.setNamedItem(typId);
  11. var body=document.getElementsByTagName("body")[0];
  12. body.appendChild(divNotify);
  13. divNotify.style.display="none";
  14. }
  15. function ntf_show(msg,timeout=8){
  16. if(ntf_msg_list.length < ntf_max_msg_line){
  17. ntf_msg_list.push(msg);
  18. }
  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. }