Advertisement
AngusRussell

jQuery mobileMenu Function. Breaks in jQuery 1.8.3

Apr 28th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function (a) {
  2.     var b = 0;
  3.     a.fn.mobileMenu = function (c) {
  4.         function m(a) {
  5.             if (f() && !g(a)) {
  6.                 l(a)
  7.             } else if (f() && g(a)) {
  8.                 j(a)
  9.             } else if (!f() && g(a)) {
  10.                 k(a)
  11.             }
  12.         }
  13.         function l(b) {
  14.             if (e(b)) {
  15.                 var c = '<select id="mobileMenu_' + b.attr("id") + '" class="mobileMenu">';
  16.                 c += '<option value="">' + d.topOptionText + "</option>";
  17.                 b.find("li").each(function () {
  18.                     var b = "";
  19.                     var e = a(this).parents("ul, ol").length;
  20.                     for (i = 1; i < e; i++) {
  21.                         b += d.indentString
  22.                     }
  23.                     var f = a(this).find("a:first-child").attr("href");
  24.                     var g = b + a(this).clone().children("ul, ol").remove().end().text();
  25.                     c += '<option value="' + f + '">' + g + "</option>"
  26.                 });
  27.                 c += "</select>";
  28.                 b.parent().append(c);
  29.                 a("#mobileMenu_" + b.attr("id")).change(function () {
  30.                     h(a(this))
  31.                 });
  32.                 j(b)
  33.             } else {
  34.                 alert("mobileMenu will only work with UL or OL elements!")
  35.             }
  36.         }
  37.         function k(b) {
  38.             b.css("display", "");
  39.             a("#mobileMenu_" + b.attr("id")).hide()
  40.         }
  41.         function j(b) {
  42.             b.hide("display", "none");
  43.             a("#mobileMenu_" + b.attr("id")).show()
  44.         }
  45.         function h(a) {
  46.             if (a.val() !== null) {
  47.                 document.location.href = a.val()
  48.             }
  49.         }
  50.         function g(c) {
  51.             if (c.attr("id")) {
  52.                 return a("#mobileMenu_" + c.attr("id")).length > 0
  53.             } else {
  54.                 b++;
  55.                 c.attr("id", "mm" + b);
  56.                 return a("#mobileMenu_mm" + b).length > 0
  57.             }
  58.         }
  59.         function f() {
  60.             return a(window).width() < d.switchWidth
  61.         }
  62.         function e(a) {
  63.             return a.is("ul, ol")
  64.         }
  65.         var d = {
  66.             switchWidth: 768,
  67.             topOptionText: "Select a page",
  68.             indentString: "   "
  69.         };
  70.         return this.each(function () {
  71.             if (c) {
  72.                 a.extend(d, c)
  73.             }
  74.             var b = a(this);
  75.             a(window).resize(function () {
  76.                 m(b)
  77.             });
  78.             m(b)
  79.         })
  80.     }
  81. })(jQuery);
  82.  
  83. jQuery(document).ready(function () {
  84.     jQuery('ul#top-nav').mobileMenu({
  85.         switchWidth: 767, //width (in px to switch at)
  86.         topOptionText: 'Select a page', //first option text
  87.         indentString: '&nbsp;&nbsp;&nbsp;' //string for indenting nested items
  88.     });
  89. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement