/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
- /**
- * PrimeFaces Growl Widget
- */
- PrimeFaces.widget.Growl = PrimeFaces.widget.BaseWidget.extend({
-
- init: function(cfg) {
- this.cfg = cfg;
- this.id = this.cfg.id
- this.jqId = PrimeFaces.escapeClientId(this.id);
- this.render();
-
- this.removeScriptElement(this.id);
- },
-
- //Override
- refresh: function(cfg) {
- this.cfg = cfg;
- this.show(cfg.msgs);
-
- this.removeScriptElement(this.id);
- },
-
- show: function(msgs) {
- var _self = this;
-
- this.jq.css('z-index', ++PrimeFaces.zindex);
- //clear previous messages
- this.removeAll();
- $.each(msgs, function(index, msg) {
- _self.renderMessage(msg);
- });
- },
-
- removeAll: function() {
- this.jq.children('div.ui-growl-item-container').remove();
- },
-
- render: function() {
- //create container
- this.jq = $('<div id="' + this.id + '_container" class="ui-growl ui-widget"></div>');
- this.jq.appendTo($(document.body));
- //render messages
- this.show(this.cfg.msgs);
- },
-
- renderMessage: function(msg) {
- var markup = '<div class="ui-growl-item-container ui-state-highlight ui-corner-all ui-helper-hidden ui-shadow" aria-live="polite">';
- markup += '<div class="ui-growl-item">';
- markup += '<div class="ui-growl-icon-close ui-icon ui-icon-closethick" style="display:none"></div>';
- markup += '<span class="ui-growl-image ui-growl-image-' + msg.severity + '" />';
- markup += '<div class="ui-growl-message">';
- markup += '<span class="ui-growl-title"></span>';
- markup += '<p></p>';
- markup += '</div><div style="clear: both;"></div></div></div>';
- var message = $(markup),
- summaryEL = message.find('span.ui-growl-title'),
- detailEL = summaryEL.next();
-
- if(this.cfg.escape) {
- summaryEL.text(msg.summary);
- detailEL.text(msg.detail);
- }
- else {
- summaryEL.html(msg.summary);
- detailEL.html(msg.detail);
- }
- this.bindEvents(message);
- message.appendTo(this.jq).fadeIn();
- },
-
- bindEvents: function(message) {
- var _self = this,
- sticky = this.cfg.sticky;
- message.mouseover(function() {
- var msg = $(this);
- //visuals
- if(!msg.is(':animated')) {
- msg.find('div.ui-growl-icon-close:first').show();
- }
- })
- .mouseout(function() {
- //visuals
- $(this).find('div.ui-growl-icon-close:first').hide();
- });
- //remove message on click of close icon
- message.find('div.ui-growl-icon-close').click(function() {
- _self.removeMessage(message);
- //clear timeout if removed manually
- if(!sticky) {
- clearTimeout(message.data('timeout'));
- }
- });
- //hide the message after given time if not sticky
- if(!sticky) {
- this.setRemovalTimeout(message);
- }
- },
-
- removeMessage: function(message) {
- message.fadeTo('normal', 0, function() {
- message.slideUp('normal', 'easeInOutCirc', function() {
- message.remove();
- });
- });
- },
-
- setRemovalTimeout: function(message) {
- var _self = this;
- var timeout = setTimeout(function() {
- _self.removeMessage(message);
- }, this.cfg.life);
- message.data('timeout', timeout);
- }
- });