Giter VIP home page Giter VIP logo

Comments (30)

joelion avatar joelion commented on May 25, 2024 5

I would like the exact same functionality. When I click an expanding-menu, I want the menu to expand also to be redirecting to a page. In some cases, I would like to make sublinks like @adi10ain is doing. In other cases, I would like something like the following, where when I click the top-level menu item, it takes me to to the top of the page "link.html", and the sub-menu items provide links to bookmarks elsewhere on link.html

<li>
    <a href="link.html">Parent item <span class="glyphicon arrow"></span></a>
    <ul>
        <li><a href="link.html#item2.1">item 2.1</a></li>
        <li><a href="link.html#item2.2">item 2.2</a></li>
    </ul>
</li>

from metismenu.

joelion avatar joelion commented on May 25, 2024 3

I found a kind of work-around. How easy this is depends on what engine you're using to create your site. I'm using Flask, so it's pretty easy with blocks. On your main page (page1.html), you just include a link to the other page (page2.html) in the menu, with no sub-menu options. Then on the page2.html, include the sub-menus in the menu definition

page1.html

<li>
    <a href="page2.html">Parent item <span class="glyphicon arrow"></span></a>
</li>

page2.html

<li>
    <a href="page2.html">Parent item <span class="glyphicon arrow"></span></a>
    <ul>
        <li><a href="page2.html#item2.1">item 2.1</a></li>
        <li><a href="page2.html#item2.2">item 2.2</a></li>
    </ul>
</li>

from metismenu.

eye-too avatar eye-too commented on May 25, 2024 2

I've been experimenting trying to separate page link and toggle submenu items in a separate a-tag. This is my latest version: http://codepen.io/eye-wonder/pen/VpqQad

from metismenu.

longnd avatar longnd commented on May 25, 2024 1

Hi @onokumus
I think it's not good for user experience. The user could not know that he has to "double click" on the menu to go - it's not a common practice on a website.
The better way is:

  • the menu is opened when click on <span class="glyphicon arrow"></span></a>
  • the parent is opened when click on "Parent item" link

from metismenu.

RatkoKovacevic avatar RatkoKovacevic commented on May 25, 2024 1

The easiest way is to set the a tag in css as display: block it works for me.

from metismenu.

onokumus avatar onokumus commented on May 25, 2024

is <a> tag inside of the <li> tag? If not, it does not work.

from metismenu.

chasegiunta avatar chasegiunta commented on May 25, 2024

Apologies, I was referencing the wrong tag, I've edited my question. Is it possible to add a clickable link to the parent <li> tag that will expand the children list and navigate to the linked page?

from metismenu.

chasegiunta avatar chasegiunta commented on May 25, 2024
<li>
  <a href="http://www.site.com/parent">Parent Page <span class="fa arrow"></span></a>
  <ul>
    <li><a href="http://www.site.com/parent/child1">Child Page</a></li>
    <li><a href="http://www.site.com/parent/child2">Child Page</a></li>
    <li><a href="http://www.site.com/parent/child3">Child Page</a></li>
    <li><a href="http://www.site.com/parent/child4">Child Page</a></li>
  </ul>
</li>

from metismenu.

chasegiunta avatar chasegiunta commented on May 25, 2024

