Add class 'active' in the menu for current page
This commit is contained in:
parent
0cc94c65a8
commit
49e2eb0187
|
@ -1,7 +1,7 @@
|
||||||
module ParserCommon
|
module ParserCommon
|
||||||
include ActionView::Helpers::TagHelper
|
include ActionView::Helpers::TagHelper
|
||||||
|
|
||||||
def menu_level(page, current, menu, edit = false)
|
def menu_level(page, current_page_id, current, menu, edit = false)
|
||||||
res = ''
|
res = ''
|
||||||
if page.ordered_and_visible_children.size > 0
|
if page.ordered_and_visible_children.size > 0
|
||||||
res << "<ul class='"
|
res << "<ul class='"
|
||||||
|
@ -10,10 +10,10 @@ module ParserCommon
|
||||||
i = nil
|
i = nil
|
||||||
i = 1 if menu.values["li_incremental_#{current}"]
|
i = 1 if menu.values["li_incremental_#{current}"]
|
||||||
if menu.values['home'] && current == 1
|
if menu.values['home'] && current == 1
|
||||||
res << menu_li(page, current, menu, i, edit)
|
res << menu_li(page, current_page_id, current, menu, i, edit)
|
||||||
end
|
end
|
||||||
page.ordered_and_visible_children.each do |child|
|
page.ordered_and_visible_children.each do |child|
|
||||||
res << menu_li(child, current, menu, i, edit)
|
res << menu_li(child, current_page_id, current, menu, i, edit)
|
||||||
i += 1 if i
|
i += 1 if i
|
||||||
end
|
end
|
||||||
res << "</ul>"
|
res << "</ul>"
|
||||||
|
@ -21,15 +21,16 @@ module ParserCommon
|
||||||
res
|
res
|
||||||
end
|
end
|
||||||
|
|
||||||
def menu_li(page, current, menu, i, edit)
|
def menu_li(page, current_page_id, current, menu, i, edit)
|
||||||
res = "<li class="
|
res = "<li class='"
|
||||||
res << menu.values["li_class_#{current}"] rescue nil
|
res << menu.values["li_class_#{current}"] rescue nil
|
||||||
res << "_#{i}" if i
|
res << "_#{i}" if i
|
||||||
res << ">"
|
res << " active" if page.id.eql?(current_page_id)
|
||||||
|
res << "'>"
|
||||||
res << "<a href='#{edit ? admin_page_path(page.id) : page.full_name}'><span>#{page.i18n_variable[I18n.locale]}</span></a>"
|
res << "<a href='#{edit ? admin_page_path(page.id) : page.full_name}'><span>#{page.i18n_variable[I18n.locale]}</span></a>"
|
||||||
if page.ordered_and_visible_children.size > 0 && current <= menu.levels
|
if page.ordered_and_visible_children.size > 0 && current <= menu.levels
|
||||||
res << "<span class='dot'></span>"
|
res << "<span class='dot'></span>"
|
||||||
res << menu_level(page, current + 1, menu, edit)
|
res << menu_level(page, current_page_id, current + 1, menu, edit)
|
||||||
end unless (page.is_home? rescue nil)
|
end unless (page.is_home? rescue nil)
|
||||||
res << "</li>"
|
res << "</li>"
|
||||||
end
|
end
|
||||||
|
@ -92,7 +93,7 @@ module ParserCommon
|
||||||
page_menu = body.css('.page_menu').first
|
page_menu = body.css('.page_menu').first
|
||||||
home = get_homepage
|
home = get_homepage
|
||||||
menu = page.design.layout.menu
|
menu = page.design.layout.menu
|
||||||
fragment = Nokogiri::HTML::DocumentFragment.new(body, menu_level(home, 1, menu, edit))
|
fragment = Nokogiri::HTML::DocumentFragment.new(body, menu_level(home, page.id, 1, menu, edit))
|
||||||
page_menu.swap(fragment)
|
page_menu.swap(fragment)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue