Module: BarItemHelper

Defined in:
app/helpers/bar_item_helper.rb

Instance Method Summary collapse

Instance Method Details

#f7_bar_item(title_or_options, options = nil, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/helpers/bar_item_helper.rb', line 3

def f7_bar_item(title_or_options, options=nil, &block)
  output = []
  if title_or_options.class == Hash
    options = title_or_options
    title = options[:title]
  else
    title = title_or_options
    options ||= {}
    options[:title] = title
  end

  position = (options[:position] || :left) unless @f7_bartype == :tabbar
  transition = options[:tansition]

  css_classes = []
  css_classes << position
  css_classes << [transition].flatten if options[:transition]
  options[:class] = ([options[:class]] || []) + css_classes

  html_options = options.reject { |k, v| [:position, :title].include? k }

  if block_given?
    output << capture(&block)
  else
    if options[:href]
      link_options =  options.select { |k, v| [:title, :href, :icon, :badge].include? k.to_sym }
      output << f7_bar_link(link_options)
    else
      output << title
    end
  end

  if @f7_bartype == :tabbar
    output.join("\n").html_safe
  else
     :div, :class => css_classes do
      output.join("\n").html_safe
    end
  end
end


44
45
46
47
48
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/helpers/bar_item_helper.rb', line 44

def f7_bar_link(title_or_options, options=nil)
  output = []
  link_classes = []

  if title_or_options.class == Hash
    options = title_or_options
    title = options[:title]
  else
    title = title_or_options
    options ||= {}
  end

  href = options[:href] || '#'
  icon = options[:icon]

  if @f7_bartype == :tabbar
    link_classes << 'tab-link'
  else
    link_classes << :link
  end

  link_classes << 'icon-only' if title.blank? 
  options[:class] = ([options[:class]] || []) + link_classes

  link_attr = options.reject { |k, v| [:title, :icon, :badge].include? k }

  span_class = (@f7_bartype == :tabbar ? {:class => 'tabbar-label'} : nil)

  if icon.blank?
     :a, title, link_attr
  else
    badge = nil
    link_options = {}
    if @f7_bartype == :tabbar
      if options[:badge].kind_of? Hash
        badge_data = options[:badge]
        badge_classes = [:badge]
        badge_classes << badge_data[:class] unless badge_data[:class].blank?
        badge =  :span, badge_data[:text], :class => badge_classes
      else
        badge =  :span, options[:badge], :class => [:badge, 'badge-red']
      end
      link = link_icon_i(options[:icon], badge)
    end
    puts " has labels: #{@has_labels ? 'true' : 'false'}"
     :a, :href => href, :class => link_classes do
      output << link_icon_i(options[:icon], badge)
      output << (:span, title, span_class) if !title.blank? && @has_labels
      output.join("\n").html_safe
    end
  end
end