Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jQuery -> $ in src/metisMenu.js to fix import. #158

Merged
merged 2 commits into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"presets": [
["env", {
"modules": "umd",
"loose": true
}]
]
"presets": [
["env"]
],
"plugins": [
["transform-es2015-modules-umd", {
"globals": {
"jquery": "jQuery"
}
}]
]
}
293 changes: 160 additions & 133 deletions dist/metisMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
var mod = {
exports: {}
};
factory(global.jquery);
factory(global.jQuery);
global.metisMenu = mod.exports;
}
})(this, function (_jquery) {
Expand All @@ -42,6 +42,24 @@
}
}

var _createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}

return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();

var Util = function ($) {
var transition = false;

Expand Down Expand Up @@ -109,7 +127,7 @@
setTransitionEndSupport();

return Util;
}(jQuery);
}(_jquery2.default);

var MetisMenu = function ($) {

Expand Down Expand Up @@ -151,171 +169,180 @@
this.init();
}

MetisMenu.prototype.init = function init() {
var self = this;
$(this._element).find(this._config.parentTrigger + '.' + this._config.activeClass).has(this._config.subMenu).children(this._config.subMenu).attr('aria-expanded', true).addClass(this._config.collapseClass + ' ' + this._config.collapseInClass);

$(this._element).find(this._config.parentTrigger).not('.' + this._config.activeClass).has(this._config.subMenu).children(this._config.subMenu).attr('aria-expanded', false).addClass(this._config.collapseClass);
_createClass(MetisMenu, [{
key: 'init',
value: function init() {
var self = this;
$(this._element).find(this._config.parentTrigger + '.' + this._config.activeClass).has(this._config.subMenu).children(this._config.subMenu).attr('aria-expanded', true).addClass(this._config.collapseClass + ' ' + this._config.collapseInClass);

$(this._element).find(this._config.parentTrigger).not('.' + this._config.activeClass).has(this._config.subMenu).children(this._config.subMenu).attr('aria-expanded', false).addClass(this._config.collapseClass);

$(this._element).find(this._config.parentTrigger).has(this._config.subMenu).children(this._config.triggerElement).on(Event.CLICK_DATA_API, function (e) {
var _this = $(this);
var _parent = _this.parent(self._config.parentTrigger);
var _siblings = _parent.siblings(self._config.parentTrigger).children(self._config.triggerElement);
var _list = _parent.children(self._config.subMenu);
if (self._config.preventDefault) {
e.preventDefault();
}
if (_this.attr('aria-disabled') === 'true') {
return;
}
if (_parent.hasClass(self._config.activeClass)) {
_this.attr('aria-expanded', false);
self._hide(_list);
} else {
self._show(_list);
_this.attr('aria-expanded', true);
if (self._config.toggle) {
_siblings.attr('aria-expanded', false);
}
}

$(this._element).find(this._config.parentTrigger).has(this._config.subMenu).children(this._config.triggerElement).on(Event.CLICK_DATA_API, function (e) {
var _this = $(this);
var _parent = _this.parent(self._config.parentTrigger);
var _siblings = _parent.siblings(self._config.parentTrigger).children(self._config.triggerElement);
var _list = _parent.children(self._config.subMenu);
if (self._config.preventDefault) {
e.preventDefault();
}
if (_this.attr('aria-disabled') === 'true') {
return;
}
if (_parent.hasClass(self._config.activeClass)) {
_this.attr('aria-expanded', false);
self._hide(_list);
} else {
self._show(_list);
_this.attr('aria-expanded', true);
if (self._config.toggle) {
_siblings.attr('aria-expanded', false);
if (self._config.onTransitionStart) {
self._config.onTransitionStart(e);
}
});
}
}, {
key: '_show',
value: function _show(element) {
if (this._transitioning || $(element).hasClass(this._config.collapsingClass)) {
return;
}
var _this = this;
var _el = $(element);

var startEvent = $.Event(Event.SHOW);
_el.trigger(startEvent);

if (self._config.onTransitionStart) {
self._config.onTransitionStart(e);
if (startEvent.isDefaultPrevented()) {
return;
}
});
};

MetisMenu.prototype._show = function _show(element) {
if (this._transitioning || $(element).hasClass(this._config.collapsingClass)) {
return;
}
var _this = this;
var _el = $(element);
_el.parent(this._config.parentTrigger).addClass(this._config.activeClass);

var startEvent = $.Event(Event.SHOW);
_el.trigger(startEvent);
if (this._config.toggle) {
this._hide(_el.parent(this._config.parentTrigger).siblings().children(this._config.subMenu + '.' + this._config.collapseInClass).attr('aria-expanded', false));
}

if (startEvent.isDefaultPrevented()) {
return;
}
_el.removeClass(this._config.collapseClass).addClass(this._config.collapsingClass).height(0);

_el.parent(this._config.parentTrigger).addClass(this._config.activeClass);
this.setTransitioning(true);

if (this._config.toggle) {
this._hide(_el.parent(this._config.parentTrigger).siblings().children(this._config.subMenu + '.' + this._config.collapseInClass).attr('aria-expanded', false));
}
var complete = function complete() {
// check if disposed
if (!_this._config || !_this._element) {
return;
}
_el.removeClass(_this._config.collapsingClass).addClass(_this._config.collapseClass + ' ' + _this._config.collapseInClass).height('').attr('aria-expanded', true);

_el.removeClass(this._config.collapseClass).addClass(this._config.collapsingClass).height(0);
_this.setTransitioning(false);

this.setTransitioning(true);
_el.trigger(Event.SHOWN);
};

var complete = function complete() {
// check if disposed
if (!_this._config || !_this._element) {
if (!Util.supportsTransitionEnd()) {
complete();
return;
}
_el.removeClass(_this._config.collapsingClass).addClass(_this._config.collapseClass + ' ' + _this._config.collapseInClass).height('').attr('aria-expanded', true);

_this.setTransitioning(false);

_el.trigger(Event.SHOWN);
};

if (!Util.supportsTransitionEnd()) {
complete();
return;
}

_el.height(_el[0].scrollHeight).one(Util.TRANSITION_END, complete).mmEmulateTransitionEnd(TRANSITION_DURATION);
};

MetisMenu.prototype._hide = function _hide(element) {

if (this._transitioning || !$(element).hasClass(this._config.collapseInClass)) {
return;
_el.height(_el[0].scrollHeight).one(Util.TRANSITION_END, complete).mmEmulateTransitionEnd(TRANSITION_DURATION);
}
var _this = this;
var _el = $(element);
}, {
key: '_hide',
value: function _hide(element) {

var startEvent = $.Event(Event.HIDE);
_el.trigger(startEvent);

if (startEvent.isDefaultPrevented()) {
return;
}

_el.parent(this._config.parentTrigger).removeClass(this._config.activeClass);
_el.height(_el.height())[0].offsetHeight;

_el.addClass(this._config.collapsingClass).removeClass(this._config.collapseClass).removeClass(this._config.collapseInClass);
if (this._transitioning || !$(element).hasClass(this._config.collapseInClass)) {
return;
}
var _this = this;
var _el = $(element);

this.setTransitioning(true);
var startEvent = $.Event(Event.HIDE);
_el.trigger(startEvent);

var complete = function complete() {
// check if disposed
if (!_this._config || !_this._element) {
if (startEvent.isDefaultPrevented()) {
return;
}
if (_this._transitioning && _this._config.onTransitionEnd) {
_this._config.onTransitionEnd();
}

_this.setTransitioning(false);
_el.trigger(Event.HIDDEN);
_el.parent(this._config.parentTrigger).removeClass(this._config.activeClass);
_el.height(_el.height())[0].offsetHeight;

_el.removeClass(_this._config.collapsingClass).addClass(_this._config.collapseClass).attr('aria-expanded', false);
};
_el.addClass(this._config.collapsingClass).removeClass(this._config.collapseClass).removeClass(this._config.collapseInClass);

if (!Util.supportsTransitionEnd()) {
complete();
return;
}
this.setTransitioning(true);

_el.height() == 0 || _el.css('display') == 'none' ? complete() : _el.height(0).one(Util.TRANSITION_END, complete).mmEmulateTransitionEnd(TRANSITION_DURATION);
};

MetisMenu.prototype.setTransitioning = function setTransitioning(isTransitioning) {
this._transitioning = isTransitioning;
};
var complete = function complete() {
// check if disposed
if (!_this._config || !_this._element) {
return;
}
if (_this._transitioning && _this._config.onTransitionEnd) {
_this._config.onTransitionEnd();
}

MetisMenu.prototype.dispose = function dispose() {
$.removeData(this._element, DATA_KEY);
_this.setTransitioning(false);
_el.trigger(Event.HIDDEN);

$(this._element).find(this._config.parentTrigger).has(this._config.subMenu).children(this._config.triggerElement).off('click');
_el.removeClass(_this._config.collapsingClass).addClass(_this._config.collapseClass).attr('aria-expanded', false);
};

this._transitioning = null;
this._config = null;
this._element = null;
};
if (!Util.supportsTransitionEnd()) {
complete();
return;
}

MetisMenu.prototype._getConfig = function _getConfig(config) {
config = $.extend({}, Default, config);
return config;
};
_el.height() == 0 || _el.css('display') == 'none' ? complete() : _el.height(0).one(Util.TRANSITION_END, complete).mmEmulateTransitionEnd(TRANSITION_DURATION);
}
}, {
key: 'setTransitioning',
value: function setTransitioning(isTransitioning) {
this._transitioning = isTransitioning;
}
}, {
key: 'dispose',
value: function dispose() {
$.removeData(this._element, DATA_KEY);

MetisMenu._jQueryInterface = function _jQueryInterface(config) {
return this.each(function () {
var $this = $(this);
var data = $this.data(DATA_KEY);
var _config = $.extend({}, Default, $this.data(), (typeof config === 'undefined' ? 'undefined' : _typeof(config)) === 'object' && config);
$(this._element).find(this._config.parentTrigger).has(this._config.subMenu).children(this._config.triggerElement).off('click');

if (!data && /dispose/.test(config)) {
this.dispose();
}
this._transitioning = null;
this._config = null;
this._element = null;
}
}, {
key: '_getConfig',
value: function _getConfig(config) {
config = $.extend({}, Default, config);
return config;
}
}], [{
key: '_jQueryInterface',
value: function _jQueryInterface(config) {
return this.each(function () {
var $this = $(this);
var data = $this.data(DATA_KEY);
var _config = $.extend({}, Default, $this.data(), (typeof config === 'undefined' ? 'undefined' : _typeof(config)) === 'object' && config);

if (!data && /dispose/.test(config)) {
this.dispose();
}

if (!data) {
data = new MetisMenu(this, _config);
$this.data(DATA_KEY, data);
}
if (!data) {
data = new MetisMenu(this, _config);
$this.data(DATA_KEY, data);
}

if (typeof config === 'string') {
if (data[config] === undefined) {
throw new Error('No method named "' + config + '"');
if (typeof config === 'string') {
if (data[config] === undefined) {
throw new Error('No method named "' + config + '"');
}
data[config]();
}
data[config]();
}
});
};
});
}
}]);

return MetisMenu;
}();
Expand All @@ -333,5 +360,5 @@
return MetisMenu._jQueryInterface;
};
return MetisMenu;
}(jQuery);
}(_jquery2.default);
});
Loading