Created
February 14, 2012 15:25
-
-
Save MrMaksimize/1827546 to your computer and use it in GitHub Desktop.
menu to dropdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function menuToDropdown(topContainer, ulClass, context){ | |
if (context == 'mobile'){ | |
$("<select />").appendTo(topContainer).addClass('mobile mobile-dropdown ' + topContainer.replace('#','') + '-mobile'); | |
$('ul'+ulClass + ' li', topContainer).each( function(){ | |
var el = this; | |
//construct optionString | |
var optionString = '<option value = "' + $('a', this).attr('href') + '" '; | |
if($(this).hasClass('active')){ | |
optionString = optionString + 'selected="selected" ' | |
} | |
optionString = optionString + '>' + $('a', this).text() + '</a>'; | |
$('select', topContainer).append(optionString); | |
/*append('<option value = "' + | |
$('a', this).attr('href') + '">' + | |
$('a', this).text() + '</a>');*/ | |
}); | |
//now hide the original lis for future use | |
$('ul'+ulClass).hide(); | |
//bind the change function | |
$('select', topContainer).change(function(){ | |
window.location = $(this).find("option:selected").val(); | |
}); | |
} | |
else{ | |
$('ul'+ulClass).show(); | |
$('select', topContainer).remove(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment