1// Add jquery class to body for jQuery dependent CSS 2(function() { 3 jQuery('html').addClass('jquery'); 4})(); 5 6// Main functionality 7jQuery(document).ready(function() { 8 9 // Menu containers array 10 var menuContainers = jrsm_params.containers.replace(/, /g,',').split(','); 11 12 // Only proceed if some menuContainer is specified 13 if ( '' == menuContainers ) 14 return false; 15 16 // 1. Loop through menu containers 17 jQuery.each(menuContainers, function( index, container ) { 18 19 // Find first <ul> in container 20 var ul = jQuery(container).find('ul').first(); 21 22 // Add dropdown <select> 23 jQuery('<select />', { 24 'class': 'jquery-responsive-select-menu jrsm-' + index, 25 'name': 'jrsm-' + index 26 }).insertAfter(ul); 27 28 if ( !jrsm_params.firstItem ) 29 var label = 'Navigation'; 30 31 // Add <label> for select 32 jQuery('<label />', { 33 'text': label, 34 'class': 'jrsm-label', 35 'for': 'jrsm-' + index 36 }).insertAfter(ul); 37 38 // Get jQuery object of <select> to append to 39 select = jQuery(container).find('.jquery-responsive-select-menu'); 40 41 // Create first, default <option> 42 if ( jrsm_params.firstItem ) { 43 var firstOption = jQuery('<option />', { 44 'class': 'first-option', 45 'value' : '', 46 'text' : jrsm_params.firstItem 47 }).appendTo(select); 48 } 49 50 // Loop through menu item <li>'s in container 51 get_child_menu_items( ul, 1 ); 52 53 // Choose <option> to be selected 54 if ( 1 == jrsm_params.showCurrentPage ) 55 select.find('.current-page').prop('selected',true); 56 else 57 select.find('option').first().prop('selected',true); 58 59 }); // End 1. Main loop through menu containers 60 61 // Select functionality 62 jQuery('.jquery-responsive-select-menu').change(function() { 63 var option = jQuery(this).find('option:selected').is('[value]'); 64 65 // Check if option has actual value 66 if ( jQuery(this).find('option:selected').is('[value]') && "#" != jQuery(this).find('option:selected').val() ) { 67 window.location = jQuery(this).find('option:selected').val(); 68 } 69 }); 70 71}); 72 73function get_child_menu_items( ul, depth ) { 74 75 // 2. Loop through menu item <li>'s 76 jQuery.each( ul.children('li'), function( index, li ) { 77 78 // Get jQuery object of <li> 79 var li = jQuery(li); 80 81 // Get depth prefix 82 var prefix = jrsm_params.indent; 83 prefix = Array(depth).join(prefix); 84 85 // Get <li> value & text 86 var value = li.children('a').attr('href'); 87 var text = li.children('a').text(); 88 89 // Ouput <option> 90 if ( ! jrsm_params.hideEmptyLinks || ( jrsm_params.hideEmptyLinks && value && "#" != value ) ) { 91 var option = jQuery('<option />', { 92 'value' : value, 93 'text' : prefix + ' ' + text 94 }).appendTo(select); 95 96 // Add "disabled" property if needed 97 if ( jrsm_params.disableEmptyLinks && ( ! value || "#" == value ) ) { 98 option.prop('disabled', true); 99 } 100 } 101 102 // Add current class to current page item 103 if ( li.hasClass('current_page_item') || li.hasClass('current-menu-item') ) { 104 option.addClass('current-page'); 105 } 106 107 // Only do something if this <li> contains a child <ul> 108 var ul = li.children('ul'); 109 110 // Repeat this loop for child <ul>'s 111 if ( ul.length > 0 ) { 112 get_child_menu_items( ul, depth + 1 ); 113 } 114 115 }); // End 2. Loop through menu item <li>'s 116 117}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.