header.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* accordion menu plugin*/ ;
  2. (function($, window, document, undefined) {
  3. var pluginName = "mobileMenu";
  4. var defaults = {
  5. speed: 400,
  6. showDelay: 0,
  7. hideDelay: 0,
  8. singleOpen: true,
  9. clickEffect: true,
  10. indicator: 'active',
  11. subMenu: 'sub-menu',
  12. subMenu2: 'sub-sub-menu',
  13. event: 'click touchstart' // click, touchstart
  14. };
  15. function Plugin(element, options) {
  16. this.element = element;
  17. this.settings = $.extend({}, defaults, options);
  18. this._defaults = defaults;
  19. this._name = pluginName;
  20. this.init();
  21. }
  22. $.extend(Plugin.prototype, {
  23. init: function() {
  24. this.openSubmenu();
  25. // this.submenuIndicators();
  26. if (defaults.clickEffect) {
  27. this.addClickEffect();
  28. }
  29. },
  30. openSubmenu: function() {
  31. $(this.element).children("ul").find("li").bind(defaults.event, function(e) {
  32. e.stopPropagation();
  33. e.preventDefault();
  34. var $subMenus = $(this).children("." + defaults.subMenu);
  35. var $allSubMenus = $(this).find("." + defaults.subMenu);
  36. if ($subMenus.length > 0) {
  37. if ($subMenus.css("display") == "none") {
  38. $subMenus.slideDown(defaults.speed).siblings("a").addClass(defaults.indicator);
  39. if (defaults.singleOpen) {
  40. $(this).siblings().find("." + defaults.subMenu).slideUp(defaults.speed)
  41. .end().find("a").removeClass(defaults.indicator);
  42. }
  43. return false;
  44. } else {
  45. $(this).find("." + defaults.subMenu).delay(defaults.hideDelay).slideUp(defaults.speed);
  46. }
  47. if ($allSubMenus.siblings("a").hasClass(defaults.indicator)) {
  48. $allSubMenus.siblings("a").removeClass(defaults.indicator);
  49. }
  50. }
  51. window.location.href = $(this).children("a").attr("href");
  52. });
  53. },
  54. // submenuIndicators: function () {
  55. // if ($(this.element).find("." + defaults.subMenu).length > 0) {
  56. // $(this.element).find("." + defaults.subMenu).siblings("a").append("<span class='submenu-indicator'>+</span>");
  57. // }
  58. // },
  59. addClickEffect: function() {
  60. var ink, d, x, y;
  61. $(this.element).find(".menu li a").bind("click touchstart", function(e) {
  62. $(".ink").remove();
  63. if ($(this).children(".ink").length === 0) {
  64. $(this).prepend("<span class='ink'></span>");
  65. }
  66. ink = $(this).find(".ink");
  67. ink.removeClass("animate-ink");
  68. if (!ink.height() && !ink.width()) {
  69. d = Math.max($(this).outerWidth(), $(this).outerHeight());
  70. ink.css({
  71. height: d,
  72. width: d
  73. });
  74. }
  75. x = e.pageX - $(this).offset().left - ink.width() / 2;
  76. y = e.pageY - $(this).offset().top - ink.height() / 2;
  77. ink.css({
  78. top: y + 'px',
  79. left: x + 'px'
  80. }).addClass("animate-ink");
  81. });
  82. }
  83. });
  84. $.fn[pluginName] = function(options) {
  85. this.each(function() {
  86. if (!$.data(this, "plugin_" + pluginName)) {
  87. $.data(this, "plugin_" + pluginName, new Plugin(this, options));
  88. }
  89. });
  90. return this;
  91. };
  92. $(".menu-wrapper").mobileMenu();
  93. $(".fullscreen-menu").mobileMenu();
  94. })(jQuery, window, document);