Skip to content

Instantly share code, notes, and snippets.

@courgette
Created December 17, 2013 14:18
Show Gist options
  • Save courgette/8005576 to your computer and use it in GitHub Desktop.
Save courgette/8005576 to your computer and use it in GitHub Desktop.
[DRUPAL] ul to select for mobile device
Drupal.theme.ulToSelect = function(selector){
$(selector).once('ulToSelect', function(){
var ul = $(this),
select = '<select id="select"/>';
ul.after(select);
ul.find('li').each(function(){
var text = $(this).text(),
link = $(this).find('a').attr('href');
$('#select').append('<option data-link="'+link+'">'+text+'</option>');
});
$('#select').live('change', function(){
var link = $(this).find('option:selected').data('link');
window.location = link;
});
ul.hide();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment