@@ -3,16 +3,20 @@ module Renderer
3
3
class Bootstrap < SimpleNavigation ::Renderer ::Base
4
4
def render ( item_container )
5
5
return '' if respond_to? ( :skip_if_empty? ) && skip_if_empty? && item_container . empty?
6
+
6
7
config_selected_class = SimpleNavigation . config . selected_class
7
8
SimpleNavigation . config . selected_class = 'active'
9
+
8
10
list_content = item_container . items . inject ( [ ] ) do |list , item |
11
+
9
12
li_options = item . html_options . reject { |k , v | k == :link }
10
13
icon = li_options . delete ( :icon )
11
14
dropdown = item_container . dropdown . nil? ? true : item_container . dropdown
12
15
split = item_container . split
13
16
split = ( include_sub_navigation? ( item ) and li_options . delete ( :split ) ) if li_options . include? ( :split )
14
17
dropdown = ( include_sub_navigation? ( item ) and li_options . delete ( :dropdown ) ) if li_options . include? ( :dropdown )
15
18
li_content = tag_for ( item , item . name , icon , split , dropdown )
19
+
16
20
if include_sub_navigation? ( item )
17
21
if split
18
22
lio = li_options . dup
@@ -22,47 +26,65 @@ def render(item_container)
22
26
li_options [ :id ] = nil
23
27
li_content = tag_for ( item )
24
28
end
29
+
25
30
item . sub_navigation . dom_class = [ item . sub_navigation . dom_class , dropdown ? 'dropdown-menu' : nil , split ? 'pull-right' : nil ] . flatten . compact . join ( ' ' )
26
31
li_content << render_sub_navigation_for ( item )
27
32
li_options [ :class ] = [ li_options [ :class ] , dropdown ? 'dropdown' : nil , split ? 'dropdown-split-right' : nil ] . flatten . compact . join ( ' ' )
28
33
end
34
+
29
35
list << content_tag ( :li , li_content , li_options )
30
36
end . join
37
+
31
38
SimpleNavigation . config . selected_class = config_selected_class
39
+
32
40
if item_container . respond_to? ( :dom_attributes )
33
41
dom_attributes = item_container . dom_attributes
34
42
else
35
43
# supports simple-navigation before the ItemContainer#dom_attributes
36
44
dom_attributes = { :id => item_container . dom_id , :class => item_container . dom_class }
37
45
end
46
+
38
47
content_tag ( :ul , list_content , dom_attributes )
39
48
end
40
49
41
50
protected
42
51
43
52
def tag_for ( item , name = '' , icon = nil , split = false , dropdown = false )
44
- unless item . url or include_sub_navigation? ( item )
53
+ include_sub_nav = include_sub_navigation? ( item )
54
+
55
+ unless item . url or include_sub_nav
45
56
return item . name
46
57
end
58
+
47
59
url = item . url
48
60
link = Array . new
49
61
link << content_tag ( :i , '' , :class => [ icon ] . flatten . compact . join ( ' ' ) ) unless icon . nil?
50
62
link << name
51
- if include_sub_navigation? ( item )
63
+
64
+ if include_sub_nav
52
65
item_options = item . html_options
53
66
item_options [ :link ] = Hash . new if item_options [ :link ] . nil?
54
67
item_options [ :link ] [ :class ] = Array . new if item_options [ :link ] [ :class ] . nil?
68
+
55
69
unless split
56
70
if dropdown
57
71
item_options [ :link ] [ :class ] << 'dropdown-toggle'
58
72
item_options [ :link ] [ :'data-toggle' ] = 'dropdown'
59
- item_options [ :link ] [ :'data-target' ] = '#'
73
+ item_options [ :link ] [ :type ] = 'button'
74
+ item_options [ :link ] [ :'aria-haspopup' ] = true
75
+ item_options [ :link ] [ :'aria-expanded' ] = false
60
76
end
61
77
link << content_tag ( :b , '' , :class => 'caret' )
62
78
end
79
+
63
80
item . html_options = item_options
64
81
end
65
- link_to ( link . join ( " " ) . html_safe , url , options_for ( item ) )
82
+
83
+ if include_sub_nav && dropdown
84
+ content_tag ( :button , link . join ( " " ) . html_safe , options_for ( item ) )
85
+ else
86
+ link_to ( link . join ( " " ) . html_safe , url , options_for ( item ) )
87
+ end
66
88
end
67
89
68
90
end
0 commit comments