diff --git a/bower.json b/bower.json index c53f93e..5dd8943 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "metisMenuAutoOpen", - "version": "0.0.8", + "version": "1.0.0", "authors": [ "Tim Schoondergang " ], @@ -25,6 +25,6 @@ ], "dependencies": { "jquery": ">2.1.1", - "metisMenu": ">1.0.0 <1.2.0" + "metisMenu": ">1.2.0" } } diff --git a/jquery.metisMenuAutoOpen.js b/jquery.metisMenuAutoOpen.js index eaffb1d..735909c 100644 --- a/jquery.metisMenuAutoOpen.js +++ b/jquery.metisMenuAutoOpen.js @@ -1,59 +1,55 @@ -;(function ($, window, document, undefined) { - +; +(function(global, factory) { + if (typeof define === "function" && define.amd) { + define(['jquery'], factory); + } else if (typeof exports !== "undefined") { + factory(require('jquery')); + } else { + var mod = { + exports: {} + }; + factory(global.jquery); + global.metisMenuAutoOpen = mod.exports; + } +})(this, function(_jquery) { var pluginName = "metisMenuAutoOpen", defaults = { classToAdd: 'current-page-item', currentLocation: window.location }; - + function Plugin(element, options) { this.element = element; - this.settings = $.extend({}, defaults, options); + this.settings = _jquery.extend({}, defaults, options); this._defaults = defaults; this._name = pluginName; this.init(); } - Plugin.prototype = { - init: function () { - - var $this_element = $(this.element), + init: function() { + var $this_element = _jquery(this.element), $classToAdd = this.settings.classToAdd, - $currentLocation = this.settings.currentLocation; - - - if (!window.location.origin){ - window.location.origin = window.location.protocol+"//"+window.location.host; - } - $currentLocation = window.location.origin + $currentLocation; - - - $this_element.find("li .nav-second-level li a").each(function(){ - //var classname = $(this).attr('class'); - var url = $(this).prop('href'); - - if($currentLocation == url){ - $(this).parentsUntil('ul').addClass($classToAdd); - $(this).parentsUntil('.nav-second-level').parent().addClass("in"); - $(this).parentsUntil('#side-menu','li:not(.'+$classToAdd+')').addClass("active"); - return false; - } - - - //var width = images.width(); - //var imgLength = images.length; - //$(this).find(".scrolling").width( width * imgLength * 1.2 ); - }); - + $currentLocation = this.settings.currentLocation; + if (!window.location.origin) { + window.location.origin = window.location.protocol + "//" + window.location.host; + } + $currentLocation = window.location.origin + $currentLocation; + $this_element.find("li .nav-second-level li a").each(function() { + var url = _jquery(this).prop('href'); + if ($currentLocation == url) { + _jquery(this).parentsUntil('ul').addClass($classToAdd); + _jquery(this).parentsUntil('.nav-second-level').parent().addClass("in"); + _jquery(this).parentsUntil('#side-menu', 'li:not(.' + $classToAdd + ')').addClass("active"); + return false; + } + }); } }; - - $.fn[ pluginName ] = function (options) { - return this.each(function () { - if (!$.data(this, "plugin_" + pluginName)) { - $.data(this, "plugin_" + pluginName, new Plugin(this, options)); + _jquery.fn[pluginName] = function(options) { + return this.each(function() { + if (!_jquery.data(this, "plugin_" + pluginName)) { + _jquery.data(this, "plugin_" + pluginName, new Plugin(this, options)); } }); }; - -})(jQuery, window, document); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..5fde3cb --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "name": "metisMenuAutoOpen", + "version": "1.0.0", + "description": "metisMenu with auto open on url", + "main": "jquery.metisMenuAutoOpen.js", + "repository": { + "url": "https://github.com/timmit-nl/metisMenuAutoOpen", + "type": "git" + }, + "author": "Tim Schoondergang ", + "license": "MIT" +}