jquery.meanmenu.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. ! function($) {
  2. "use strict";
  3. $.fn.meanmenu = function(e) {
  4. var n = {
  5. meanMenuTarget: jQuery(this),
  6. meanMenuContainer: ".mobile-nav",
  7. meanMenuClose: "X",
  8. meanMenuCloseSize: "18px",
  9. meanMenuOpen: "<span></span><span></span><span></span>",
  10. meanRevealPosition: "right",
  11. meanRevealPositionDistance: "0",
  12. meanRevealColour: "",
  13. meanScreenWidth: "480",
  14. meanNavPush: "",
  15. meanShowChildren: !0,
  16. meanExpandableChildren: !0,
  17. meanExpand: "+",
  18. meanContract: "-",
  19. meanRemoveAttrs: !1,
  20. onePage: !1,
  21. meanDisplay: "block",
  22. removeElements: ""
  23. };
  24. e = $.extend(n, e);
  25. var a = window.innerWidth || document.documentElement.clientWidth;
  26. return this.each(function() {
  27. var n = e.meanMenuTarget,
  28. t = e.meanMenuContainer,
  29. r = e.meanMenuClose,
  30. i = e.meanMenuCloseSize,
  31. s = e.meanMenuOpen,
  32. u = e.meanRevealPosition,
  33. m = e.meanRevealPositionDistance,
  34. l = e.meanRevealColour,
  35. o = e.meanScreenWidth,
  36. c = e.meanNavPush,
  37. v = ".meanmenu-reveal",
  38. h = e.meanShowChildren,
  39. d = e.meanExpandableChildren,
  40. y = e.meanExpand,
  41. j = e.meanContract,
  42. Q = e.meanRemoveAttrs,
  43. f = e.onePage,
  44. g = e.meanDisplay,
  45. p = e.removeElements,
  46. C = !1;
  47. (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/Blackberry/i) || navigator.userAgent.match(/Windows Phone/i)) && (C = !0), (navigator.userAgent.match(/MSIE 8/i) || navigator.userAgent.match(/MSIE 7/i)) && jQuery("html").css("overflow-y", "scroll");
  48. var w = "",
  49. x = function() {
  50. if ("center" === u) {
  51. var e = window.innerWidth || document.documentElement.clientWidth,
  52. n = e / 2 - 22 + "px";
  53. w = "left:" + n + ";right:auto;", C ? jQuery(".meanmenu-reveal").animate({
  54. left: n
  55. }) : jQuery(".meanmenu-reveal").css("left", n)
  56. }
  57. },
  58. A = !1,
  59. E = !1;
  60. "right" === u && (w = "right:" + m + ";left:auto;"), "left" === u && (w = "left:" + m + ";right:auto;"), x();
  61. var M = "",
  62. P = function() {
  63. M.html(jQuery(M).is(".meanmenu-reveal.meanclose") ? r : s)
  64. },
  65. W = function() {
  66. jQuery(".mean-bar,.mean-push").remove(), jQuery(t).removeClass("mean-container"), jQuery(n).css("display", g), A = !1, E = !1, jQuery(p).removeClass("mean-remove")
  67. },
  68. b = function() {
  69. var e = "background:" + l + ";color:" + l + ";" + w;
  70. if (o >= a) {
  71. jQuery(p).addClass("mean-remove"), E = !0, jQuery(t).addClass("mean-container"), jQuery(".mean-container").prepend('<div class="mean-bar"><a href="#nav" class="meanmenu-reveal" style="' + e + '">Show Navigation</a><nav class="mean-nav"></nav></div>');
  72. var r = jQuery(n).html();
  73. jQuery(".mean-nav").html(r), Q && jQuery("nav.mean-nav ul, nav.mean-nav ul *").each(function() {
  74. jQuery(this).is(".mean-remove") ? jQuery(this).attr("class", "mean-remove") : jQuery(this).removeAttr("class"), jQuery(this).removeAttr("id")
  75. }), jQuery(n).before('<div class="mean-push" />'), jQuery(".mean-push").css("margin-top", c), jQuery(n).hide(), jQuery(".meanmenu-reveal").show(), jQuery(v).html(s), M = jQuery(v), jQuery(".mean-nav ul").hide(), h ? d ? (jQuery(".mean-nav ul ul").each(function() {
  76. jQuery(this).children().length && jQuery(this, "li:first").parent().append('<a class="mean-expand" href="#" style="font-size: ' + i + '">' + y + "</a>")
  77. }), jQuery(".mean-expand").on("click", function(e) {
  78. e.preventDefault(), jQuery(this).hasClass("mean-clicked") ? (jQuery(this).text(y), jQuery(this).prev("ul").slideUp(300, function() {})) : (jQuery(this).text(j), jQuery(this).prev("ul").slideDown(300, function() {})), jQuery(this).toggleClass("mean-clicked")
  79. })) : jQuery(".mean-nav ul ul").show() : jQuery(".mean-nav ul ul").hide(), jQuery(".mean-nav ul li").last().addClass("mean-last"), M.removeClass("meanclose"), jQuery(M).click(function(e) {
  80. e.preventDefault(), A === !1 ? (M.css("text-align", "center"), M.css("text-indent", "0"), M.css("font-size", i), jQuery(".mean-nav ul:first").slideDown(), A = !0) : (jQuery(".mean-nav ul:first").slideUp(), A = !1), M.toggleClass("meanclose"), P(), jQuery(p).addClass("mean-remove")
  81. }), f && jQuery(".mean-nav ul > li > a:first-child").on("click", function() {
  82. jQuery(".mean-nav ul:first").slideUp(), A = !1, jQuery(M).toggleClass("meanclose").html(s)
  83. })
  84. } else W()
  85. };
  86. C || jQuery(window).resize(function() {
  87. a = window.innerWidth || document.documentElement.clientWidth, a > o, W(), o >= a ? (b(), x()) : W()
  88. }), jQuery(window).resize(function() {
  89. a = window.innerWidth || document.documentElement.clientWidth, C ? (x(), o >= a ? E === !1 && b() : W()) : (W(), o >= a && (b(), x()))
  90. }), b()
  91. })
  92. }
  93. }(jQuery);