开发者

Semantic-Menu root bahaviour

require 'rubygems'
require 'action_view'
require 'active_support'

class MenuItem
  include ActionView::Helpers::TagHelper,
          ActionView::Helpers::UrlHelper

  attr_accessor :children, :link
  cattr_accessor :request

  def initialize(title, link, level, link_opts={})
    @title, @link, @level, @link_opts = title, link, level, link_opts
    @children = []
  end

  def add(title, link, link_opts={}, &block)
    returning(MenuItem.new(title, link, @level +1, link_opts)) do |adding|
      @children << adding
      yield adding if block_given?
    end
  end

  def to_s
    content_tag(:li, content_tag(:div, link_to(@title, @link, @link_opts), :class => "menu_header_level_"+@level.to_s) + child_output, ({:class => 'active'} if active?)).html_safe
  end

  def level_class
    "menu_level_#{@level}"
  end

  def child_output
    children.empty? ? '' : content_tag(:ul, @children.collect(&:to_s).join.html_safe, :class => level_class)
  end

  def active?
    children.any?(&:active?) || on_current_page?
  end

  def on_current_page?
    # set it for current_page? defined in UrlHelper
    # current_page?(@link)
    false
  end

  # def request
  #     @@request
  #   end
end

class SemanticMenu < MenuItem

  def initialize(rq, opts={},&block)
    @@request   = rq
    @opts       = {:class => 'menu'}.merge opts
    @level      = 0
    @children   = []
    yield self if block_given?
  end

  def to_s
    content_tag(:ul, @children.collect(&:to_s).join.html_safe, @opts).html_safe
  end
end

Hello. I am trying to change the behaviour of the Semantic-Menu root. When I click one of the roots, the menu drops down and displays all the children. What I woul开发者_StackOverflow社区d like is happen is when I click, it goes to a default page and then display the children. Semantic-menu seems to allow links only to lower levels and not the main ones. Roots links only work when they don't have children.

The code below is the one that is in the plug-in in Ruby. and I think is the one that needs to be modified. There the html code but I don't think it has to do with it.

Can you please tell me what need to be added in other to make to father trigger their links?

Thank you.


I don't know the direct answer to your question, but SemanticMenu seems outdated.

Check out the SimpleNavigation gem: https://github.com/andi/simple-navigation/wiki

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