JAVASCRIPT   107
jquery accordion menu js
Guest on 20th August 2022 12:58:15 AM


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

Raw Paste

Login or Register to edit or fork this paste. It's free.