Skip to content

Instantly share code, notes, and snippets.

@laurentperroteau
Created September 4, 2014 15:24
Show Gist options
  • Save laurentperroteau/7bd9b00c96adbc254e03 to your computer and use it in GitHub Desktop.
Save laurentperroteau/7bd9b00c96adbc254e03 to your computer and use it in GitHub Desktop.
Transform list in dropdown
/**
* 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