You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AdminLTE/dist/js/adminlte.js

619 lines
15 KiB

9 years ago
'use strict';
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; }; }();
9 years ago
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*!
* AdminLTE v3.0.0-alpha (https://almsaeedstudio.com)
9 years ago
* Copyright 2014-2016 Abdullah Almsaeed <abdullah@almsaeedstudio.com>
* Project website Almsaeed Studio (https://almsaeedstudio.com)
* Licensed under MIT (https://github.com/almasaeed2010/AdminLTE/blob/master/LICENSE)
*/
var Layout = function ($) {
9 years ago
'use strict';
9 years ago
/**
* Constants
* ====================================================
*/
9 years ago
var NAME = 'Layout';
var DATA_KEY = 'lte.layout';
var EVENT_KEY = '.' + DATA_KEY;
var JQUERY_NO_CONFLICT = $.fn[NAME];
9 years ago
var Event = {
SIDEBAR: 'sidebar'
};
var Selector = {
SIDEBAR: '.main-sidebar',
HEADER: '.main-header',
CONTENT: '.content-wrapper',
CONTENT_HEADER: '.content-header',
9 years ago
WRAPPER: '.wrapper',
CONTROL_SIDEBAR: '.control-sidebar',
LAYOUT_FIXED: '.layout-fixed',
FOOTER: '.main-footer'
};
var ClassName = {
HOLD: 'hold-transition',
SIDEBAR: 'main-sidebar',
LAYOUT_FIXED: 'layout-fixed'
};
/**
* Class Definition
* ====================================================
*/
var Layout = function () {
9 years ago
function Layout(element) {
_classCallCheck(this, Layout);
this._element = element;
this._init();
}
// Public
_createClass(Layout, [{
key: 'fixLayoutHeight',
value: function fixLayoutHeight() {
8 years ago
var heights = [$(window).height(), $(Selector.HEADER).outerHeight(), $(Selector.FOOTER).outerHeight(), $(Selector.SIDEBAR).height()],
max = this._max(heights);
9 years ago
8 years ago
$(Selector.CONTENT).css('min-height', max - (heights[1] + heights[2]));
9 years ago
}
// Private
}, {
key: '_init',
value: function _init() {
var _this = this;
// Enable transitions
9 years ago
$('body').removeClass(ClassName.HOLD);
// Activate layout height watcher
9 years ago
this.fixLayoutHeight();
8 years ago
$(Selector.SIDEBAR).on('collapsed.lte.treeview expanded.lte.treeview collapsed.lte.pushmenu expanded.lte.pushmenu', function () {
9 years ago
_this.fixLayoutHeight();
});
$(window).resize(function () {
_this.fixLayoutHeight();
});
}
}, {
key: '_max',
value: function _max(numbers) {
// Calculate the maximum number in a list
9 years ago
var max = 0;
numbers.forEach(function (v) {
if (v > max) {
max = v;
}
});
return max;
}
// Static
}], [{
key: '_jQueryInterface',
value: function _jQueryInterface(operation) {
return this.each(function () {
var data = $(this).data(DATA_KEY);
if (!data) {
data = new Layout(this);
$(this).data(DATA_KEY, data);
}
if (operation) {
data[operation]();
}
});
}
}]);
return Layout;
}();
9 years ago
/**
* jQuery API
* ====================================================
*/
$.fn[NAME] = Layout._jQueryInterface;
$.fn[NAME].Constructor = Layout;
$.fn[NAME].noConflict = function () {
$.fn[NAME] = JQUERY_NO_CONFLICT;
return Layout._jQueryInterface;
};
return Layout;
}(jQuery);
var Treeview = function ($) {
/**
* Constants
* ====================================================
*/
var NAME = 'Treeview';
var DATA_KEY = 'lte.treeview';
var EVENT_KEY = '.' + DATA_KEY;
var JQUERY_NO_CONFLICT = $.fn[NAME];
9 years ago
var Event = {
SELECTED: 'selected' + EVENT_KEY,
EXPANDED: 'expanded' + EVENT_KEY,
COLLAPSED: 'collapsed' + EVENT_KEY,
LOAD_DATA_API: 'load' + EVENT_KEY
};
var Selector = {
LI: '.nav-item',
LINK: '.nav-link',
9 years ago
TREEVIEW_MENU: '.nav-treeview',
OPEN: '.menu-open',
DATA_WIDGET: '[data-widget="treeview"]'
};
9 years ago
var ClassName = {
LI: 'nav-item',
LINK: 'nav-link',
TREEVIEW_MENU: 'nav-treeview',
OPEN: 'menu-open'
};
var Default = {
trigger: Selector.DATA_WIDGET + ' ' + Selector.LINK,
animationSpeed: 300,
8 years ago
accordion: true
9 years ago
};
/**
* Class Definition
* ====================================================
*/
var Treeview = function () {
function Treeview(element, config) {
_classCallCheck(this, Treeview);
this._config = config;
this._element = element;
}
// Public
9 years ago
_createClass(Treeview, [{
key: 'init',
value: function init() {
this._setupListeners();
}
}, {
key: 'expand',
value: function expand(treeviewMenu, parentLi) {
var _this2 = this;
var expandedEvent = $.Event(Event.EXPANDED);
if (this._config.accordion) {
var openMenuLi = parentLi.siblings(Selector.OPEN).first();
var openTreeview = openMenuLi.find(Selector.TREEVIEW_MENU).first();
this.collapse(openTreeview, openMenuLi);
}
treeviewMenu.slideDown(this._config.animationSpeed, function () {
parentLi.addClass(ClassName.OPEN);
$(_this2._element).trigger(expandedEvent);
});
}
}, {
key: 'collapse',
value: function collapse(treeviewMenu, parentLi) {
var _this3 = this;
var collapsedEvent = $.Event(Event.COLLAPSED);
treeviewMenu.slideUp(this._config.animationSpeed, function () {
parentLi.removeClass(ClassName.OPEN);
$(_this3._element).trigger(collapsedEvent);
treeviewMenu.find(Selector.OPEN + ' > ' + Selector.TREEVIEW_MENU).slideUp();
treeviewMenu.find(Selector.OPEN).removeClass(ClassName.OPEN);
});
}
}, {
key: 'collapseAll',
value: function collapseAll() {}
}, {
key: 'expandAll',
value: function expandAll() {}
}, {
key: 'toggle',
value: function toggle(event) {
var $relativeTarget = $(event.currentTarget);
var treeviewMenu = $relativeTarget.next();
if (!treeviewMenu.is(Selector.TREEVIEW_MENU)) {
return;
}
event.preventDefault();
var parentLi = $relativeTarget.parents(Selector.LI).first();
var isOpen = parentLi.hasClass(ClassName.OPEN);
if (isOpen) {
this.collapse($(treeviewMenu), parentLi);
} else {
this.expand($(treeviewMenu), parentLi);
}
}
// Private
9 years ago
}, {
key: '_setupListeners',
value: function _setupListeners() {
var _this4 = this;
9 years ago
$(document).on('click', this._config.trigger, function (event) {
_this4.toggle(event);
});
}
// Static
}], [{
key: '_jQueryInterface',
value: function _jQueryInterface(config) {
return this.each(function () {
9 years ago
var data = $(this).data(DATA_KEY);
var _config = $.extend({}, Default, $(this).data());
if (!data) {
data = new Treeview($(this), _config);
$(this).data(DATA_KEY, data);
}
if (config === 'init') {
data[config]();
}
});
}
}]);
return Treeview;
}();
9 years ago
/**
* Data API
* ====================================================
*/
$(window).on(Event.LOAD_DATA_API, function () {
$(Selector.DATA_WIDGET).each(function () {
var $treeview = $(this);
Treeview._jQueryInterface.call($treeview, 'init');
});
});
/**
* jQuery API
* ====================================================
*/
$.fn[NAME] = Treeview._jQueryInterface;
$.fn[NAME].Constructor = Treeview;
$.fn[NAME].noConflict = function () {
$.fn[NAME] = JQUERY_NO_CONFLICT;
return Treeview._jQueryInterface;
};
return Treeview;
}(jQuery);
var PushMenu = function ($) {
'use strict';
/**
* Constants
* ====================================================
*/
var NAME = 'PushMenu';
var DATA_KEY = 'lte.pushmenu';
var EVENT_KEY = '.' + DATA_KEY;
var JQUERY_NO_CONFLICT = $.fn[NAME];
var Event = {
COLLAPSED: 'collapsed' + EVENT_KEY,
9 years ago
SHOWN: 'shown' + EVENT_KEY
};
var Selector = {
COLLAPSED: 'sidebar-collapse',
TOGGLE_BUTTON: '[data-widget="pushmenu"]'
};
/**
* Class Definition
* ====================================================
*/
var PushMenu = function () {
9 years ago
function PushMenu(element) {
_classCallCheck(this, PushMenu);
9 years ago
this._element = element;
this._isShown = !$('body').hasClass(Selector.COLLAPSED) || $('body').hasClass('sidebar-open');
}
9 years ago
// Public
9 years ago
_createClass(PushMenu, [{
key: 'show',
value: function show() {
9 years ago
$('body').addClass('sidebar-open').removeClass(Selector.COLLAPSED);
this._isShown = true;
var shownEvent = $.Event(Event.SHOWN);
$(this._element).trigger(shownEvent);
}
}, {
key: 'collapse',
value: function collapse() {
9 years ago
$('body').removeClass('sidebar-open').addClass(Selector.COLLAPSED);
this._isShown = false;
var collapsedEvent = $.Event(Event.COLLAPSED);
$(this._element).trigger(collapsedEvent);
}
}, {
key: 'toggle',
value: function toggle() {
if (typeof this._isShown === 'undefined') {
9 years ago
this._isShown = !$('body').hasClass(Selector.COLLAPSED) || $('body').hasClass('sidebar-open');
}
if (this._isShown) {
this.collapse();
} else {
this.show();
}
}
// Static
}], [{
key: '_jQueryInterface',
value: function _jQueryInterface(operation) {
return this.each(function () {
var data = $(this).data(DATA_KEY);
if (!data) {
data = new PushMenu(this);
$(this).data(DATA_KEY, data);
}
if (operation) {
data[operation]();
}
});
}
}]);
return PushMenu;
}();
/**
* Data API
* ====================================================
*/
$(document).on('click', Selector.TOGGLE_BUTTON, function (event) {
event.preventDefault();
9 years ago
var button = event.currentTarget;
if ($(button).data('widget') !== 'pushmenu') {
button = $(button).closest(Selector.TOGGLE_BUTTON);
}
PushMenu._jQueryInterface.call($(button), 'toggle');
});
/**
* jQuery API
* ====================================================
*/
$.fn[NAME] = PushMenu._jQueryInterface;
$.fn[NAME].Constructor = PushMenu;
$.fn[NAME].noConflict = function () {
$.fn[NAME] = JQUERY_NO_CONFLICT;
return PushMenu._jQueryInterface;
};
return PushMenu;
}(jQuery);
var Widget = function ($) {
'use strict';
var Widget = function () {
9 years ago
function Widget(element) {
_classCallCheck(this, Widget);
9 years ago
this._element = element;
}
9 years ago
_createClass(Widget, null, [{
key: '_jQueryInterface',
value: function _jQueryInterface(element) {
var $this = $(element);
$this.show();
}
}]);
return Widget;
}();
return Widget;
}(jQuery);
var ControlSidebar = function ($) {
'use strict';
/**
* Constants
* ====================================================
*/
var NAME = 'ControlSidebar';
var DATA_KEY = 'lte.control.sidebar';
var EVENT_KEY = '.' + DATA_KEY;
var JQUERY_NO_CONFLICT = $.fn[NAME];
var DATA_API_KEY = '.data-api';
var Event = {
CLICK_DATA_API: 'click' + EVENT_KEY + DATA_API_KEY
};
var Selector = {
CONTROL_SIDEBAR: '.control-sidebar',
DATA_TOGGLE: '[data-widget="control-sidebar"]'
};
var ClassName = {
CONTROL_SIDEBAR_OPEN: 'control-sidebar-open',
CONTROL_SIDEBAR_SLIDE: 'control-sidebar-slide-open'
};
var Default = {
slide: true
};
/**
* Class Definition
* ====================================================
*/
var ControlSidebar = function () {
function ControlSidebar(element, config) {
_classCallCheck(this, ControlSidebar);
this._element = element;
this._config = this._getConfig(config);
}
// Public
_createClass(ControlSidebar, [{
key: 'show',
value: function show() {
console.log('showing', this._config.slide);
// Show the control sidebar
if (this._config.slide) {
$('body').removeClass(ClassName.CONTROL_SIDEBAR_SLIDE);
} else {
$('body').removeClass(ClassName.CONTROL_SIDEBAR_OPEN);
}
}
}, {
key: 'collapse',
value: function collapse() {
// Collapse the control sidebar
if (this._config.slide) {
$('body').addClass(ClassName.CONTROL_SIDEBAR_SLIDE);
} else {
$('body').addClass(ClassName.CONTROL_SIDEBAR_OPEN);
}
}
}, {
key: 'toggle',
value: function toggle() {
if ($('body').hasClass(ClassName.CONTROL_SIDEBAR_OPEN) || $('body').hasClass(ClassName.CONTROL_SIDEBAR_SLIDE)) {
// Open the control sidebar
this.show();
} else {
// Close the control sidebar
this.collapse();
}
}
// Private
}, {
key: '_getConfig',
value: function _getConfig(config) {
return $.extend({}, Default, config);
}
// Static
}], [{
key: '_jQueryInterface',
value: function _jQueryInterface(operation) {
return this.each(function () {
var data = $(this).data(DATA_KEY);
if (!data) {
data = new ControlSidebar(this, $(this).data());
$(this).data(DATA_KEY, data);
}
if (data[operation] === undefined) {
throw new Error(operation + ' is not a function');
}
data[operation]();
});
}
}]);
return ControlSidebar;
}();
/**
*
* Data Api implementation
* ====================================================
*/
$(document).on('click', Selector.DATA_TOGGLE, function (event) {
event.preventDefault();
ControlSidebar._jQueryInterface.call($(this), 'toggle');
});
/**
* jQuery API
* ====================================================
*/
$.fn[NAME] = ControlSidebar._jQueryInterface;
$.fn[NAME].Constructor = ControlSidebar;
$.fn[NAME].noConflict = function () {
$.fn[NAME] = JQUERY_NO_CONFLICT;
return ControlSidebar._jQueryInterface;
};
return ControlSidebar;
}(jQuery);
9 years ago
//# sourceMappingURL=adminlte.js.map