1(function ($) { 2 $.fn.mobileMenu = function (o) { 3 4 var o = jQuery.extend({ ulsource: '', maxlevel: 8 }, o); 5 6 // internal functions 7 String.prototype.lpad = function (padString, length) { 8 var str = this; 9 while (str.length < length) 10 str = padString + str; 11 return str; 12 } 13 14 var MENU = MENU || { 15 optionsList: "<option select='selected'>Menu</option>", 16 17 // recursively walks an unordered list and builds a list of option elements for a select dropdown 18 BuildSelectOptionsFromMenu: function (liElems, level, maxLevel) { 19 20 if (liElems.length == 0) 21 return; 22 23 var spaces = "".lpad(" » ", (level - 1) * 12); 24 25 liElems.each(function () { 26 27 var aSpanElem = $(this).find("span.menu-item-text").first(); 28 var aSpanElemLink = aSpanElem.parent().parent().attr("href"); 29 30 //console.log(aSpanElem.text()); 31 32 if (typeof aSpanElemLink !== "undefined") { 33 MENU.optionsList += "<option value='" + aSpanElemLink + "'>" + spaces + aSpanElem.text() + "</option> \n"; 34 } else { 35 MENU.optionsList += "<option value='#'>" + spaces + aSpanElem.text() + "</option> \n"; 36 } 37 38 39 // recursively get next level of li tags 40 if (level < maxLevel) 41 MENU.BuildSelectOptionsFromMenu($(this).children("ul").children("li"), level + 1, maxLevel); 42 }); 43 } 44 } 45 46 // plugin code 47 var ul = $(o.ulsource); 48 var lis = ul.children("li"); 49 50 if (this.length == 0 || !this.is("select")) { 51 $.error("mobileMenu method not applied to a select element on jquery.mobilemenu"); 52 return this; 53 } 54 55 if (ul.length == 0 || lis.length == 0) { 56 $.error("ulsource not found in DOM, or doesn't contain li elements on jquery.mobilemenu"); 57 return this; 58 } 59 60 MENU.BuildSelectOptionsFromMenu(lis, 1, o.maxlevel); 61 62 // add newly constructed list of options to the select element and navigate on the change event 63 this.html(MENU.optionsList).bind("change.mobileMenu", function () { 64 window.location.href = $(this).val(); 65 }); 66 67 return this; 68 69 }; 70})(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.