Skip to content

Instantly share code, notes, and snippets.

@Kcko
Created February 19, 2015 20:27
Show Gist options
  • Save Kcko/790e8394b0a62ea07c8a to your computer and use it in GitHub Desktop.
Save Kcko/790e8394b0a62ea07c8a to your computer and use it in GitHub Desktop.
HTML seznam do selectboxu (např. pro responsivní navigaci)
$(function(){
var select = $("select");
$("nav a").each(function(){
var $this = $(this);
var text = $this.text();
var level = $this.parents("ul").length;
var indent = '';
if (level > 1)
{
indent = str_repeat("\u2013", level);
}
select.append('<option>'+indent + text+'</option>');
});
});
function str_repeat (input, multiplier) {
// http://kevin.vanzonneveld.net
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
// + improved by: Ian Carter (http://euona.com/)
// * example 1: str_repeat('-=', 10);
// * returns 1: '-=-=-=-=-=-=-=-=-=-='
var y = '';
while (true) {
if (multiplier & 1) {
y += input;
}
multiplier >>= 1;
if (multiplier) {
input += input;
}
else {
break;
}
}
return y;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment