Created
September 4, 2014 15:24
-
-
Save laurentperroteau/7bd9b00c96adbc254e03 to your computer and use it in GitHub Desktop.
Transform list in dropdown
This file contains 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
/** | |
* List to dropdown | |
* =================================== | |
*/ | |
o.listToDropdown = function () { | |
if(!o.device('m') || !$('.list-to-dropdown').length ) | |
return false; | |
// Create the dropdown base | |
$("<select />").appendTo(".list-to-dropdown .element-select"); | |
if($('#history').length){ | |
var intitule = "Accueil compte"; | |
}else if($('.link-list').length){ | |
var intitule = "Choisir"; | |
} | |
// Create default option "Go to..." | |
$("<option />", { | |
"selected": "selected", | |
"value" : "", | |
"text" : intitule | |
}).appendTo(".list-to-dropdown select"); | |
// Populate dropdown with menu items | |
$(".list-to-dropdown a").each(function() { | |
var el = $(this); | |
$("<option />", { | |
"value" : el.attr("href"), | |
"text" : el.text() | |
}).appendTo(".list-to-dropdown select"); | |
}); | |
$(".list-to-dropdown select").change(function() { | |
window.location = $(this).find("option:selected").val(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment