/*! adminlte app.js * ================ * 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 * @email * @version 2.1.0 * @license mit */ 'use strict'; //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. * 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. */ $.adminlte = {}; /* -------------------- * - 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 //���slimscroll���˵�����������app.jsǰ������slimscroll��� navbarmenuslimscroll: true, navbarmenuslimscrollwidth: "3px", //the width of the scroll bar ��������� navbarmenuheight: "200px", //the height of the inner menu �߶� //sidebar push menu toggle button selector �˵��л���ť sidebartoggleselector: "[data-toggle='offcanvas']", //activate sidebar push menu �ƿ�����˵��л� sidebarpushmenu: true, //activate sidebar slimscroll if the fixed layout is set (requires slimscroll plugin) �˵������� sidebarslimscroll: true, //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, //boxrefresh plugin enableboxrefresh: true, //bootstrap.js tooltip enablebstoppltip: true, bstooltipselector: "[data-toggle='tooltip']", //enable fast click. fastclick.js creates a more //native touch experience with touch devices. if you //choose to enable the plugin, make sure you load the script //before adminlte's app.js enablefastclick: false, //control sidebar options �ҳ��������ƿ���� enablecontrolsidebar: false, controlsidebaroptions: { //which button should trigger the open/close event togglebtnselector: "[data-toggle='control-sidebar']", //the sidebar selector selector: ".control-sidebar", //enable slide over content slide: true }, //box widget plugin. enable this plugin //to allow boxes to be collapsed and/or removed enableboxwidget: true, //box widget plugin options boxwidgetoptions: { boxwidgeticons: { //collapse icon collapse: 'fa-minus', //open icon open: 'fa-plus', //remove icon remove: 'fa-times' }, 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"]' }, //define the set of colors to use globally around the website colors: { lightblue: "#1b65b9", 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", gray: "#d2d6de" }, //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 } }; /* ------------------ * - implementation - * ------------------ * the next block of code implements adminlte's * functions and plugins as specified by the * options above. */ $(function () { //extend options if external options exist if (typeof adminlteoptions !== "undefined") { $.extend(true, $.adminlte.options, adminlteoptions); } //easy access to options var o = $.adminlte.options; //set up the object _init(); //activate the layout maker $.adminlte.layout.activate(); //enable sidebar tree view controls $.adminlte.tree('.sidebar'); //enable control sidebar if (o.enablecontrolsidebar) { $.adminlte.controlsidebar.activate(); } //add slimscroll to navbar dropdown if (o.navbarmenuslimscroll && typeof $.fn.slimscroll != 'undefined') { $(".navbar .menu").slimscroll({ height: o.navbarmenuheight, alwaysvisible: false, size: o.navbarmenuslimscrollwidth }).css("width", "100%"); } //activate sidebar push menu if (o.sidebarpushmenu) { $.adminlte.pushmenu.activate(o.sidebartoggleselector); } //activate bootstrap tooltip if (o.enablebstoppltip) { $('body').tooltip({ selector: o.bstooltipselector }); } //activate box widget if (o.enableboxwidget) { $.adminlte.boxwidget.activate(); } //activate fast click if (o.enablefastclick && typeof fastclick != 'undefined') { fastclick.attach(document.body); } //activate direct chat widget if (o.directchat.enable) { $(o.directchat.contacttoggleselector).on('click', function () { var box = $(this).parents('.direct-chat').first(); box.toggleclass('direct-chat-contacts-open'); }); } /* * initialize button toggle * ------------------------ */ $('.btn-group[data-toggle="btn-toggle"]').each(function () { var group = $(this); $(this).find(".btn").on('click', function (e) { group.find(".btn.active").removeclass("active"); $(this).addclass("active"); e.preventdefault(); }); }); }); /* ---------------------------------- * - initialize the adminlte object - * ---------------------------------- * all adminlte functions are implemented below. */ function _init() { /* 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; _this.fix(); _this.fixsidebar(); $(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()); //$(".main-frame", ".content-wrapper").css('min-height', window_height - $('.main-footer').outerheight() - $('.main-header').outerheight() - 5); //$(".main-frame", ".content-wrapper").height(window_height - $('.main-footer').outerheight() - $('.main-header').outerheight() - 5); $(".main-frame", ".content-wrapper").css('min-height', window_height - $('.main-footer').outerheight() - 85); $(".main-frame", ".content-wrapper").height(window_height - $('.main-footer').outerheight() - 85); } else { var postsetwidth; if (window_height >= sidebar_height) { $(".content-wrapper, .right-side").css('min-height', window_height - neg); postsetwidth = window_height - neg; } else { $(".content-wrapper, .right-side").css('min-height', sidebar_height); postsetwidth = sidebar_height; } //fix for the control sidebar height var controlsidebar = $($.adminlte.options.controlsidebaroptions.selector); if (typeof controlsidebar !== "undefined") { if (controlsidebar.height() > postsetwidth) $(".content-wrapper, .right-side").css('min-height', controlsidebar.height()); } } }, 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; } else if (typeof $.fn.slimscroll == 'undefined' && console) { console.error("error: the fixed layout requires the slimscroll plugin!"); } //enable slimscroll for fixed layout if ($.adminlte.options.sidebarslimscroll) { if (typeof $.fn.slimscroll != 'undefined') { //destroy if it exists $(".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" }); } } } }; /* pushmenu() * ========== * adds the push menu functionality to the sidebar. * * @type function * @usage: $.adminlte.pushmenu("[data-toggle='offcanvas']") */ $.adminlte.pushmenu = { activate: function (togglebtn) { //get the screen sizes var screensizes = $.adminlte.options.screensizes; //enable sidebar toggle $(togglebtn).on('click', function (e) { e.preventdefault(); //enable sidebar push menu if ($(window).width() > (screensizes.sm - 1)) { $("body").toggleclass('sidebar-collapse'); } //handle sidebar push menu for small screens else { if ($("body").hasclass('sidebar-open')) { $("body").removeclass('sidebar-open'); $("body").removeclass('sidebar-collapse') } else { $("body").addclass('sidebar-open'); } } }); $(".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")) { $("body").removeclass('sidebar-open'); } }); //enable expand on hover for sidebar mini if ($.adminlte.options.sidebarexpandonhover || ($('body').hasclass('fixed') && $('body').hasclass('sidebar-mini'))) { this.expandonhover(); } }, 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') && $("body").hasclass('sidebar-collapse') && $(window).width() > screenwidth) { _this.expand(); } }, function () { if ($('body').hasclass('sidebar-mini') && $('body').hasclass('sidebar-expanded-on-hover') && $(window).width() > screenwidth) { _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'); } } }; /* tree() * ====== * converts the sidebar into a multilevel * tree view menu. * * @type function * @usage: $.adminlte.tree('.sidebar') */ $.adminlte.tree = function (menu) { var _this = this; $("li a", $(menu)).on('click', function (e) { //get the clicked link and the next element var $this = $(this); var checkelement = $this.next(); //check if the next element is a menu and is visible if ((checkelement.is('.treeview-menu')) && (checkelement.is(':visible'))) { //close the menu checkelement.slideup('normal', function () { 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 var ul = parent.find('ul:visible').slideup('normal'); //remove the menu-open class from the parent ul.removeclass('menu-open'); //get the parent li var parent_li = $this.parent("li"); //open the target menu and add the menu-open class checkelement.slidedown('normal', function () { //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(); } }); }; /* controlsidebar * ============== * adds functionality to the right sidebar * * @type object * @usage $.adminlte.controlsidebar.activate(options) */ $.adminlte.controlsidebar = { //instantiate the object activate: function () { //get the object var _this = this; //update options var o = $.adminlte.options.controlsidebaroptions; //get the sidebar var sidebar = $(o.selector); //the toggle button var btn = $(o.togglebtnselector); //listen to the click event btn.on('click', function (e) { e.preventdefault(); //if the sidebar is not open if (!sidebar.hasclass('control-sidebar-open') && !$('body').hasclass('control-sidebar-open')) { //open the sidebar _this.open(sidebar, o.slide); } else { _this.close(sidebar, o.slide); } }); //if the body has a boxed layout, fix the sidebar bg position var bg = $(".control-sidebar-bg"); _this._fix(bg); //if the body has a fixed layout, make the control sidebar fixed if ($('body').hasclass('fixed')) { _this._fixforfixed(sidebar); } else { //if the content height is less than the sidebar's height, force max height if ($('.content-wrapper, .right-side').height() < sidebar.height()) { _this._fixforcontent(sidebar); } } }, //open the control sidebar open: function (sidebar, slide) { var _this = this; //slide over content if (slide) { sidebar.addclass('control-sidebar-open'); } else { //push the content by adding the open class to the body instead //of the sidebar itself $('body').addclass('control-sidebar-open'); } }, //close the control sidebar close: function (sidebar, slide) { if (slide) { sidebar.removeclass('control-sidebar-open'); } else { $('body').removeclass('control-sidebar-open'); } }, _fix: function (sidebar) { var _this = this; 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' }); } }, _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()); } }; /* boxwidget * ========= * boxwidget is a plugin to handle collapsing and * removing boxes from the screen. * * @type object * @usage $.adminlte.boxwidget.activate() * set all your options in the main $.adminlte.options object */ $.adminlte.boxwidget = { selectors: $.adminlte.options.boxwidgetoptions.boxwidgetselectors, icons: $.adminlte.options.boxwidgetoptions.boxwidgeticons, activate: function () { var _this = this; //listen for collapse event triggers $(_this.selectors.collapse).on('click', function (e) { e.preventdefault(); _this.collapse($(this)); }); //listen for remove event triggers $(_this.selectors.remove).on('click', function (e) { e.preventdefault(); _this.remove($(this)); }); }, collapse: function (element) { var _this = this; //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"); if (!box.hasclass("collapsed-box")) { //convert minus into plus element.children(":first") .removeclass(_this.icons.collapse) .addclass(_this.icons.open); //hide the content box_content.slideup(300, function () { box.addclass("collapsed-box"); }); } else { //convert plus into minus element.children(":first") .removeclass(_this.icons.open) .addclass(_this.icons.collapse); //show the content box_content.slidedown(300, function () { box.removeclass("collapsed-box"); }); } }, remove: function (element) { //find the box parent var box = element.parents(".box").first(); box.slideup(); } }; } /* ------------------ * - custom plugins - * ------------------ * all custom plugins are defined below. */ /* * box refresh button * ------------------ * this is a custom plugin to use with the component box. it allows you to add * a refresh button to the box. it converts the box's state to a loading state. * * @type plugin * @usage $("#box-widget").boxrefresh( options ); */ (function ($) { $.fn.boxrefresh = function (options) { // render options var settings = $.extend({ //refresh button selector trigger: ".refresh-btn", //file source to be loaded (e.g: ajax/src.php) source: "", //callbacks onloadstart: function (box) { }, //right after the button has been clicked onloaddone: function (box) { } //when the source has been loaded }, options); //the overlay var overlay = $('
'); return this.each(function () { //if a source is specified if (settings.source === "") { if (console) { console.log("please specify a source first - boxrefresh()"); } return; } //the box var box = $(this); //the button var rbtn = box.find(settings.trigger).first(); //on trigger click rbtn.on('click', function (e) { 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); /* * todo list custom plugin * ----------------------- * this plugin depends on icheck plugin for checkbox and radio inputs * * @type plugin * @usage $("#todo-widget").todolist( options ); */ (function ($) { $.fn.todolist = function (options) { // render options var settings = $.extend({ //when the user checks the input oncheck: function (ele) { }, //when the user unchecks the input onuncheck: function (ele) { } }, options); return this.each(function () { if (typeof $.fn.icheck != 'undefined') { $('input', this).on('ifchecked', function (event) { var ele = $(this).parents("li").first(); ele.toggleclass("done"); settings.oncheck.call(ele); }); $('input', this).on('ifunchecked', function (event) { var ele = $(this).parents("li").first(); ele.toggleclass("done"); settings.onuncheck.call(ele); }); } else { $('input', this).on('change', function (event) { var ele = $(this).parents("li").first(); ele.toggleclass("done"); settings.oncheck.call(ele); }); } }); }; }(jquery)); (function ($) { $.fn.serializejson = function (){ var serializeobj={}; $( this .serializearray()).each( function (){ serializeobj[this.name]= this.value; }); return serializeobj; }; /** * 下拉框的联动 * url:数据的获取地址 * sub:下级组件选择器 * value:option的值对应的属性 * name:显示的名字对应的值 */ $("[data-cascade]").change(function(){ var defaultparam = {value:"id",name:"name"}; var $this = $(this); var params = $.extend(defaultparam,$.parsejson($this.attr("data-cascade"))); var subobject = $(params.sub).empty(); //$.post(params.url) subobject.append([$("