jquery.metisMenu.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ;(function ($, window, document, undefined) {
  2. var pluginName = "metisMenu",
  3. defaults = {
  4. toggle: true
  5. };
  6. function Plugin(element, options) {
  7. this.element = element;
  8. this.settings = $.extend({}, defaults, options);
  9. this._defaults = defaults;
  10. this._name = pluginName;
  11. this.init();
  12. }
  13. Plugin.prototype = {
  14. init: function () {
  15. var $this = $(this.element),
  16. $toggle = this.settings.toggle;
  17. $this.find('li.active').has('ul').children('ul').addClass('collapse in');
  18. $this.find('li').not('.active').has('ul').children('ul').addClass('collapse');
  19. $this.find('li').has('ul').children('a').on('click', function (e) {
  20. e.preventDefault();
  21. $(this).parent('li').toggleClass('active').children('ul').collapse('toggle');
  22. if ($toggle) {
  23. $(this).parent('li').siblings().removeClass('active').children('ul.in').collapse('hide');
  24. }
  25. });
  26. }
  27. };
  28. $.fn[ pluginName ] = function (options) {
  29. return this.each(function () {
  30. if (!$.data(this, "plugin_" + pluginName)) {
  31. $.data(this, "plugin_" + pluginName, new Plugin(this, options));
  32. }
  33. });
  34. };
  35. })(jQuery, window, document);