jquery.meanmenu.min.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. (function($) {
  2. 'use strict';
  3. $.fn.meanmenu = function(e) {
  4. var n = {
  5. meanMenuTarget: jQuery(this),
  6. meanMenuContainer: 'body',
  7. meanMenuClose: '<span /><span /><span />',
  8. meanMenuCloseSize: '18px',
  9. meanMenuOpen: '<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) ||
  48. navigator.userAgent.match(/iPod/i) ||
  49. navigator.userAgent.match(/iPad/i) ||
  50. navigator.userAgent.match(/Android/i) ||
  51. navigator.userAgent.match(/Blackberry/i) ||
  52. navigator.userAgent.match(/Windows Phone/i)) &&
  53. (C = !0),
  54. (navigator.userAgent.match(/MSIE 8/i) ||
  55. navigator.userAgent.match(/MSIE 7/i)) &&
  56. jQuery('html').css('overflow-y', 'scroll');
  57. var w = '',
  58. x = function() {
  59. if ('center' === u) {
  60. var e =
  61. window.innerWidth ||
  62. document.documentElement.clientWidth,
  63. n = e / 2 - 22 + 'px';
  64. (w = 'left:' + n + ';right:auto;'),
  65. C
  66. ?
  67. jQuery('.meanmenu-reveal').animate({
  68. left: n,
  69. }) :
  70. jQuery('.meanmenu-reveal').css('left', n);
  71. }
  72. },
  73. A = !1,
  74. E = !1;
  75. 'right' === u && (w = 'right:' + m + ';left:auto;'),
  76. 'left' === u && (w = 'left:' + m + ';right:auto;'),
  77. x();
  78. var M = '',
  79. W = function() {
  80. jQuery('.mean-bar,.mean-push').remove(),
  81. jQuery(t).removeClass('mean-container'),
  82. jQuery(n).css('display', g),
  83. (A = !1),
  84. (E = !1),
  85. jQuery(p).removeClass('mean-remove');
  86. },
  87. b = function() {
  88. var e = 'background:' + l + ';color:' + l + ';' + w;
  89. if (o >= a) {
  90. jQuery(p).addClass('mean-remove'),
  91. (E = !0),
  92. jQuery(t).addClass('mean-container'),
  93. jQuery('.mean-container').prepend(
  94. '<div class="mean-bar"><a href="#nav" class="meanmenu-reveal" style="' +
  95. e +
  96. '">Show Navigation</a><nav class="mean-nav"></nav></div>'
  97. );
  98. jQuery(v).html(s),
  99. setTimeout(function(){
  100. var r = jQuery(n).html();
  101. jQuery('.mean-nav').html(r),
  102. Q &&
  103. jQuery(
  104. 'nav.mean-nav ul, nav.mean-nav ul *'
  105. ).each(function() {
  106. jQuery(this).is('.mean-remove') ?
  107. jQuery(this).attr(
  108. 'class',
  109. 'mean-remove'
  110. ) :
  111. jQuery(this).removeAttr('class'),
  112. jQuery(this).removeAttr('id');
  113. }),
  114. jQuery(n).before('<div class="mean-push" />'),
  115. jQuery('.mean-push').css('margin-top', c),
  116. jQuery(n).hide(),
  117. jQuery('.meanmenu-reveal').show(),
  118. (M = jQuery(v)),
  119. jQuery('.mean-nav ul').hide(),
  120. h ?
  121. d ?
  122. (jQuery('.mean-nav ul ul').each(
  123. function() {
  124. jQuery(this).children()
  125. .length &&
  126. jQuery(this, 'li:first')
  127. .parent()
  128. .append(
  129. '<a class="mean-expand" href="#" style="font-size: ' +
  130. i +
  131. '">' +
  132. y +
  133. '</a>'
  134. );
  135. }
  136. ),
  137. jQuery('.mean-expand').on(
  138. 'click',
  139. function(e) {
  140. e.preventDefault(),
  141. jQuery(this).hasClass(
  142. 'mean-clicked'
  143. ) ?
  144. (jQuery(this).text(y),
  145. jQuery(this)
  146. .prev('ul')
  147. .slideUp(
  148. 300,
  149. function() {}
  150. )) :
  151. (jQuery(this).text(j),
  152. jQuery(this)
  153. .prev('ul')
  154. .slideDown(
  155. 300,
  156. function() {}
  157. )),
  158. jQuery(this).toggleClass(
  159. 'mean-clicked'
  160. );
  161. }
  162. )) :
  163. jQuery('.mean-nav ul ul').show() :
  164. jQuery('.mean-nav ul ul').hide(),
  165. jQuery('.mean-nav ul li')
  166. .last()
  167. .addClass('mean-last'),
  168. M.removeClass('meanclose'),
  169. jQuery(M).on('click',function(e) {
  170. e.preventDefault(),
  171. A === !1 ?
  172. (M.css('text-align', 'center'),
  173. M.css('text-indent', '0'),
  174. M.css('font-size', i),
  175. jQuery(
  176. '.mean-nav ul:first'
  177. ).slideDown(),
  178. (A = !0)) :
  179. (jQuery(
  180. '.mean-nav ul:first'
  181. ).slideUp(),
  182. (A = !1)),
  183. M.toggleClass('meanclose'),
  184. jQuery(p).addClass('mean-remove');
  185. }),
  186. f &&
  187. jQuery('.mean-nav ul > li > a:first-child').on(
  188. 'click',
  189. function() {
  190. jQuery('.mean-nav ul:first').slideUp(),
  191. (A = !1),
  192. jQuery(M)
  193. .toggleClass('meanclose')
  194. .html(s);
  195. }
  196. );
  197. },300)
  198. } else W();
  199. };
  200. C ||
  201. jQuery(window).resize(function() {
  202. (a =
  203. window.innerWidth ||
  204. document.documentElement.clientWidth),
  205. a > o,
  206. W(),
  207. o >= a ? (b(), x()) : W();
  208. }),
  209. jQuery(window).resize(function() {
  210. (a =
  211. window.innerWidth ||
  212. document.documentElement.clientWidth),
  213. C
  214. ?
  215. (x(), o >= a ? E === !1 && b() : W()) :
  216. (W(), o >= a && (b(), x()));
  217. }),
  218. b();
  219. });
  220. };
  221. })(jQuery);