2017-10-13 2 views
1

Ich verwende Gritter Benachrichtigungen in der Rails 5 App und kann keinen Weg finden, den Standardtitel des Benachrichtigungs-Popups zu entfernen. Ich füge Gritter als Gebrüll:Rails, Gritter - Standardtitel entfernen

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

Versuchte:

<%= 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) %> 

Und noch Popup erscheint mit dem Standardtitel - "Benachrichtigung". Versucht, im gesamten App-Projekt "Benachrichtigung" oder "Streuner" zu suchen, aber nichts wurde gefunden.

Wie man es loswerden?

Antwort

1

Die add_gritter Methode im Juwel der options[:title] setzt als " Benachrichtigung "wenn options[:title].blank? True zurückgibt.

Die „schmutzige“ Option ist es wieder zu definieren, mit einem Hash von Optionen statt *args, und um den Titel zu machen, wenn es als Option Argument übergeben wurde, wie:

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 

Aber der Streuer. js Datei hat ein if zu prüfen, ob die title Inhalte hat, so sollten Sie mit Ihrem eigenen zu tun haben und bearbeiten, nur für den Text zu überprüfen, wie:

//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.'; 
} 
1

Klingt nicht wie ein bester Weg, aber funktioniert. Wenn alle anderen Lösungen - bitte frei :)

.gritter-title { 
    display: none; 
} 

bearbeiten fühlen:

Da ich SCSS verwenden, das ist besser:

<%= js add_gritter(flash[:notice], sticky: false, :on_click => remove_gritter, :time => 100000, class_name: 'no-title') %> 
.no-title { 
    .gritter-title {  
     display: none; 
    } 
} 
Verwandte Themen