From a13b509193f1257e3a474f0745b362f8ad763ebf Mon Sep 17 00:00:00 2001 From: chiu Date: Tue, 21 Jan 2020 17:37:25 +0800 Subject: [PATCH] let user can choose to expand next layer --- .../site_menu_widgets_controller.rb | 33 ++++++++++++------- config/locales/en.yml | 1 + config/locales/zh_tw.yml | 1 + lib/site_menu_widget/engine.rb | 3 ++ 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/app/controllers/site_menu_widgets_controller.rb b/app/controllers/site_menu_widgets_controller.rb index 2f0c385..471ae6b 100644 --- a/app/controllers/site_menu_widgets_controller.rb +++ b/app/controllers/site_menu_widgets_controller.rb @@ -35,9 +35,9 @@ class SiteMenuWidgetsController < ApplicationController #item = [] @count += 1 if (!item1["children"].nil? && item1["children"].length!=0) - @li_index << @count - if children_is_current(item1['obj']) - @ul_index << ( @li_index.length - 1 ) + @count1 += 1 + if (@expand_current_layer && children_is_current(item1['obj'])) || (@expand_next_layer && item1['obj'].id == @page_id) + @ul_index << [@count1, @count] end create_menu_bool_object(item1['children']) #item = [children_is_current(item1['obj']),item1['obj'].id==@page_id,create_menu_bool_object(item1['children'])] @@ -57,6 +57,8 @@ class SiteMenuWidgetsController < ApplicationController page = Page.where(:page_id => params[:page_id]).first @page_id = page.id @expand_layer = false + @expand_next_layer = false + @expand_current_layer = false if page.parent_page == Page.root @pages = page.sorted_published_child_pages else @@ -80,25 +82,32 @@ class SiteMenuWidgetsController < ApplicationController value = YAML.load(select_option.value) if value[I18n.locale] == t('site_menu.yes') @expand_layer = true + @expand_current_layer = true + end + elsif !(@show_options.nil?) && select_option.field_name == @show_options.keys[2].to_s + value = YAML.load(select_option.value) + if value[I18n.locale] == t('site_menu.yes') + @expand_layer = true + @expand_next_layer = true end end end end end @ul_index=[] - @li_index= [] @count = -1 + @count1 = 0 + @li_index = [] title = subpart.title items = create_json(@pages) - create_menu_bool_object(items) - if @expand_layer + if @expand_layer + create_menu_bool_object(items) temp = @ul_index.reverse.collect do |ul_index| - tp = @li_index[ul_index] + 1 - "var ul_tp = $('div[data-subpart-id=#{subpart.id}]').find('ul').eq(#{tp}) - ul_tp.removeClass('dropdown-menu') - $('div[data-subpart-id=#{subpart.id}]').find('li').eq(#{@li_index[ul_index]}).find('span').eq(0).remove() - " - end + "var ul_tp = $('div[data-subpart-id=#{subpart.id}]').find('ul').eq(#{ul_index[0]}) + ul_tp.removeClass('dropdown-menu') + $('div[data-subpart-id=#{subpart.id}]').find('li').eq(#{ul_index[1]}).find('span').eq(0).remove() + " + end if temp.length != 0 temp = temp.join(' ') expand_script = "