Add class 'active' in the menu for current page
This commit is contained in:
parent
0cc94c65a8
commit
49e2eb0187
|
@ -1,7 +1,7 @@
|
|||
module ParserCommon
|
||||
include ActionView::Helpers::TagHelper
|
||||
|
||||
def menu_level(page, current, menu, edit = false)
|
||||
def menu_level(page, current_page_id, current, menu, edit = false)
|
||||
res = ''
|
||||
if page.ordered_and_visible_children.size > 0
|
||||
res << "<ul class='"
|
||||
|
@ -10,10 +10,10 @@ module ParserCommon
|
|||
i = nil
|
||||
i = 1 if menu.values["li_incremental_#{current}"]
|
||||
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
|
||||
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
|
||||
end
|
||||
res << "</ul>"
|
||||
|
@ -21,15 +21,16 @@ module ParserCommon
|
|||
res
|
||||
end
|
||||
|
||||
def menu_li(page, current, menu, i, edit)
|
||||
res = "<li class="
|
||||
def menu_li(page, current_page_id, current, menu, i, edit)
|
||||
res = "<li class='"
|
||||
res << menu.values["li_class_#{current}"] rescue nil
|
||||
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>"
|
||||
if page.ordered_and_visible_children.size > 0 && current <= menu.levels
|
||||
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)
|
||||
res << "</li>"
|
||||
end
|
||||
|
@ -92,7 +93,7 @@ module ParserCommon
|
|||
page_menu = body.css('.page_menu').first
|
||||
home = get_homepage
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
Reference in New Issue