AdminLTE/dist/js/app.js

759 lines
22 KiB
JavaScript
Raw Normal View History

2015-03-04 00:59:20 +00:00
/*! AdminLTE app.js
* ================
2015-02-01 21:25:09 +00:00
* Main JS application file for AdminLTE v2. This file
* should be included in all pages. It controls some layout
* options and implements exclusive AdminLTE plugins.
*
* @Author Almsaeed Studio
* @Support <http://www.almsaeedstudio.com>
* @Email <support@almsaeedstudio.com>
2015-10-23 14:50:49 +00:00
* @version 2.3.2
2015-02-01 21:25:09 +00:00
* @license MIT <http://opensource.org/licenses/MIT>
*/
//Make sure jQuery has been loaded before app.js
if (typeof jQuery === "undefined") {
throw new Error("AdminLTE requires jQuery");
}
/* AdminLTE
*
* @type Object
* @description $.AdminLTE is the main object for the template's app.
2015-03-02 23:41:47 +00:00
* It's used for implementing functions and options related
* to the template. Keeping everything wrapped in an object
* prevents conflict with other plugins and is a better
* way to organize our code.
2015-02-01 21:25:09 +00:00
*/
2015-02-20 21:46:03 +00:00
$.AdminLTE = {};
2015-02-01 21:25:09 +00:00
/* --------------------
* - AdminLTE Options -
* --------------------
* Modify these options to suit your implementation
*/
$.AdminLTE.options = {
//Add slimscroll to navbar menus
//This requires you to load the slimscroll plugin
//in every page before app.js
navbarMenuSlimscroll: true,
navbarMenuSlimscrollWidth: "3px", //The width of the scroll bar
navbarMenuHeight: "200px", //The height of the inner menu
2015-07-12 13:42:55 +00:00
//General animation speed for JS animated elements such as box collapse/expand and
2015-05-23 10:09:35 +00:00
//sidebar treeview slide up/down. This options accepts an integer as milliseconds,
//'fast', 'normal', or 'slow'
animationSpeed: 500,
2015-02-01 21:25:09 +00:00
//Sidebar push menu toggle button selector
sidebarToggleSelector: "[data-toggle='offcanvas']",
//Activate sidebar push menu
sidebarPushMenu: true,
2015-02-11 00:53:16 +00:00
//Activate sidebar slimscroll if the fixed layout is set (requires SlimScroll Plugin)
sidebarSlimScroll: true,
2015-04-19 12:21:03 +00:00
//Enable sidebar expand on hover effect for sidebar mini
//This option is forced to true if both the fixed layout and sidebar mini
//are used together
sidebarExpandOnHover: false,
2015-02-01 21:25:09 +00:00
//BoxRefresh Plugin
enableBoxRefresh: true,
//Bootstrap.js tooltip
enableBSToppltip: true,
BSTooltipSelector: "[data-toggle='tooltip']",
//Enable Fast Click. Fastclick.js creates a more
2015-03-02 23:41:47 +00:00
//native touch experience with touch devices. If you
2015-03-04 00:59:20 +00:00
//choose to enable the plugin, make sure you load the script
//before AdminLTE's app.js
enableFastclick: true,
2015-03-28 18:44:48 +00:00
//Control Sidebar Options
enableControlSidebar: true,
controlSidebarOptions: {
//Which button should trigger the open/close event
toggleBtnSelector: "[data-toggle='control-sidebar']",
//The sidebar selector
selector: ".control-sidebar",
2015-03-29 00:39:26 +00:00
//Enable slide over content
slide: true
2015-03-28 18:44:48 +00:00
},
2015-02-01 21:25:09 +00:00
//Box Widget Plugin. Enable this plugin
//to allow boxes to be collapsed and/or removed
enableBoxWidget: true,
//Box Widget plugin options
boxWidgetOptions: {
boxWidgetIcons: {
2015-04-04 00:52:09 +00:00
//Collapse icon
collapse: 'fa-minus',
//Open icon
open: 'fa-plus',
//Remove icon
remove: 'fa-times'
2015-02-01 21:25:09 +00:00
},
boxWidgetSelectors: {
//Remove button selector
remove: '[data-widget="remove"]',
//Collapse button selector
collapse: '[data-widget="collapse"]'
}
},
//Direct Chat plugin options
directChat: {
//Enable direct chat by default
enable: true,
//The button to open and close the chat contacts pane
contactToggleSelector: '[data-widget="chat-pane-toggle"]'
},
2015-02-01 21:25:09 +00:00
//Define the set of colors to use globally around the website
colors: {
lightBlue: "#3c8dbc",
red: "#f56954",
green: "#00a65a",
aqua: "#00c0ef",
yellow: "#f39c12",
blue: "#0073b7",
navy: "#001F3F",
teal: "#39CCCC",
olive: "#3D9970",
lime: "#01FF70",
orange: "#FF851B",
fuchsia: "#F012BE",
purple: "#8E24AA",
maroon: "#D81B60",
black: "#222222",
2015-02-06 23:40:49 +00:00
gray: "#d2d6de"
2015-03-04 00:59:20 +00:00
},
//The standard screen sizes that bootstrap uses.
//If you change these in the variables.less file, change
//them here too.
screenSizes: {
xs: 480,
sm: 768,
md: 992,
lg: 1200
2015-02-01 21:25:09 +00:00
}
};
/* ------------------
* - Implementation -
* ------------------
* The next block of code implements AdminLTE's
* functions and plugins as specified by the
* options above.
*/
$(function () {
2015-07-25 19:06:16 +00:00
"use strict";
2015-08-16 20:31:59 +00:00
//Fix for IE page transitions
$("body").removeClass("hold-transition");
2015-04-19 15:16:32 +00:00
//Extend options if external options exist
if (typeof AdminLTEOptions !== "undefined") {
$.extend(true,
2015-09-19 18:05:54 +00:00
$.AdminLTE.options,
AdminLTEOptions);
2015-04-19 15:16:32 +00:00
}
2015-02-01 21:25:09 +00:00
//Easy access to options
var o = $.AdminLTE.options;
2015-03-17 15:23:28 +00:00
//Set up the object
_init();
2015-02-01 21:25:09 +00:00
//Activate the layout maker
$.AdminLTE.layout.activate();
2015-02-06 21:43:14 +00:00
//Enable sidebar tree view controls
$.AdminLTE.tree('.sidebar');
2015-03-28 18:44:48 +00:00
//Enable control sidebar
if (o.enableControlSidebar) {
2015-03-29 00:39:26 +00:00
$.AdminLTE.controlSidebar.activate();
2015-03-28 18:44:48 +00:00
}
2015-02-01 21:25:09 +00:00
//Add slimscroll to navbar dropdown
if (o.navbarMenuSlimscroll && typeof $.fn.slimscroll != 'undefined') {
$(".navbar .menu").slimscroll({
2015-04-10 01:06:47 +00:00
height: o.navbarMenuHeight,
2015-02-01 21:25:09 +00:00
alwaysVisible: false,
2015-04-10 01:06:47 +00:00
size: o.navbarMenuSlimscrollWidth
2015-02-01 21:25:09 +00:00
}).css("width", "100%");
}
//Activate sidebar push menu
if (o.sidebarPushMenu) {
2015-04-19 12:21:03 +00:00
$.AdminLTE.pushMenu.activate(o.sidebarToggleSelector);
2015-02-01 21:25:09 +00:00
}
//Activate Bootstrap tooltip
if (o.enableBSToppltip) {
$('body').tooltip({
selector: o.BSTooltipSelector
});
2015-02-01 21:25:09 +00:00
}
//Activate box widget
if (o.enableBoxWidget) {
$.AdminLTE.boxWidget.activate();
}
//Activate fast click
if (o.enableFastclick && typeof FastClick != 'undefined') {
FastClick.attach(document.body);
}
2015-02-01 21:25:09 +00:00
//Activate direct chat widget
if (o.directChat.enable) {
2015-07-21 03:02:35 +00:00
$(document).on('click', o.directChat.contactToggleSelector, function () {
var box = $(this).parents('.direct-chat').first();
box.toggleClass('direct-chat-contacts-open');
});
}
2015-02-01 21:25:09 +00:00
/*
* INITIALIZE BUTTON TOGGLE
* ------------------------
*/
$('.btn-group[data-toggle="btn-toggle"]').each(function () {
var group = $(this);
2015-04-09 23:43:40 +00:00
$(this).find(".btn").on('click', function (e) {
2015-02-01 21:25:09 +00:00
group.find(".btn.active").removeClass("active");
$(this).addClass("active");
e.preventDefault();
});
});
});
2015-03-17 15:23:28 +00:00
/* ----------------------------------
* - Initialize the AdminLTE Object -
* ----------------------------------
2015-02-01 21:25:09 +00:00
* All AdminLTE functions are implemented below.
*/
2015-03-17 15:23:28 +00:00
function _init() {
2015-07-25 19:06:16 +00:00
'use strict';
2015-03-17 15:23:28 +00:00
/* Layout
* ======
* Fixes the layout height in case min-height fails.
*
* @type Object
* @usage $.AdminLTE.layout.activate()
* $.AdminLTE.layout.fix()
* $.AdminLTE.layout.fixSidebar()
*/
$.AdminLTE.layout = {
activate: function () {
var _this = this;
2015-02-01 21:25:09 +00:00
_this.fix();
_this.fixSidebar();
2015-03-17 15:23:28 +00:00
$(window, ".wrapper").resize(function () {
_this.fix();
_this.fixSidebar();
});
},
fix: function () {
//Get window height and the wrapper height
var neg = $('.main-header').outerHeight() + $('.main-footer').outerHeight();
var window_height = $(window).height();
var sidebar_height = $(".sidebar").height();
//Set the min-height of the content and sidebar based on the
//the height of the document.
if ($("body").hasClass("fixed")) {
$(".content-wrapper, .right-side").css('min-height', window_height - $('.main-footer').outerHeight());
2015-02-07 16:44:45 +00:00
} else {
2015-04-19 22:41:56 +00:00
var postSetWidth;
2015-03-17 15:23:28 +00:00
if (window_height >= sidebar_height) {
$(".content-wrapper, .right-side").css('min-height', window_height - neg);
2015-04-19 22:41:56 +00:00
postSetWidth = window_height - neg;
2015-03-17 15:23:28 +00:00
} else {
$(".content-wrapper, .right-side").css('min-height', sidebar_height);
2015-04-19 22:41:56 +00:00
postSetWidth = sidebar_height;
2015-03-17 15:23:28 +00:00
}
2015-04-19 22:41:56 +00:00
//Fix for the control sidebar height
var controlSidebar = $($.AdminLTE.options.controlSidebarOptions.selector);
if (typeof controlSidebar !== "undefined") {
if (controlSidebar.height() > postSetWidth)
2015-04-19 22:41:56 +00:00
$(".content-wrapper, .right-side").css('min-height', controlSidebar.height());
}
2015-02-07 16:44:45 +00:00
}
2015-03-17 15:23:28 +00:00
},
fixSidebar: function () {
//Make sure the body tag has the .fixed class
if (!$("body").hasClass("fixed")) {
if (typeof $.fn.slimScroll != 'undefined') {
$(".sidebar").slimScroll({destroy: true}).height("auto");
}
return;
2015-07-25 19:06:16 +00:00
} else if (typeof $.fn.slimScroll == 'undefined' && window.console) {
window.console.error("Error: the fixed layout requires the slimscroll plugin!");
2015-02-01 21:25:09 +00:00
}
2015-03-17 15:23:28 +00:00
//Enable slimscroll for fixed layout
if ($.AdminLTE.options.sidebarSlimScroll) {
if (typeof $.fn.slimScroll != 'undefined') {
2015-04-22 21:13:31 +00:00
//Destroy if it exists
2015-03-17 15:23:28 +00:00
$(".sidebar").slimScroll({destroy: true}).height("auto");
//Add slimscroll
$(".sidebar").slimscroll({
height: ($(window).height() - $(".main-header").height()) + "px",
color: "rgba(0,0,0,0.2)",
size: "3px"
});
}
2015-02-01 21:25:09 +00:00
}
}
2015-03-17 15:23:28 +00:00
};
2015-02-01 21:25:09 +00:00
2015-03-17 15:23:28 +00:00
/* PushMenu()
* ==========
* Adds the push menu functionality to the sidebar.
*
* @type Function
* @usage: $.AdminLTE.pushMenu("[data-toggle='offcanvas']")
*/
2015-04-19 12:21:03 +00:00
$.AdminLTE.pushMenu = {
activate: function (toggleBtn) {
//Get the screen sizes
var screenSizes = $.AdminLTE.options.screenSizes;
2015-03-04 00:59:20 +00:00
2015-04-19 12:21:03 +00:00
//Enable sidebar toggle
$(document).on('click', toggleBtn, function (e) {
2015-04-19 12:21:03 +00:00
e.preventDefault();
2015-03-04 00:59:20 +00:00
2015-04-19 12:21:03 +00:00
//Enable sidebar push menu
if ($(window).width() > (screenSizes.sm - 1)) {
if ($("body").hasClass('sidebar-collapse')) {
$("body").removeClass('sidebar-collapse').trigger('expanded.pushMenu');
} else {
$("body").addClass('sidebar-collapse').trigger('collapsed.pushMenu');
}
2015-04-19 12:21:03 +00:00
}
//Handle sidebar push menu for small screens
else {
if ($("body").hasClass('sidebar-open')) {
$("body").removeClass('sidebar-open').removeClass('sidebar-collapse').trigger('collapsed.pushMenu');
2015-04-19 12:21:03 +00:00
} else {
$("body").addClass('sidebar-open').trigger('expanded.pushMenu');
2015-04-19 12:21:03 +00:00
}
}
});
$(".content-wrapper").click(function () {
//Enable hide menu when clicking on the content-wrapper on small screens
if ($(window).width() <= (screenSizes.sm - 1) && $("body").hasClass("sidebar-open")) {
2015-03-17 15:23:28 +00:00
$("body").removeClass('sidebar-open');
}
2015-04-19 12:21:03 +00:00
});
2015-02-07 21:01:45 +00:00
2015-04-19 12:21:03 +00:00
//Enable expand on hover for sidebar mini
if ($.AdminLTE.options.sidebarExpandOnHover
2015-09-19 18:05:54 +00:00
|| ($('body').hasClass('fixed')
&& $('body').hasClass('sidebar-mini'))) {
2015-04-19 12:21:03 +00:00
this.expandOnHover();
2015-03-17 15:23:28 +00:00
}
2015-04-19 12:21:03 +00:00
},
expandOnHover: function () {
var _this = this;
var screenWidth = $.AdminLTE.options.screenSizes.sm - 1;
//Expand sidebar on hover
$('.main-sidebar').hover(function () {
if ($('body').hasClass('sidebar-mini')
2015-09-19 18:05:54 +00:00
&& $("body").hasClass('sidebar-collapse')
&& $(window).width() > screenWidth) {
2015-04-19 12:21:03 +00:00
_this.expand();
}
}, function () {
if ($('body').hasClass('sidebar-mini')
2015-09-19 18:05:54 +00:00
&& $('body').hasClass('sidebar-expanded-on-hover')
&& $(window).width() > screenWidth) {
2015-04-19 12:21:03 +00:00
_this.collapse();
}
});
},
expand: function () {
$("body").removeClass('sidebar-collapse').addClass('sidebar-expanded-on-hover');
},
collapse: function () {
if ($('body').hasClass('sidebar-expanded-on-hover')) {
$('body').removeClass('sidebar-expanded-on-hover').addClass('sidebar-collapse');
}
}
2015-03-17 15:23:28 +00:00
};
2015-03-04 00:59:20 +00:00
2015-03-17 15:23:28 +00:00
/* Tree()
* ======
* Converts the sidebar into a multilevel
* tree view menu.
*
* @type Function
* @Usage: $.AdminLTE.tree('.sidebar')
*/
$.AdminLTE.tree = function (menu) {
var _this = this;
2015-05-23 10:09:35 +00:00
var animationSpeed = $.AdminLTE.options.animationSpeed;
2016-02-01 18:44:51 +00:00
$(document).on('click', menu + ' li a', function (e) {
2015-03-17 15:23:28 +00:00
//Get the clicked link and the next element
var $this = $(this);
var checkElement = $this.next();
2015-02-01 21:25:09 +00:00
2015-03-17 15:23:28 +00:00
//Check if the next element is a menu and is visible
if ((checkElement.is('.treeview-menu')) && (checkElement.is(':visible')) && (!$('body').hasClass('sidebar-collapse'))) {
2015-03-17 15:23:28 +00:00
//Close the menu
2015-05-23 10:09:35 +00:00
checkElement.slideUp(animationSpeed, function () {
2015-03-17 15:23:28 +00:00
checkElement.removeClass('menu-open');
//Fix the layout in case the sidebar stretches over the height of the window
//_this.layout.fix();
});
checkElement.parent("li").removeClass("active");
}
//If the menu is not visible
else if ((checkElement.is('.treeview-menu')) && (!checkElement.is(':visible'))) {
//Get the parent menu
var parent = $this.parents('ul').first();
//Close all open menus within the parent
2015-05-23 10:09:35 +00:00
var ul = parent.find('ul:visible').slideUp(animationSpeed);
2015-03-17 15:23:28 +00:00
//Remove the menu-open class from the parent
ul.removeClass('menu-open');
//Get the parent li
var parent_li = $this.parent("li");
2015-02-01 21:25:09 +00:00
2015-03-17 15:23:28 +00:00
//Open the target menu and add the menu-open class
2015-05-23 10:09:35 +00:00
checkElement.slideDown(animationSpeed, function () {
2015-03-17 15:23:28 +00:00
//Add the class active to the parent li
checkElement.addClass('menu-open');
parent.find('li.active').removeClass('active');
parent_li.addClass('active');
//Fix the layout in case the sidebar stretches over the height of the window
_this.layout.fix();
});
}
//if this isn't a link, prevent the page from being redirected
if (checkElement.is('.treeview-menu')) {
e.preventDefault();
}
2015-02-01 21:25:09 +00:00
});
2015-03-17 15:23:28 +00:00
};
2015-03-28 18:44:48 +00:00
/* ControlSidebar
* ==============
2015-03-29 00:39:26 +00:00
* Adds functionality to the right sidebar
*
* @type Object
2015-03-28 18:44:48 +00:00
* @usage $.AdminLTE.controlSidebar.activate(options)
*/
$.AdminLTE.controlSidebar = {
2015-03-28 18:44:48 +00:00
//instantiate the object
2015-03-29 00:39:26 +00:00
activate: function () {
2015-03-28 18:44:48 +00:00
//Get the object
var _this = this;
//Update options
2015-03-29 00:39:26 +00:00
var o = $.AdminLTE.options.controlSidebarOptions;
2015-03-28 18:44:48 +00:00
//Get the sidebar
var sidebar = $(o.selector);
//The toggle button
var btn = $(o.toggleBtnSelector);
2015-03-29 00:39:26 +00:00
2015-03-28 18:44:48 +00:00
//Listen to the click event
2015-04-09 23:43:40 +00:00
btn.on('click', function (e) {
2015-03-28 18:44:48 +00:00
e.preventDefault();
2015-04-09 22:52:51 +00:00
//If the sidebar is not open
2015-03-29 00:39:26 +00:00
if (!sidebar.hasClass('control-sidebar-open')
2015-09-19 18:05:54 +00:00
&& !$('body').hasClass('control-sidebar-open')) {
2015-03-28 18:44:48 +00:00
//Open the sidebar
2015-03-29 00:39:26 +00:00
_this.open(sidebar, o.slide);
2015-03-28 18:44:48 +00:00
} else {
2015-03-29 00:39:26 +00:00
_this.close(sidebar, o.slide);
2015-03-28 18:44:48 +00:00
}
});
2015-04-08 01:06:05 +00:00
//If the body has a boxed layout, fix the sidebar bg position
2015-04-09 22:52:51 +00:00
var bg = $(".control-sidebar-bg");
_this._fix(bg);
2015-04-19 12:21:03 +00:00
2015-07-12 13:42:55 +00:00
//If the body has a fixed layout, make the control sidebar fixed
2015-04-19 12:21:03 +00:00
if ($('body').hasClass('fixed')) {
_this._fixForFixed(sidebar);
} else {
2015-04-22 21:13:31 +00:00
//If the content height is less than the sidebar's height, force max height
2015-04-19 12:21:03 +00:00
if ($('.content-wrapper, .right-side').height() < sidebar.height()) {
_this._fixForContent(sidebar);
}
}
},
2015-03-28 18:44:48 +00:00
//Open the control sidebar
2015-03-29 00:39:26 +00:00
open: function (sidebar, slide) {
2015-04-09 22:52:51 +00:00
//Slide over content
if (slide) {
2015-03-29 00:39:26 +00:00
sidebar.addClass('control-sidebar-open');
} else {
2015-07-12 13:42:55 +00:00
//Push the content by adding the open class to the body instead
//of the sidebar itself
2015-03-29 00:39:26 +00:00
$('body').addClass('control-sidebar-open');
}
},
2015-03-28 18:44:48 +00:00
//Close the control sidebar
2015-03-29 00:39:26 +00:00
close: function (sidebar, slide) {
if (slide) {
sidebar.removeClass('control-sidebar-open');
} else {
$('body').removeClass('control-sidebar-open');
}
2015-04-08 01:06:05 +00:00
},
_fix: function (sidebar) {
var _this = this;
2015-04-09 22:52:51 +00:00
if ($("body").hasClass('layout-boxed')) {
sidebar.css('position', 'absolute');
sidebar.height($(".wrapper").height());
$(window).resize(function () {
_this._fix(sidebar);
});
} else {
sidebar.css({
'position': 'fixed',
'height': 'auto'
});
2015-04-09 22:52:51 +00:00
}
2015-04-19 12:21:03 +00:00
},
_fixForFixed: function (sidebar) {
sidebar.css({
'position': 'fixed',
'max-height': '100%',
'overflow': 'auto',
'padding-bottom': '50px'
});
},
_fixForContent: function (sidebar) {
$(".content-wrapper, .right-side").css('min-height', sidebar.height());
2015-03-28 18:44:48 +00:00
}
};
2015-02-01 21:25:09 +00:00
2015-03-17 15:23:28 +00:00
/* BoxWidget
* =========
2015-04-22 21:13:31 +00:00
* BoxWidget is a plugin to handle collapsing and
2015-03-17 15:23:28 +00:00
* removing boxes from the screen.
*
* @type Object
* @usage $.AdminLTE.boxWidget.activate()
2015-04-22 21:13:31 +00:00
* Set all your options in the main $.AdminLTE.options object
2015-03-17 15:23:28 +00:00
*/
$.AdminLTE.boxWidget = {
2015-04-04 00:52:09 +00:00
selectors: $.AdminLTE.options.boxWidgetOptions.boxWidgetSelectors,
icons: $.AdminLTE.options.boxWidgetOptions.boxWidgetIcons,
animationSpeed: $.AdminLTE.options.animationSpeed,
2015-05-21 09:06:14 +00:00
activate: function (_box) {
2015-03-17 15:23:28 +00:00
var _this = this;
if (!_box) {
2015-05-21 09:06:14 +00:00
_box = document; // activate all boxes per default
}
2015-03-17 15:23:28 +00:00
//Listen for collapse event triggers
2015-07-21 03:02:35 +00:00
$(_box).on('click', _this.selectors.collapse, function (e) {
2015-03-17 15:23:28 +00:00
e.preventDefault();
_this.collapse($(this));
2015-02-01 21:25:09 +00:00
});
2015-03-17 15:23:28 +00:00
//Listen for remove event triggers
2015-07-21 03:02:35 +00:00
$(_box).on('click', _this.selectors.remove, function (e) {
2015-03-17 15:23:28 +00:00
e.preventDefault();
_this.remove($(this));
2015-02-01 21:25:09 +00:00
});
2015-03-17 15:23:28 +00:00
},
collapse: function (element) {
2015-04-04 00:52:09 +00:00
var _this = this;
2015-03-17 15:23:28 +00:00
//Find the box parent
var box = element.parents(".box").first();
//Find the body and the footer
var box_content = box.find("> .box-body, > .box-footer, > form >.box-body, > form > .box-footer");
2015-03-17 15:23:28 +00:00
if (!box.hasClass("collapsed-box")) {
2015-04-08 01:06:05 +00:00
//Convert minus into plus
2015-04-04 00:52:09 +00:00
element.children(":first")
2015-09-19 18:05:54 +00:00
.removeClass(_this.icons.collapse)
.addClass(_this.icons.open);
2015-04-04 00:52:09 +00:00
//Hide the content
2015-05-23 10:09:35 +00:00
box_content.slideUp(_this.animationSpeed, function () {
2015-03-17 15:23:28 +00:00
box.addClass("collapsed-box");
});
} else {
//Convert plus into minus
2015-04-04 00:52:09 +00:00
element.children(":first")
2015-09-19 18:05:54 +00:00
.removeClass(_this.icons.open)
.addClass(_this.icons.collapse);
2015-04-04 00:52:09 +00:00
//Show the content
2015-05-23 10:09:35 +00:00
box_content.slideDown(_this.animationSpeed, function () {
2015-03-17 15:23:28 +00:00
box.removeClass("collapsed-box");
});
}
},
remove: function (element) {
2015-03-17 15:23:28 +00:00
//Find the box parent
var box = element.parents(".box").first();
2015-05-23 10:09:35 +00:00
box.slideUp(this.animationSpeed);
2015-04-04 00:52:09 +00:00
}
2015-03-17 15:23:28 +00:00
};
}
2015-02-01 21:25:09 +00:00
/* ------------------
* - Custom Plugins -
* ------------------
* All custom plugins are defined below.
*/
/*
* BOX REFRESH BUTTON
* ------------------
2015-04-22 21:13:31 +00:00
* This is a custom plugin to use with the component BOX. It allows you to add
2015-02-01 21:25:09 +00:00
* a refresh button to the box. It converts the box's state to a loading state.
*
2015-03-02 23:41:47 +00:00
* @type plugin
2015-02-01 21:25:09 +00:00
* @usage $("#box-widget").boxRefresh( options );
*/
(function ($) {
2015-07-25 19:06:16 +00:00
"use strict";
2015-02-01 21:25:09 +00:00
$.fn.boxRefresh = function (options) {
// Render options
var settings = $.extend({
2015-04-22 21:13:31 +00:00
//Refresh button selector
2015-02-01 21:25:09 +00:00
trigger: ".refresh-btn",
//File source to be loaded (e.g: ajax/src.php)
source: "",
//Callbacks
onLoadStart: function (box) {
2015-07-25 19:06:16 +00:00
return box;
2015-02-01 21:25:09 +00:00
}, //Right after the button has been clicked
onLoadDone: function (box) {
2015-07-25 19:06:16 +00:00
return box;
2015-02-01 21:25:09 +00:00
} //When the source has been loaded
}, options);
//The overlay
2015-03-02 23:41:47 +00:00
var overlay = $('<div class="overlay"><div class="fa fa-refresh fa-spin"></div></div>');
2015-02-01 21:25:09 +00:00
return this.each(function () {
//if a source is specified
if (settings.source === "") {
2015-07-25 19:06:16 +00:00
if (window.console) {
window.console.log("Please specify a source first - boxRefresh()");
2015-02-01 21:25:09 +00:00
}
return;
}
//the box
var box = $(this);
//the button
var rBtn = box.find(settings.trigger).first();
//On trigger click
2015-04-09 23:43:40 +00:00
rBtn.on('click', function (e) {
2015-02-01 21:25:09 +00:00
e.preventDefault();
//Add loading overlay
start(box);
//Perform ajax call
box.find(".box-body").load(settings.source, function () {
done(box);
});
});
});
function start(box) {
//Add overlay and loading img
box.append(overlay);
settings.onLoadStart.call(box);
}
function done(box) {
//Remove overlay and loading img
box.find(overlay).remove();
settings.onLoadDone.call(box);
}
};
})(jQuery);
2015-09-21 12:41:29 +00:00
/*
* EXPLICIT BOX CONTROLS
2015-05-21 09:06:14 +00:00
* -----------------------
* This is a custom plugin to use with the component BOX. It allows you to activate
2015-09-21 12:41:29 +00:00
* a box inserted in the DOM after the app.js was loaded, toggle and remove box.
2015-05-21 09:06:14 +00:00
*
* @type plugin
* @usage $("#box-widget").activateBox();
2015-09-21 12:41:29 +00:00
* @usage $("#box-widget").toggleBox();
* @usage $("#box-widget").removeBox();
2015-05-21 09:06:14 +00:00
*/
(function ($) {
2015-07-25 19:06:16 +00:00
'use strict';
2015-05-21 09:06:14 +00:00
$.fn.activateBox = function () {
$.AdminLTE.boxWidget.activate(this);
};
2015-09-21 12:41:29 +00:00
$.fn.toggleBox = function(){
var button = $($.AdminLTE.boxWidget.selectors.collapse, this);
$.AdminLTE.boxWidget.collapse(button);
};
2015-09-21 12:41:29 +00:00
$.fn.removeBox = function(){
var button = $($.AdminLTE.boxWidget.selectors.remove, this);
$.AdminLTE.boxWidget.remove(button);
};
2015-05-21 09:06:14 +00:00
})(jQuery);
2015-02-01 21:25:09 +00:00
/*
* TODO LIST CUSTOM PLUGIN
* -----------------------
* This plugin depends on iCheck plugin for checkbox and radio inputs
*
* @type plugin
* @usage $("#todo-widget").todolist( options );
*/
(function ($) {
2015-07-25 19:06:16 +00:00
'use strict';
2015-02-01 21:25:09 +00:00
$.fn.todolist = function (options) {
// Render options
var settings = $.extend({
//When the user checks the input
onCheck: function (ele) {
2015-07-25 19:06:16 +00:00
return ele;
2015-02-01 21:25:09 +00:00
},
//When the user unchecks the input
onUncheck: function (ele) {
2015-07-25 19:06:16 +00:00
return ele;
2015-02-01 21:25:09 +00:00
}
}, options);
return this.each(function () {
if (typeof $.fn.iCheck != 'undefined') {
2015-07-25 19:06:16 +00:00
$('input', this).on('ifChecked', function () {
2015-02-01 21:25:09 +00:00
var ele = $(this).parents("li").first();
ele.toggleClass("done");
settings.onCheck.call(ele);
});
2015-07-25 19:06:16 +00:00
$('input', this).on('ifUnchecked', function () {
2015-02-01 21:25:09 +00:00
var ele = $(this).parents("li").first();
ele.toggleClass("done");
settings.onUncheck.call(ele);
});
} else {
2015-07-25 19:06:16 +00:00
$('input', this).on('change', function () {
2015-02-01 21:25:09 +00:00
var ele = $(this).parents("li").first();
ele.toggleClass("done");
2015-07-25 19:06:16 +00:00
if ($('input', ele).is(":checked")) {
settings.onCheck.call(ele);
} else {
settings.onUncheck.call(ele);
}
2015-02-01 21:25:09 +00:00
});
}
});
};
2015-09-21 12:41:29 +00:00
}(jQuery));