@onokumus do you understand what I'm trying to accomplish? I'd really love to use metismenu! Is it possible for the parent to link to a page or hash (www.site.com/current/page#section45) and expand the children?

from metismenu.

onokumus avatar onokumus commented on May 25, 2024

@chasegiunta
Please see following links.
http://www.w3schools.com/jsref/prop_loc_hash.asp
https://developer.mozilla.org/en-US/docs/Web/API/URLUtils.hash

See sample pages
https://gist.github.com/onokumus/224181ad4627b709cdc0

from metismenu.

adi10ain avatar adi10ain commented on May 25, 2024

I am wondering about the same thing but you didn't provide any real answer. Right now a parent item will only expand/collapse. I want it to redirect me as well.

For example:

<li>
    <a href="link.html">Parent item <span class="glyphicon arrow"></span></a>
    <ul>
        <li><a href="sublink1.html">item 2.1</a></li>
        <li><a href="sublink2">item 2.2</a></li>
    </ul>
</li>

when I press "Parent item" it only expands/collapses, it does not take me to link.html. How can I achieve this?

Thanks in advance!

from metismenu.

nnyamekye avatar nnyamekye commented on May 25, 2024

ridiculous no answer to the question from the owner that's sad.

from metismenu.

indaduke avatar indaduke commented on May 25, 2024

any updates on this? I need this feature also.

from metismenu.

onokumus avatar onokumus commented on May 25, 2024

@indaduke, @longnd, @nnyamekye, @chasegiunta, @joelion
Hi,
Sorry for the belated answer.
First take a look at https://github.com/onokumus/metisMenu#doubletaptogo

For example .

<ul class="metismenu">
 <li>
    <a href="link.html">Parent item <span class="glyphicon arrow"></span></a>
    <ul>
        <li><a href="sublink1.html">item 2.1</a></li>
        <li><a href="sublink2">item 2.2</a></li>
    </ul>
 </li>
</ul>

<script>
$('.metismenu').metisMenu({
 doubleTapToGo: true
});

When "Parent item" link is once clicked the menu will open and when you click it for the second time, "link.html" page will be opened.

from metismenu.

chasegiunta avatar chasegiunta commented on May 25, 2024

This depends on how you have your site set up, but obviously if navigating causes a page reload, it won't matter if the parent item is expanded to reveal children, because metisMenu is not smart enough to reveal children on the new page.

A way to remedy this, would be an option in metisMenu to detect query parameters and expand the correlating parent node(s).

from metismenu.

LorenDorez avatar LorenDorez commented on May 25, 2024

The issue is that a link can only truly do one task either navigate or expand. This could be accomplished but you would have to move the Expand Collapse Icon outside the link tag. This can create other issue in styling as well.

Something like this might work with some special css styling (class mm-toggler) for the icon like floating right etc...

<ul class="metismenu">
 <li>
    <span class="glyphicon arrow mm-toggler"></span>
    <a href="link.html">Parent item</a>
    <ul>
        <li><a href="sublink1.html">item 2.1</a></li>
        <li><a href="sublink2">item 2.2</a></li>
    </ul>
 </li>
</ul>

If you add cookie support for tracking the menu state then you would have a feasible work around for this by navigating to the page from the parent link and expanding the children sub-menu onload.

See this issue for a cookie support #5

from metismenu.

killaman808 avatar killaman808 commented on May 25, 2024

You could achieve this by commenting out the line in jquery.metismenu.js that has e.preventdefault. You would also need to track which li item was clicked so that upon loading the new page, you would be able to expand navigation to the right place. You could achieve this in several ways. One mentioned was through a cookie. I preferred setting an id for the li items and appending that id to a url variable so that it could easily be pulled on the loading page. This was a dynamic nav so I just stored the navid in the db with the display and url values and it was super easy.

HTH

from metismenu.

ziedmahdi avatar ziedmahdi commented on May 25, 2024

@onokumus
your doubleTapToGo: true cause the page to reload which is bad for single page applications.

from metismenu.

ziedmahdi avatar ziedmahdi commented on May 25, 2024

I got a workaround by adding preventDefault: false and when I want to prevent the default action, I just add a .prevent-default to the element with the event handler.

$('.prevent-default').on('click', function (event) {
   event.preventDefault();
});

from metismenu.

onokumus avatar onokumus commented on May 25, 2024

@ziedmahdi

The doubleTapToGo option will be deprecated in the next release.

https://github.com/onokumus/metisMenu#doubletaptogo

from metismenu.

PeterGhimself avatar PeterGhimself commented on May 25, 2024

I found a work around in vanilla js.

What I did was bind click event listeners to those parent li elements (that were already behaving as drop down menus), then in the corresponding handler functions I used assignments to window.location.href to navigate to the desired page.

sample of html

<li class="dropdown spacecraft-btn-js">
    <a href="spacecraft.html" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspop="true" aria-expanded="false">
        Spacecraft Division<span class="caret"></span>
    </a>
    <ul class="dropdown-menu">
        <li><a href="consat-1.html">ConSat-1</a></li>
        <li><a href="aleksandr.html">Aleksandr</a></li>
        <li><a href="groundsegment.html">Ground Station</a></li>
    </ul>
</li>

sample of js

document.addEventListener("DOMContentLoaded", function() {
    // get nav button
    var spaceCraftBtn = document.querySelectorAll('.spacecraft-btn-js')[0];

    var navigateToSpaceCraft = function() {
        window.location.href = 'spacecraft.html';
    }

    // bind listeners to dropdown button hybrids
    spaceCraftBtn.onclick = navigateToSpaceCraft;
});

from metismenu.

peterszarvas94 avatar peterszarvas94 commented on May 25, 2024
<ul>
	<li>
		<a href="">A</a>
	</li>
	<li>
		<a href="">B</a>
	</li>
	<li>
		<a href="">C</a>
	</li>
</ul>
function openainside(e) {
	window.open(e.children[0].getAttribute('href'), '_same');
}

window.addEventListener('load', ()=> {
	var lis = document.querySelector('ul').children;
	for (var i = 0; i < lis.length; i++) {
		lis[i].setAttribute('onclick', 'openainside(this)');
	}
});

from metismenu.

daveberk avatar daveberk commented on May 25, 2024

Wouldn't adding: onclick="window.location.href='/admin/index.html';" also work?

As in:

<li>
  <a class="has-arrow " href="#" aria-expanded="false" onclick="window.location.href='/admin/index.html';">Admin</a>
  <ul aria-expanded="false" class="collapse">
    <li><a href="/admin/orders.html">Orders</a></li>
...

from metismenu.

cosmopolit avatar cosmopolit commented on May 25, 2024

And good solution to link the a tag and open menu with arrow?

from metismenu.

cosmopolit avatar cosmopolit commented on May 25, 2024

The easiest way is to set the a tag in css as display: block it works for me.

is this solution still up to date? Any example?

from metismenu.

RatkoKovacevic avatar RatkoKovacevic commented on May 25, 2024

The easiest way is to set the a tag in css as display: block it works for me.

is this solution still up to date? Any example?

Yes! :)

