Created
December 17, 2013 14:18
-
-
Save courgette/8005576 to your computer and use it in GitHub Desktop.
[DRUPAL] ul to select for mobile device
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
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