1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to add navtab with id to add-on

Discussion in 'XenForo Development Discussions' started by Dadparvar, Apr 6, 2016.

  1. Dadparvar

    Dadparvar Well-Known Member

    Hi,

    My add-on has a push menu, that when you click on something with "baseexpand" id, menu comes out.

    I added this tab to navigation:
    Code:
    <li style="cursor: pointer" id="baseexpand" class="navTab PopupClosed"><a class="navLink">TAB LABEL</a></li>
    And it works.

    But I want to add it using code event listener. This is my php code:
    Code:
    $extraTabs['baseexpand'] = array(
                'title' => 'Push Menu',
                'href' => XenForo_Link::buildPublicLink('#XenForo'),
                'selected' => ($selectedTabId == 'baseexpand'),
                'linksTemplate' => 'dad_pushmenu_Navtabs',
          'position' => 'end'
            );
    It adds the navtab, but when I click on it, push menu doesn't come out.

    Any opinion on how to reach that goal will be appreciated
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    Each tab automatically has a unique class name, in your case it will be "baseexpand".

    Assuming that you have some JS code somewhere that is doing something like this:
    Code:
    $('#baseexpand').something();
    You'd just need to update it so it looks like this:
    Code:
    $('.navTab.baseexpand').something();
     
    Dadparvar likes this.
  3. Dadparvar

    Dadparvar Well-Known Member

    it works.
    But there is a problem.
    when I click on it, although push menu starts coming out, but the page also starts reloading. Because that tab behaves like a link. How to disable such functionality?
     
  4. Dadparvar

    Dadparvar Well-Known Member

    I mean, now the created navtab is like this:
    Code:
    <a href="index.php?/" class="navLink">Push Menu</a>
    So that when I click it, it load the page.
    If it was like this:
    Code:
    <a  class="navLink">Push Menu</a>
    Menu would working fine.
    Or in any way, the link doesn't load the page and just be clicked.
     
  5. Chris D

    Chris D XenForo Developer Staff Member

    Set the href to "javascript:"
     
  6. Dadparvar

    Dadparvar Well-Known Member

    Weird!
    I set it to :
    Code:
    'href' => XenForo_Link::buildPublicLink('javascript:'),
    But when I click it, it goes to:
    Code:
    http://localhost/xenforo/index.php?javascript:/
    and so:
    Code:
    Route javascript:/ could not be found.
     
  7. Chris D

    Chris D XenForo Developer Staff Member

    No. Just "javascript:". Don't run it through the link builder.
     
    Dadparvar likes this.
  8. Dadparvar

    Dadparvar Well-Known Member

    Awesome.
    Exactly what I needed.
    Thanks
     

Share This Page