from metismenu.

revolversi avatar revolversi commented on May 25, 2024

Simplest way to handle this would be by inserting a selector and jquery:
`href="/go-somewhere" class="breakoutMetis"

$(".breakoutMetis").click(function () {
window.location = $(this).attr("href");
});`

from metismenu.

cosmopolit avatar cosmopolit commented on May 25, 2024

I've been experimenting trying to separate page link and toggle submenu items in a separate a-tag. This is my latest version: http://codepen.io/eye-wonder/pen/VpqQad

Hi! Thank you for the codepen. Have you done any changes in the original js?

I am asking because its not working with the latest version of metismenu.

By the way - this is the best solution so far. it best corresponds to the habits of a DAU.

from metismenu.

eye-too avatar eye-too commented on May 25, 2024

I've been experimenting trying to separate page link and toggle submenu items in a separate a-tag. This is my latest version: http://codepen.io/eye-wonder/pen/VpqQad

Hi! Thank you for the codepen. Have you done any changes in the original js?

I am asking because its not working with the latest version of metismenu.

By the way - this is the best solution so far. it best corresponds to the habits of a DAU.

I haven't been working with menus like this for a while and I don't know the latest versions of MetisMenu. The last part of the javascript (click outside) is custom. The latest version of MetisMenu might also use different classes and/or IDs.

With the old one it looks like I activated the whole thing for this menu towards the end.

$(function () {
      $('#menu1').metisMenu();
  });

There might be other issues like missing jQuery or jQuery version or other settings or components. First take a look at this https://github.com/onokumus/metismenu#migrating-to-v3-from-v2

Also remember that the codepen is a proof-of-concept. It might work cross browser, but the CSS is far from tidy and optimized.

from metismenu.

cosmopolit avatar cosmopolit commented on May 25, 2024

I want to share an update of the split-button solution with you. Its working with the latest version.
Split Button Menu

from metismenu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.