Guest User

Untitled

a guest
Jun 19th, 2018
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. /**
  2. * Message Class
  3. * Handles displaying of messages
  4. * @author Danilo Bargen <gezuru@gmail.com>
  5. * @param string type Type of message (ok, info, alert, error)
  6. * @param string dest ID of destination DOM element
  7. * @param string message Message to be displayed
  8. * @param string bold Optional bold text preceding the error message
  9. */
  10. function Message (type, dest, message, bold) {
  11. this.id = new Date().getTime();
  12. this.type = type;
  13. this.dest = dest;
  14. if ( bold === undefined) {
  15. this.bold = '';
  16. }
  17. else {
  18. this.bold = bold;
  19. }
  20. this.message = message;
  21. this.showMessage = showMessage;
  22. this.hideMessage = hideMessage;
  23. this.clearAllMessages = clearAllMessages;
  24. }
  25.  
  26. /**
  27. * Displays Message in previously defined DOM element
  28. * @author Danilo Bargen <gezuru@gmail.com>
  29. * @return false if invalid type was passed previously
  30. */
  31. function showMessage() {
  32. switch (this.type)
  33. {
  34. case 'ok':
  35. this.icon = 'check';
  36. this.classname = 'ok';
  37. break;
  38. case 'info':
  39. this.icon = 'info';
  40. this.classname = 'ok';
  41. break;
  42. case 'alert':
  43. this.icon = 'alert';
  44. this.classname = 'highlight';
  45. break;
  46. case 'error':
  47. this.icon = 'closethick';
  48. this.classname = 'error';
  49. break;
  50. default:
  51. return false;
  52. }
  53. this.msgHtml = '<div id="' + this.id + '" class="ui-state-' + this.classname + ' ui-corner-all" style="padding: 0em 0.6em;">';
  54. this.msgHtml = this.msgHtml + '<p><span class="ui-icon ui-icon-' + this.icon + '" style="float: left; margin-right: .3em;"></span>';
  55. this.msgHtml = this.msgHtml + '<strong>' + this.bold + '</strong> ' + this.message + '</p></div><br />';
  56. $('#'+this.id).remove();
  57. $('#'+this.dest).append(this.msgHtml);
  58. }
  59.  
  60. /**
  61. * Removes Message from previously defined DOM element
  62. * @author Danilo Bargen <gezuru@gmail.com>
  63. */
  64. function hideMessage() {
  65. $('#'+this.id).remove();
  66. }
  67.  
  68. /**
  69. * Removes all Messages from previously defined DOM element
  70. * @author Danilo Bargen <gezuru@gmail.com>
  71. */
  72. function clearAllMessages() {
  73. $('#'+this.dest).empty();
  74. }
Add Comment
Please, Sign In to add comment