1

我在 Rails 5 应用程序中使用Gritter通知,但找不到删除通知弹出窗口默认标题的方法。我将 Gritter 添加如下:

<%= js add_gritter(flash[:notice], title: 'I dont need you', sticky: false) %>

试过:

<%= js add_gritter(flash[:notice], title: false, sticky: false) %>
<%= js add_gritter(flash[:notice], title: nil, sticky: false) %>
<%= js add_gritter(flash[:notice], title: '', sticky: false) %>
<%= js add_gritter(flash[:notice], title: ' ', sticky: false) %>

并且仍然弹出默认标题 - “通知”。尝试在整个应用的项目“Notification”或“gritter”中搜索,但没有找到相关的。

如何摆脱它?

4

2 回答 2

1

如果返回 true add_gritter,gem 中的方法将设置options[:title]为“通知” 。options[:title].blank?

"dirty" 选项是再次定义它,使用选项哈希代替*args,如果它作为选项参数传递,则呈现标题,例如:

def add_gritter(text, options={})
  if %w(success warning error notice progress).include?(options[:image].to_s)
    options[:image] = image_path("#{options[:image]}#{options[:image].to_s == 'progress' ? '.gif' : '.png'}") 
  end
  notification = Array.new
  notification.push("jQuery(function(){") if options[:nodom_wrap].blank?
  notification.push("jQuery.gritter.add({")
  notification.push("image:'#{options[:image]}',") if options[:image].present?
  notification.push("sticky:#{options[:sticky]},") if options[:sticky].present?
  notification.push("time:#{options[:time]},") if options[:time].present?
  notification.push("class_name:'#{options[:class_name]}',") if options[:class_name].present?
  notification.push("before_open:function(e){#{options[:before_open]}},") if options[:before_open].present?
  notification.push("after_open:function(e){#{options[:after_open]}},") if options[:after_open].present?
  notification.push("before_close:function(e){#{options[:before_close]}},") if options[:before_close].present?
  notification.push("after_close:function(e){#{options[:after_close]}},") if options[:after_close].present?
  notification.push("on_click:function(e){#{options[:on_click]}},") if options[:on_click].present?
  notification.push("title:'#{escape_javascript(options[:title])}',") if options[:title].blank? # Here
  notification.push("text:'#{escape_javascript(text)}'")
  notification.push("});")
  notification.push("});") if options[:nodom_wrap].blank?
  text.present? ? notification.join.html_safe : nil
end

但是 gritt.js 文件有一个if检查是否title有任何内容,所以你应该自己处理并编辑它,只是为了检查文本,比如:

//We might have some issues if we don't have a title or text!
if (!params.text) {
  throw 'You need to fill out the text parameter.';
}
于 2017-10-13T15:35:33.360 回答
1

听起来不是最好的方法,但有效。如果有任何其他解决方案 - 请随意:)

.gritter-title {
  display: none;
}

编辑:

由于我使用 SCSS,这更好:

<%= js add_gritter(flash[:notice], sticky: false, :on_click => remove_gritter, :time => 100000, class_name: 'no-title') %>
.no-title {
  .gritter-title {    
      display: none;
  }
}
于 2017-10-13T14:54:43.257 回答