diff options
author | Tommy Chen <tommy351@gmail.com> | 2012-06-03 04:20:50 +0200 |
---|---|---|
committer | Tommy Chen <tommy351@gmail.com> | 2012-06-03 04:20:50 +0200 |
commit | e3cc2b2ff5d96ed69c982c100692a1745bc261ef (patch) | |
tree | 364196089ecf8031a73a00ba5cb4ce3652dbc72f | |
parent | 5ba7052e5f584b5859ae3d9b00b1847391989ca1 (diff) | |
download | octopress-theme-jeyzu-e3cc2b2ff5d96ed69c982c100692a1745bc261ef.zip octopress-theme-jeyzu-e3cc2b2ff5d96ed69c982c100692a1745bc261ef.tar.gz |
rewrite navigation.js
-rw-r--r-- | source/javascripts/navigation.js | 16 | ||||
-rw-r--r-- | source/javascripts/slash.js | 42 |
2 files changed, 30 insertions, 28 deletions
diff --git a/source/javascripts/navigation.js b/source/javascripts/navigation.js deleted file mode 100644 index 652aafa..0000000 --- a/source/javascripts/navigation.js +++ /dev/null @@ -1,16 +0,0 @@ -(function($){ - var appends = '<option>Menu</option>'; - - $('.menu .main > li').each(function(){ - var link = $(this).children('a'); - appends += '<option value="'+link.attr('href')+'">'+link.html()+'</option>'; - $(this).find('li').each(function(){ - var link = $(this).children('a'); - appends += '<option value="'+link.attr('href')+'">- '+link.html()+'</option>'; - }); - }); - - $('nav.menu').append('<select>'+appends+'</select>').on('change', 'select', function(){ - location.href = $(this).val(); - }); -})(jQuery);
\ No newline at end of file diff --git a/source/javascripts/slash.js b/source/javascripts/slash.js index 270f39c..0105d69 100644 --- a/source/javascripts/slash.js +++ b/source/javascripts/slash.js @@ -14,22 +14,40 @@ }); }; + // Append menu for mobile device + var navigationMenu = function(){ + var appends = '<option>Menu</option>'; - /* navigation.js */ - var appends = '<option>Menu</option>'; + var search = function(obj, level){ + var children = obj.children(), + link = children.eq(0), + _level = level + 1; - $('.menu .main > li').each(function(){ - var link = $(this).children('a'); - appends += '<option value="'+link.attr('href')+'">'+link.html()+'</option>'; - $(this).find('li').each(function(){ - var link = $(this).children('a'); - appends += '<option value="'+link.attr('href')+'">- '+link.html()+'</option>'; + appends += '<option value="'+link.attr('href')+'">'; + + if (level > 0) appends += '|'; + + for (var i=0; i<level; i++){ + appends += '—'; + } + + appends += link.text()+'</option>'; + + if (children.length > 1){ + children.eq(1).children('li').each(function(){ + search($(this), _level); + }); + } + }; + + $('#header .menu .main').children('li').each(function(){ + search($(this), 0); }); - }); - $('nav.menu').append('<select>'+appends+'</select>').on('change', 'select', function(){ - location.href = $(this).val(); - }); + $('#header .menu').append('<select>'+appends+'</select>').on('change', 'select', function(){ + location.href = $(this).val(); + }); + }; /* caption.js */ $('.entry').each(function(i){ |