Skip to content

Instantly share code, notes, and snippets.

@danrcoull
Last active October 24, 2016 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danrcoull/461b444318e52372ff712a135ffdbb81 to your computer and use it in GitHub Desktop.
Save danrcoull/461b444318e52372ff712a135ffdbb81 to your computer and use it in GitHub Desktop.
Convert standard Foundation 6 Menu to dropdown menu on small screens on the fly.
## Convert standard Foundation 6 Menu to dropdown menu on small screens on the fly.
## Great for ecommerce like Magento 1.9 / 2.0
## Author: Daniel Coull <ttechitsolutions@gmail.com>
var topLinksMobile = {
topLinks: null,
topLinksWrapper: null,
topLinkWrap:'<ul class="dropdown menu top-links-wrapper" data-dropdown-menu><li></li></ul>',
topLinkBefore: '<a href="" class="cust-menu">Customer Menu</a>',
dropdown : null,
init : function() {
this.topLinks = $j('.top-links');
this.topLinksWrapper = $j('.top-links-wrapper');
},
createDropdown: function() {
if(this.topLinksWrapper.length == 0 && this.topLinks.length > 0) {
//wrap the structure
this.topLinks.wrap(this.topLinkWrap);
this.topLinksWrapper = $j('.top-links-wrapper');
//add a new a tag for dropdown
$j('.top-links-wrapper > li > ul').before(this.topLinkBefore);
//initialize foundation dropdown on the element
this.dropdown = new Foundation.DropdownMenu(this.topLinksWrapper);
}
},
destroyDropdown: function(){
this.topLinksWrapper = $j('.top-links-wrapper');
if(this.topLinksWrapper.length > 0 && this.topLinks.length > 0) {
this.topLinksWrapper.foundation('destroy');
$j('.top-links-wrapper .cust-menu').remove();
this.topLinks.unwrap().unwrap().removeClass('first-sub vertical');
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment