Skip to content

Commit

Permalink
AMD support and updated bower.json en added package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Schoondergang committed Dec 22, 2017
1 parent e316faa commit 210e456
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 43 deletions.
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metisMenuAutoOpen",
"version": "0.0.8",
"version": "1.0.0",
"authors": [
"Tim Schoondergang <[email protected]>"
],
Expand All @@ -25,6 +25,6 @@
],
"dependencies": {
"jquery": ">2.1.1",
"metisMenu": ">1.0.0 <1.2.0"
"metisMenu": ">1.2.0"
}
}
78 changes: 37 additions & 41 deletions jquery.metisMenuAutoOpen.js
Original file line number Diff line number Diff line change
@@ -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);
});
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"license": "MIT"
}

0 comments on commit 210e456

Please sign in to comment.