Module: Gritter::Helpers
- Defined in:
- lib/gritter/helpers.rb
Instance Method Summary collapse
- #add_gritter(text, *args) ⇒ Object
- #extend_gritter(*args) ⇒ Object
- #gflash(*args) ⇒ Object
- #js(*args) ⇒ Object
- #remove_gritter(*args) ⇒ Object
Instance Method Details
#add_gritter(text, *args) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gritter/helpers.rb', line 3 def add_gritter text, *args = args. [:title] = "Notification" if [:title].blank? [:image] = image_path("#{options[:image]}#{options[:image].to_s == 'progress' ? '.gif' : '.png'}") if %w(success warning error notice progress).include?([:image].to_s) notification = Array.new notification.push("jQuery(function(){") if [:nodom_wrap].blank? notification.push("jQuery.gritter.add({") notification.push("image:'#{options[:image]}',") if [:image].present? notification.push("sticky:#{options[:sticky]},") if [:sticky].present? notification.push("time:#{options[:time]},") if [:time].present? notification.push("class_name:'#{options[:class_name]}',") if [:class_name].present? notification.push("before_open:function(e){#{options[:before_open]}},") if [:before_open].present? notification.push("after_open:function(e){#{options[:after_open]}},") if [:after_open].present? notification.push("before_close:function(e){#{options[:before_close]}},") if [:before_close].present? notification.push("after_close:function(e){#{options[:after_close]}},") if [:after_close].present? notification.push("on_click:function(e){#{options[:on_click]}},") if [:on_click].present? notification.push("title:'#{escape_javascript(options[:title])}',") notification.push("text:'#{escape_javascript(text)}'") notification.push("});") notification.push("});") if [:nodom_wrap].blank? text.present? ? notification.join.html_safe : nil end |
#extend_gritter(*args) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gritter/helpers.rb', line 35 def extend_gritter *args = args. [:fade_in_speed] = "'#{options[:fade_in_speed]}'" if [:fade_in_speed].is_a?(String) [:fade_out_speed] = "'#{options[:fade_out_speed]}'" if [:fade_out_speed].is_a?(String) [:position] = "'#{options[:position].to_s.gsub("_", "-")}'" if [:position] extended = ["jQuery.extend($.gritter.options,{"] extended.push("fade_in_speed:#{options[:fade_in_speed]},") if [:fade_in_speed].present? extended.push("fade_out_speed:#{options[:fade_out_speed]},") if [:fade_out_speed].present? extended.push("time:#{options[:time]},") if [:time].present? extended.push("position:#{options[:position]}") if [:position].present? extended.push("});") extended.join.html_safe end |
#gflash(*args) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/gritter/helpers.rb', line 49 def gflash *args if session[:gflash].present? = args. nodom_wrap = [:nodom_wrap] .delete(:nodom_wrap) titles = gflash_titles() flashes = [] session[:gflash].each do |key, value| key = key.to_sym value.each do |gflash_value| = { :image => key, :title => titles[key], :nodom_wrap => nodom_wrap } if gflash_value.is_a?(Hash) text = gflash_value.has_key?(:value) ? (gflash_value[:value] and gflash_value.delete(:value)) : nil .merge!(gflash_value) else text = gflash_value end flashes.push(add_gritter(text, )) end end session[:gflash] = nil [:js] ? flashes.join("\n") : js(flashes).html_safe end end |
#js(*args) ⇒ Object
75 76 77 |
# File 'lib/gritter/helpers.rb', line 75 def js *args javascript_tag(args.join("\n")) end |
#remove_gritter(*args) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/gritter/helpers.rb', line 26 def remove_gritter *args = args. removed = ["jQuery.gritter.removeAll({"] removed.push("before_close:function(e){#{options[:before_close]}},") if [:before_close].present? removed.push("after_close:function(e){#{options[:after_close]}},") if [:after_close].present? removed.push("});") removed.join.html_safe end |