You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 line
1.7KB

  1. /** Modified from original Node-Red source, for audio system visualization
  2. * vim: set ts=4:
  3. * Copyright 2013 IBM Corp.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. **/
  17. RED.notify = (function() {
  18. var currentNotifications = [];
  19. var c = 0;
  20. return function(msg,type,fixed,timeout) {
  21. if (currentNotifications.length > 4) {
  22. var ll = currentNotifications.length;
  23. for (var i = 0;ll > 4 && i<currentNotifications.length;i+=1) {
  24. var notifiction = currentNotifications[i];
  25. if (!notifiction.fixed) {
  26. window.clearTimeout(notifiction.timeoutid);
  27. notifiction.close();
  28. ll -= 1;
  29. }
  30. }
  31. }
  32. var n = document.createElement("div");
  33. n.id="red-notification-"+c;
  34. n.className = "alert";
  35. n.fixed = fixed;
  36. if (type) {
  37. n.className = "alert alert-"+type;
  38. }
  39. n.style.display = "none";
  40. n.innerHTML = msg;
  41. $("#notifications").append(n);
  42. $(n).slideDown(300);
  43. n.close = (function() {
  44. var nn = n;
  45. return function() {
  46. currentNotifications.splice(currentNotifications.indexOf(nn),1);
  47. $(nn).slideUp(300, function() {
  48. nn.parentNode.removeChild(nn);
  49. });
  50. };
  51. })();
  52. if (!fixed) {
  53. n.timeoutid = window.setTimeout(n.close,timeout||3000);
  54. }
  55. currentNotifications.push(n);
  56. c+=1;
  57. return n;
  58. }
  59. })();