1/** 2 * jQuery Mobile Menu 3 * Turn unordered list menu into dropdown select menu 4 * version 1.0(31-OCT-2011) 5 * 6 * Built on top of the jQuery library 7 * http://jquery.com 8 * 9 * Documentation 10 * http://github.com/mambows/mobilemenu 11 */ 12(function($){ 13$.fn.mobileMenu = function(options) { 14 15 // function isMobile(){ 16 // return ($('body').width() < 760); 17 // } 18 19 var defaults = { 20 defaultText: 'Navigate to...', 21 className: 'select-menu', 22 subMenuClass: 'sub-menu', 23 subMenuDash: '–' 24 }, 25 settings = $.extend( defaults, options ), 26 el = $(this); 27 28 this.each(function(){ 29 // ad class to submenu list 30 el.find('ul').addClass(settings.subMenuClass); 31 32 // Create base menu 33 $('<select />',{ 34 'class' : settings.className 35 }).insertAfter( el ); 36 37 // Create default option 38 $('<option />', { 39 "value" : '#', 40 "text" : settings.defaultText 41 }).appendTo( '.' + settings.className ); 42 43 // Create select option from menu 44 el.find('a,.separator').each(function(){ 45 var $this = $(this), 46 optText = $this.text(), 47 optSub = $this.parents( '.' + settings.subMenuClass ), 48 len = optSub.length, 49 dash; 50 51 // if menu has sub menu 52 if( $this.parents('ul').hasClass( settings.subMenuClass ) ) { 53 dash = Array( len+1 ).join( settings.subMenuDash ); 54 optText = dash + optText; 55 } 56 if($this.is('span')){ 57 // Now build menu and append it 58 $('<optgroup />', { 59 "label" : optText, 60 }).appendTo( '.' + settings.className ); 61 } 62 else{ 63 // Now build menu and append it 64 $('<option />', { 65 "value" : this.href, 66 "html" : optText, 67 "selected" : (this.href == window.location.href) 68 }).appendTo( '.' + settings.className ); 69 } 70 71 }); // End el.find('a').each 72 73 // Change event on select element 74 $('.' + settings.className).change(function(){ 75 var locations = $(this).val(); 76 if( locations !== '#' ) { 77 window.location.href = $(this).val(); 78 } 79 }); 80 $('.select-menu').show(); 81 82 }); // End this.each 83 // function runPlugin(){ 84 85 //menu exists, and browser is mobile width 86 // if(isMobile()){ 87 // $('.select-menu').show(); 88 // $('.sf-menu').hide(); 89 // } 90 91 // otherwise, hide the mobile menu 92 // else{ 93 // $('.select-menu').hide(); 94 // $('.sf-menu').show(); 95 // } 96 97 // }//runPlugin() 98 99// runPlugin(); 100 // $(window).resize(function(){runPlugin();}); 101 102 return this; 103}; 104})(jQuery);
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.