1/** 2 * jQuery Mobile Menu 3 * Turn unordered list menu into dropdown select menu 4 * version 1.1(27-JULY-2013) 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 var defaults = {}, title = $(this).data('title'), default_title = ''; 15 if (title.length > 0) 16 default_title = title; 17 else{ 18 default_title = 'Menu'; 19 } 20 defaults = { 21 defaultText: default_title, 22 className: 'select-menu', 23 subMenuClass: 'sub-menu', 24 subMenuDash: '–' 25 }, 26 settings = $.extend( defaults, options ), 27 el = $(this); 28 29 this.each(function(){ 30 var $el = $(this), 31 $select_menu; 32 33 // ad class to submenu list 34 $el.find('ul').addClass(settings.subMenuClass); 35 36 // Create base menu 37 var $select_menu = $('<select />',{ 38 'class' : settings.className + ' ' + el.get(0).className 39 }).insertAfter( $el ); 40 41 title = $el.data('title'); 42 if (title.length > 0) 43 { 44 default_title = title; 45 }else{ 46 default_title = 'Menu'; 47 } 48 49 // Create default option 50 $('<option />', { 51 "value" : '#', 52 "text" : default_title 53 }).appendTo( $select_menu ); 54 55 // Create select option from menu 56 $el.find('a').each(function(){ 57 var $this = $(this), 58 optText = ' ' + $this.text(), 59 optSub = $this.parents( '.' + settings.subMenuClass ), 60 len = optSub.length, 61 dash; 62 63 // if menu has sub menu 64 if( $this.parents('ul').hasClass( settings.subMenuClass ) ) { 65 dash = Array( len+1 ).join( settings.subMenuDash ); 66 optText = dash + optText; 67 } 68 69 // Now build menu and append it 70 $('<option />', { 71 "value" : this.href, 72 "html" : optText, 73 "selected" : (this.href == window.location.href) 74 }).appendTo( $select_menu ); 75 76 }); // End el.find('a').each 77 78 // Change event on select element 79 $select_menu.change(function(){ 80 var locations = $(this).val(); 81 if( locations !== '#' ) { 82 window.location.href = $(this).val(); 83 }; 84 }); 85 $('.select-menu').show(); 86 }); // End this.each 87 88 return this; 89 90}; 91})(jQuery); 92 93$(function(){ 94 var resized = false; 95 $(window).load(function(){ 96 var w=$(this).width(); 97 if (w <= 940){ 98 resized = true; 99 $('.sf-menu').mobileMenu(); 100 } 101 }); 102 $(window).resize(function(){ 103 var w=$(this).width(); 104 if (w <= 940 && !resized){ 105 $('.sf-menu').mobileMenu(); 106 resized = true; 107 } 108 }); 109});
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.