我一直在寻找相同的功能(将咆哮设置为从特定的消息严重性发出粘性)。PrimeFaces (6.1) 不提供此功能,但很容易破解咆哮的 JavaScript。更具体地说,在bindEvents
他们检查是否sticky
已配置并基于此的功能中:
//hide the message after given time if not sticky
if(!sticky) {
this.setRemovalTimeout(message);
}
因此,您可以根据消息严重性对函数进行原型(覆盖)bindEvents
和设置。sticky
PrimeFaces.widget.Growl.prototype.bindEvents = function(message) {
var _self = this,
sticky = this.cfg.sticky;
// Start hack
if (!sticky) {
// Your rule
}
...
您还可以原型renderMessage
化并将严重性作为参数添加到bindEvents
. 我选择使用快速破解并从className
.
我添加了这些实用功能:
var SEVERITIES = [ "info", "warn", "error", "fatal" ];
function getSeverity(domNode) {
// HACK Severity can be found in the className after the last - character.
var severity = domNode.className;
return severity.substring(severity.lastIndexOf("-") + 1);
}
function getSeverityIndex(severityString) {
return SEVERITIES.indexOf(severityString);
}
现在您可以使用以下检查:
if (!sticky) {
sticky = getSeverityIndex(getSeverity(message[0])) >= getSeverityIndex("error");
}
stickSeverity
我可能会在 GitHub 上创建一个拉取请求,您可以在其中使用组件上的属性设置最小严重性以粘贴按摩p:growl
。
这是完整的 JavaScript hack(PrimeFaces 6.1):
var SEVERITIES = [ "info", "warn", "error", "fatal" ];
function getSeverity(domNode) {
// HACK Severity can be found in the className after the last - character.
var severity = domNode.className;
return severity.substring(severity.lastIndexOf("-") + 1);
}
function getSeverityIndex(severityString) {
return SEVERITIES.indexOf(severityString);
}
PrimeFaces.widget.Growl.prototype.bindEvents = function(message) {
var _self = this,
sticky = this.cfg.sticky;
// Start customization
if (!sticky) {
sticky = getSeverityIndex(getSeverity(message[0])) >= getSeverityIndex("error");
}
// End customization
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);
}
}