Advertisement
ForbodingAngel

Untitled

May 15th, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. jQuery(document).ready(function() {
  2.  
  3. // Add jquery class to body for jquery dependent CSS
  4. jQuery('body').addClass('jquery');
  5.  
  6. // Menu containers array
  7. var menuContainers = php_params.containers.replace(/, /g,',').split(',');
  8.  
  9. // Only proceed if some menuContainer is specified
  10. if ( '' == menuContainers )
  11. return false;
  12.  
  13. // 1. Loop through menu containers
  14. jQuery.each(menuContainers, function( index, container ) {
  15.  
  16. // Find first <ul> in container
  17. var ul = jQuery(container).find('ul').first();
  18.  
  19. // Add dropdown <select>
  20. jQuery('<select />', {
  21. 'class': 'jquery-responsive-select-menu jrsm-' + index,
  22. 'name': 'jrsm-' + index
  23. }).insertAfter(ul);
  24.  
  25. if ( !php_params.firstItem )
  26. var label = 'Navigation';
  27.  
  28. // Add <label> for select
  29. jQuery('<label />', {
  30. 'text': label,
  31. 'class': 'jrsm-label',
  32. 'for': 'jrsm-' + index
  33. }).insertAfter(ul);
  34.  
  35. // Get jQuery object of <select> to append to
  36. select = jQuery(container).find('.jquery-responsive-select-menu');
  37.  
  38. // Create first, default <option>
  39. if ( php_params.firstItem ) {
  40. var firstOption = jQuery('<option />', {
  41. 'class': 'first-option',
  42. 'value' : '',
  43. 'text' : php_params.firstItem
  44. }).appendTo(select);
  45. }
  46.  
  47. // Loop through menu item <li>'s in container
  48. get_child_menu_items( ul, 1 );
  49.  
  50. // Choose <option> to be selected
  51. if ( 1 == php_params.showCurrentPage )
  52. select.find('.current-page').attr('selected',true);
  53. else
  54. select.find('option').first().attr('selected',true);
  55.  
  56. }); // End 1. Main loop through menu containers
  57.  
  58. // Select functionality
  59. jQuery('.jquery-responsive-select-menu').change(function() {
  60. window.location = jQuery(this).find('option:selected').val();
  61. });
  62.  
  63. });
  64.  
  65. function get_child_menu_items( ul, depth ) {
  66.  
  67. // 2. Loop through menu item <li>'s
  68. jQuery.each( ul.children('li'), function( index, li ) {
  69.  
  70. // Get jQuery object of <li>
  71. var li = jQuery(li);
  72.  
  73. // Get depth prefix
  74. var prefix = php_params.indent;
  75. prefix = Array(depth).join(prefix);
  76.  
  77. // Get <li> value & text
  78. var value = li.children('a').attr('href');
  79. var text = li.children('a').text();
  80.  
  81. // Ouput <option>
  82. var option = jQuery('<option />', {
  83. 'value' : value,
  84. 'text' : prefix + ' ' + text
  85. }).appendTo(select);
  86.  
  87. // Add current class to current page item
  88. if ( li.hasClass('current_page_item') ) {
  89. option.addClass('current-page');
  90. }
  91.  
  92. // Only do something if this <li> contains a child <ul>
  93. var ul = li.children('ul');
  94.  
  95. // Repeat this loop for child <ul>'s
  96. if ( ul.length > 0 ) {
  97. get_child_menu_items( ul, depth + 1 );
  98. }
  99.  
  100. }); // End 2. Loop through menu item <li>'s
  101.  
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement