PageRenderTime 55ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/resources/META-INF/resources/primefaces/growl/growl.js

http://primefaces.googlecode.com/
JavaScript | 128 lines | 89 code | 27 blank | 12 comment | 5 complexity | 5a664a8a71ce3dff20c2dc21b5082568 MD5 | raw file
Possible License(s): Apache-2.0
  1. /**
  2. * PrimeFaces Growl Widget
  3. */
  4. PrimeFaces.widget.Growl = PrimeFaces.widget.BaseWidget.extend({
  5. init: function(cfg) {
  6. this.cfg = cfg;
  7. this.id = this.cfg.id
  8. this.jqId = PrimeFaces.escapeClientId(this.id);
  9. this.render();
  10. this.removeScriptElement(this.id);
  11. },
  12. //Override
  13. refresh: function(cfg) {
  14. this.cfg = cfg;
  15. this.show(cfg.msgs);
  16. this.removeScriptElement(this.id);
  17. },
  18. show: function(msgs) {
  19. var _self = this;
  20. this.jq.css('z-index', ++PrimeFaces.zindex);
  21. //clear previous messages
  22. this.removeAll();
  23. $.each(msgs, function(index, msg) {
  24. _self.renderMessage(msg);
  25. });
  26. },
  27. removeAll: function() {
  28. this.jq.children('div.ui-growl-item-container').remove();
  29. },
  30. render: function() {
  31. //create container
  32. this.jq = $('<div id="' + this.id + '_container" class="ui-growl ui-widget"></div>');
  33. this.jq.appendTo($(document.body));
  34. //render messages
  35. this.show(this.cfg.msgs);
  36. },
  37. renderMessage: function(msg) {
  38. var markup = '<div class="ui-growl-item-container ui-state-highlight ui-corner-all ui-helper-hidden ui-shadow" aria-live="polite">';
  39. markup += '<div class="ui-growl-item">';
  40. markup += '<div class="ui-growl-icon-close ui-icon ui-icon-closethick" style="display:none"></div>';
  41. markup += '<span class="ui-growl-image ui-growl-image-' + msg.severity + '" />';
  42. markup += '<div class="ui-growl-message">';
  43. markup += '<span class="ui-growl-title"></span>';
  44. markup += '<p></p>';
  45. markup += '</div><div style="clear: both;"></div></div></div>';
  46. var message = $(markup),
  47. summaryEL = message.find('span.ui-growl-title'),
  48. detailEL = summaryEL.next();
  49. if(this.cfg.escape) {
  50. summaryEL.text(msg.summary);
  51. detailEL.text(msg.detail);
  52. }
  53. else {
  54. summaryEL.html(msg.summary);
  55. detailEL.html(msg.detail);
  56. }
  57. this.bindEvents(message);
  58. message.appendTo(this.jq).fadeIn();
  59. },
  60. bindEvents: function(message) {
  61. var _self = this,
  62. sticky = this.cfg.sticky;
  63. message.mouseover(function() {
  64. var msg = $(this);
  65. //visuals
  66. if(!msg.is(':animated')) {
  67. msg.find('div.ui-growl-icon-close:first').show();
  68. }
  69. })
  70. .mouseout(function() {
  71. //visuals
  72. $(this).find('div.ui-growl-icon-close:first').hide();
  73. });
  74. //remove message on click of close icon
  75. message.find('div.ui-growl-icon-close').click(function() {
  76. _self.removeMessage(message);
  77. //clear timeout if removed manually
  78. if(!sticky) {
  79. clearTimeout(message.data('timeout'));
  80. }
  81. });
  82. //hide the message after given time if not sticky
  83. if(!sticky) {
  84. this.setRemovalTimeout(message);
  85. }
  86. },
  87. removeMessage: function(message) {
  88. message.fadeTo('normal', 0, function() {
  89. message.slideUp('normal', 'easeInOutCirc', function() {
  90. message.remove();
  91. });
  92. });
  93. },
  94. setRemovalTimeout: function(message) {
  95. var _self = this;
  96. var timeout = setTimeout(function() {
  97. _self.removeMessage(message);
  98. }, this.cfg.life);
  99. message.data('timeout', timeout);
  100. }
  101. });