app.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /*! AdminLTE app.js
  2. * ================
  3. * Main JS application file for AdminLTE v2. This file
  4. * should be included in all pages. It controls some layout
  5. * options and implements exclusive AdminLTE plugins.
  6. *
  7. * @Author Almsaeed Studio
  8. * @Support <http://www.almsaeedstudio.com>
  9. * @Email <support@almsaeedstudio.com>
  10. * @version 2.1.0
  11. * @license MIT <http://opensource.org/licenses/MIT>
  12. */
  13. 'use strict';
  14. //Make sure jQuery has been loaded before app.js
  15. if (typeof jQuery === "undefined") {
  16. throw new Error("AdminLTE requires jQuery");
  17. }
  18. /* AdminLTE
  19. *
  20. * @type Object
  21. * @description $.AdminLTE is the main object for the template's app.
  22. * It's used for implementing functions and options related
  23. * to the template. Keeping everything wrapped in an object
  24. * prevents conflict with other plugins and is a better
  25. * way to organize our code.
  26. */
  27. $.AdminLTE = {};
  28. /* --------------------
  29. * - AdminLTE Options -
  30. * --------------------
  31. * Modify these options to suit your implementation
  32. */
  33. $.AdminLTE.options = {
  34. //Add slimscroll to navbar menus
  35. //This requires you to load the slimscroll plugin
  36. //in every page before app.js
  37. navbarMenuSlimscroll: true,
  38. navbarMenuSlimscrollWidth: "3px", //The width of the scroll bar
  39. navbarMenuHeight: "200px", //The height of the inner menu
  40. //Sidebar push menu toggle button selector
  41. sidebarToggleSelector: "[data-toggle='offcanvas']",
  42. //Activate sidebar push menu
  43. sidebarPushMenu: true,
  44. //Activate sidebar slimscroll if the fixed layout is set (requires SlimScroll Plugin)
  45. sidebarSlimScroll: true,
  46. //Enable sidebar expand on hover effect for sidebar mini
  47. //This option is forced to true if both the fixed layout and sidebar mini
  48. //are used together
  49. sidebarExpandOnHover: false,
  50. //BoxRefresh Plugin
  51. enableBoxRefresh: true,
  52. //Bootstrap.js tooltip
  53. enableBSToppltip: true,
  54. BSTooltipSelector: "[data-toggle='tooltip']",
  55. //Enable Fast Click. Fastclick.js creates a more
  56. //native touch experience with touch devices. If you
  57. //choose to enable the plugin, make sure you load the script
  58. //before AdminLTE's app.js
  59. enableFastclick: true,
  60. //Control Sidebar Options
  61. enableControlSidebar: true,
  62. controlSidebarOptions: {
  63. //Which button should trigger the open/close event
  64. toggleBtnSelector: "[data-toggle='control-sidebar']",
  65. //The sidebar selector
  66. selector: ".control-sidebar",
  67. //Enable slide over content
  68. slide: true
  69. },
  70. //Box Widget Plugin. Enable this plugin
  71. //to allow boxes to be collapsed and/or removed
  72. enableBoxWidget: true,
  73. //Box Widget plugin options
  74. boxWidgetOptions: {
  75. boxWidgetIcons: {
  76. //Collapse icon
  77. collapse: 'fa-minus',
  78. //Open icon
  79. open: 'fa-plus',
  80. //Remove icon
  81. remove: 'fa-times'
  82. },
  83. boxWidgetSelectors: {
  84. //Remove button selector
  85. remove: '[data-widget="remove"]',
  86. //Collapse button selector
  87. collapse: '[data-widget="collapse"]'
  88. }
  89. },
  90. //Direct Chat plugin options
  91. directChat: {
  92. //Enable direct chat by default
  93. enable: true,
  94. //The button to open and close the chat contacts pane
  95. contactToggleSelector: '[data-widget="chat-pane-toggle"]'
  96. },
  97. //Define the set of colors to use globally around the website
  98. colors: {
  99. lightBlue: "#3c8dbc",
  100. red: "#f56954",
  101. green: "#00a65a",
  102. aqua: "#00c0ef",
  103. yellow: "#f39c12",
  104. blue: "#0073b7",
  105. navy: "#001F3F",
  106. teal: "#39CCCC",
  107. olive: "#3D9970",
  108. lime: "#01FF70",
  109. orange: "#FF851B",
  110. fuchsia: "#F012BE",
  111. purple: "#8E24AA",
  112. maroon: "#D81B60",
  113. black: "#222222",
  114. gray: "#d2d6de"
  115. },
  116. //The standard screen sizes that bootstrap uses.
  117. //If you change these in the variables.less file, change
  118. //them here too.
  119. screenSizes: {
  120. xs: 480,
  121. sm: 768,
  122. md: 992,
  123. lg: 1200
  124. }
  125. };
  126. /* ------------------
  127. * - Implementation -
  128. * ------------------
  129. * The next block of code implements AdminLTE's
  130. * functions and plugins as specified by the
  131. * options above.
  132. */
  133. $(function () {
  134. //Extend options if external options exist
  135. if (typeof AdminLTEOptions !== "undefined") {
  136. $.AdminLTE.options = $.extend({},
  137. $.AdminLTE.options,
  138. AdminLTEOptions);
  139. }
  140. //Easy access to options
  141. var o = $.AdminLTE.options;
  142. //Set up the object
  143. _init();
  144. //Activate the layout maker
  145. $.AdminLTE.layout.activate();
  146. //Enable sidebar tree view controls
  147. $.AdminLTE.tree('.sidebar');
  148. //Enable control sidebar
  149. if (o.enableControlSidebar) {
  150. $.AdminLTE.controlSidebar.activate();
  151. }
  152. //Add slimscroll to navbar dropdown
  153. if (o.navbarMenuSlimscroll && typeof $.fn.slimscroll != 'undefined') {
  154. $(".navbar .menu").slimscroll({
  155. height: o.navbarMenuHeight,
  156. alwaysVisible: false,
  157. size: o.navbarMenuSlimscrollWidth
  158. }).css("width", "100%");
  159. }
  160. //Activate sidebar push menu
  161. if (o.sidebarPushMenu) {
  162. $.AdminLTE.pushMenu.activate(o.sidebarToggleSelector);
  163. }
  164. //Activate Bootstrap tooltip
  165. if (o.enableBSToppltip) {
  166. $(o.BSTooltipSelector).tooltip();
  167. }
  168. //Activate box widget
  169. if (o.enableBoxWidget) {
  170. $.AdminLTE.boxWidget.activate();
  171. }
  172. //Activate fast click
  173. if (o.enableFastclick && typeof FastClick != 'undefined') {
  174. FastClick.attach(document.body);
  175. }
  176. //Activate direct chat widget
  177. if (o.directChat.enable) {
  178. $(o.directChat.contactToggleSelector).on('click', function () {
  179. var box = $(this).parents('.direct-chat').first();
  180. box.toggleClass('direct-chat-contacts-open');
  181. });
  182. }
  183. /*
  184. * INITIALIZE BUTTON TOGGLE
  185. * ------------------------
  186. */
  187. $('.btn-group[data-toggle="btn-toggle"]').each(function () {
  188. var group = $(this);
  189. $(this).find(".btn").on('click', function (e) {
  190. group.find(".btn.active").removeClass("active");
  191. $(this).addClass("active");
  192. e.preventDefault();
  193. });
  194. });
  195. });
  196. /* ----------------------------------
  197. * - Initialize the AdminLTE Object -
  198. * ----------------------------------
  199. * All AdminLTE functions are implemented below.
  200. */
  201. function _init() {
  202. /* Layout
  203. * ======
  204. * Fixes the layout height in case min-height fails.
  205. *
  206. * @type Object
  207. * @usage $.AdminLTE.layout.activate()
  208. * $.AdminLTE.layout.fix()
  209. * $.AdminLTE.layout.fixSidebar()
  210. */
  211. $.AdminLTE.layout = {
  212. activate: function () {
  213. var _this = this;
  214. _this.fix();
  215. _this.fixSidebar();
  216. $(window, ".wrapper").resize(function () {
  217. _this.fix();
  218. _this.fixSidebar();
  219. });
  220. },
  221. fix: function () {
  222. //Get window height and the wrapper height
  223. var neg = $('.main-header').outerHeight() + $('.main-footer').outerHeight();
  224. var window_height = $(window).height();
  225. var sidebar_height = $(".sidebar").height();
  226. //Set the min-height of the content and sidebar based on the
  227. //the height of the document.
  228. if ($("body").hasClass("fixed")) {
  229. $(".content-wrapper, .right-side").css('min-height', window_height - $('.main-footer').outerHeight());
  230. } else {
  231. var postSetWidth;
  232. if (window_height >= sidebar_height) {
  233. $(".content-wrapper, .right-side").css('min-height', window_height - neg);
  234. postSetWidth = window_height - neg;
  235. } else {
  236. $(".content-wrapper, .right-side").css('min-height', sidebar_height);
  237. postSetWidth = sidebar_height;
  238. }
  239. //Fix for the control sidebar height
  240. var controlSidebar = $($.AdminLTE.options.controlSidebarOptions.selector);
  241. if(typeof controlSidebar !== "undefined") {
  242. if(controlSidebar.height() > postSetWidth)
  243. $(".content-wrapper, .right-side").css('min-height', controlSidebar.height());
  244. }
  245. }
  246. },
  247. fixSidebar: function () {
  248. //Make sure the body tag has the .fixed class
  249. if (!$("body").hasClass("fixed")) {
  250. if (typeof $.fn.slimScroll != 'undefined') {
  251. $(".sidebar").slimScroll({destroy: true}).height("auto");
  252. }
  253. return;
  254. } else if (typeof $.fn.slimScroll == 'undefined' && console) {
  255. console.error("Error: the fixed layout requires the slimscroll plugin!");
  256. }
  257. //Enable slimscroll for fixed layout
  258. if ($.AdminLTE.options.sidebarSlimScroll) {
  259. if (typeof $.fn.slimScroll != 'undefined') {
  260. //Distroy if it exists
  261. $(".sidebar").slimScroll({destroy: true}).height("auto");
  262. //Add slimscroll
  263. $(".sidebar").slimscroll({
  264. height: ($(window).height() - $(".main-header").height()) + "px",
  265. color: "rgba(0,0,0,0.2)",
  266. size: "3px"
  267. });
  268. }
  269. }
  270. }
  271. };
  272. /* PushMenu()
  273. * ==========
  274. * Adds the push menu functionality to the sidebar.
  275. *
  276. * @type Function
  277. * @usage: $.AdminLTE.pushMenu("[data-toggle='offcanvas']")
  278. */
  279. $.AdminLTE.pushMenu = {
  280. activate: function (toggleBtn) {
  281. //Get the screen sizes
  282. var screenSizes = $.AdminLTE.options.screenSizes;
  283. //Enable sidebar toggle
  284. $(toggleBtn).on('click', function (e) {
  285. e.preventDefault();
  286. //Enable sidebar push menu
  287. if ($(window).width() > (screenSizes.sm - 1)) {
  288. $("body").toggleClass('sidebar-collapse');
  289. }
  290. //Handle sidebar push menu for small screens
  291. else {
  292. if ($("body").hasClass('sidebar-open')) {
  293. $("body").removeClass('sidebar-open');
  294. $("body").removeClass('sidebar-collapse')
  295. } else {
  296. $("body").addClass('sidebar-open');
  297. }
  298. }
  299. });
  300. $(".content-wrapper").click(function () {
  301. //Enable hide menu when clicking on the content-wrapper on small screens
  302. if ($(window).width() <= (screenSizes.sm - 1) && $("body").hasClass("sidebar-open")) {
  303. $("body").removeClass('sidebar-open');
  304. }
  305. });
  306. //Enable expand on hover for sidebar mini
  307. if ($.AdminLTE.options.sidebarExpandOnHover
  308. || ($('body').hasClass('fixed')
  309. && $('body').hasClass('sidebar-mini'))) {
  310. this.expandOnHover();
  311. }
  312. },
  313. expandOnHover: function () {
  314. var _this = this;
  315. var screenWidth = $.AdminLTE.options.screenSizes.sm - 1;
  316. //Expand sidebar on hover
  317. $('.main-sidebar').hover(function () {
  318. if ($('body').hasClass('sidebar-mini')
  319. && $("body").hasClass('sidebar-collapse')
  320. && $(window).width() > screenWidth) {
  321. _this.expand();
  322. }
  323. }, function () {
  324. if ($('body').hasClass('sidebar-mini')
  325. && $('body').hasClass('sidebar-expanded-on-hover')
  326. && $(window).width() > screenWidth) {
  327. _this.collapse();
  328. }
  329. });
  330. },
  331. expand: function () {
  332. $("body").removeClass('sidebar-collapse').addClass('sidebar-expanded-on-hover');
  333. },
  334. collapse: function () {
  335. if ($('body').hasClass('sidebar-expanded-on-hover')) {
  336. $('body').removeClass('sidebar-expanded-on-hover').addClass('sidebar-collapse');
  337. }
  338. }
  339. };
  340. /* Tree()
  341. * ======
  342. * Converts the sidebar into a multilevel
  343. * tree view menu.
  344. *
  345. * @type Function
  346. * @Usage: $.AdminLTE.tree('.sidebar')
  347. */
  348. $.AdminLTE.tree = function (menu) {
  349. var _this = this;
  350. $("li a", $(menu)).on('click', function (e) {
  351. //Get the clicked link and the next element
  352. var $this = $(this);
  353. var checkElement = $this.next();
  354. //Check if the next element is a menu and is visible
  355. if ((checkElement.is('.treeview-menu')) && (checkElement.is(':visible'))) {
  356. //Close the menu
  357. checkElement.slideUp('normal', function () {
  358. checkElement.removeClass('menu-open');
  359. //Fix the layout in case the sidebar stretches over the height of the window
  360. //_this.layout.fix();
  361. });
  362. checkElement.parent("li").removeClass("active");
  363. }
  364. //If the menu is not visible
  365. else if ((checkElement.is('.treeview-menu')) && (!checkElement.is(':visible'))) {
  366. //Get the parent menu
  367. var parent = $this.parents('ul').first();
  368. //Close all open menus within the parent
  369. var ul = parent.find('ul:visible').slideUp('normal');
  370. //Remove the menu-open class from the parent
  371. ul.removeClass('menu-open');
  372. //Get the parent li
  373. var parent_li = $this.parent("li");
  374. //Open the target menu and add the menu-open class
  375. checkElement.slideDown('normal', function () {
  376. //Add the class active to the parent li
  377. checkElement.addClass('menu-open');
  378. parent.find('li.active').removeClass('active');
  379. parent_li.addClass('active');
  380. //Fix the layout in case the sidebar stretches over the height of the window
  381. _this.layout.fix();
  382. });
  383. }
  384. //if this isn't a link, prevent the page from being redirected
  385. if (checkElement.is('.treeview-menu')) {
  386. e.preventDefault();
  387. }
  388. });
  389. };
  390. /* ControlSidebar
  391. * ==============
  392. * Adds functionality to the right sidebar
  393. *
  394. * @type Object
  395. * @usage $.AdminLTE.controlSidebar.activate(options)
  396. */
  397. $.AdminLTE.controlSidebar = {
  398. //instantiate the object
  399. activate: function () {
  400. //Get the object
  401. var _this = this;
  402. //Update options
  403. var o = $.AdminLTE.options.controlSidebarOptions;
  404. //Get the sidebar
  405. var sidebar = $(o.selector);
  406. //The toggle button
  407. var btn = $(o.toggleBtnSelector);
  408. //Listen to the click event
  409. btn.on('click', function (e) {
  410. e.preventDefault();
  411. //If the sidebar is not open
  412. if (!sidebar.hasClass('control-sidebar-open')
  413. && !$('body').hasClass('control-sidebar-open')) {
  414. //Open the sidebar
  415. _this.open(sidebar, o.slide);
  416. } else {
  417. _this.close(sidebar, o.slide);
  418. }
  419. });
  420. //If the body has a boxed layout, fix the sidebar bg position
  421. var bg = $(".control-sidebar-bg");
  422. _this._fix(bg);
  423. //If the body has a fixed layout, make the control sidebar fixed
  424. if ($('body').hasClass('fixed')) {
  425. _this._fixForFixed(sidebar);
  426. } else {
  427. //If the content height is less the sidebar's height, force max height
  428. if ($('.content-wrapper, .right-side').height() < sidebar.height()) {
  429. _this._fixForContent(sidebar);
  430. }
  431. }
  432. },
  433. //Open the control sidebar
  434. open: function (sidebar, slide) {
  435. //Slide over content
  436. if (slide)
  437. sidebar.addClass('control-sidebar-open');
  438. //Push the content by adding the open class to the body instead
  439. //of the sidebar itself
  440. else
  441. $('body').addClass('control-sidebar-open');
  442. },
  443. //Close the control sidebar
  444. close: function (sidebar, slide) {
  445. if (slide)
  446. sidebar.removeClass('control-sidebar-open');
  447. else
  448. $('body').removeClass('control-sidebar-open');
  449. },
  450. _fix: function (sidebar) {
  451. var _this = this;
  452. if ($("body").hasClass('layout-boxed')) {
  453. sidebar.css('position', 'absolute');
  454. sidebar.height($(".wrapper").height());
  455. $(window).resize(function () {
  456. _this._fix(sidebar);
  457. });
  458. } else {
  459. sidebar.css({
  460. 'position': 'fixed',
  461. 'height': 'auto'
  462. });
  463. }
  464. },
  465. _fixForFixed: function (sidebar) {
  466. sidebar.css({
  467. 'position': 'fixed',
  468. 'max-height': '100%',
  469. 'overflow': 'auto',
  470. 'padding-bottom': '50px'
  471. });
  472. },
  473. _fixForContent: function (sidebar) {
  474. $(".content-wrapper, .right-side").css('min-height', sidebar.height());
  475. }
  476. };
  477. /* BoxWidget
  478. * =========
  479. * BoxWidget is plugin to handle collapsing and
  480. * removing boxes from the screen.
  481. *
  482. * @type Object
  483. * @usage $.AdminLTE.boxWidget.activate()
  484. * Set all of your option in the main $.AdminLTE.options object
  485. */
  486. $.AdminLTE.boxWidget = {
  487. selectors: $.AdminLTE.options.boxWidgetOptions.boxWidgetSelectors,
  488. icons: $.AdminLTE.options.boxWidgetOptions.boxWidgetIcons,
  489. activate: function () {
  490. var _this = this;
  491. //Listen for collapse event triggers
  492. $(_this.selectors.collapse).on('click', function (e) {
  493. e.preventDefault();
  494. _this.collapse($(this));
  495. });
  496. //Listen for remove event triggers
  497. $(_this.selectors.remove).on('click', function (e) {
  498. e.preventDefault();
  499. _this.remove($(this));
  500. });
  501. },
  502. collapse: function (element) {
  503. var _this = this;
  504. //Find the box parent
  505. var box = element.parents(".box").first();
  506. //Find the body and the footer
  507. var box_content = box.find("> .box-body, > .box-footer");
  508. if (!box.hasClass("collapsed-box")) {
  509. //Convert minus into plus
  510. element.children(":first")
  511. .removeClass(_this.icons.collapse)
  512. .addClass(_this.icons.open);
  513. //Hide the content
  514. box_content.slideUp(300, function () {
  515. box.addClass("collapsed-box");
  516. });
  517. } else {
  518. //Convert plus into minus
  519. element.children(":first")
  520. .removeClass(_this.icons.open)
  521. .addClass(_this.icons.collapse);
  522. //Show the content
  523. box_content.slideDown(300, function () {
  524. box.removeClass("collapsed-box");
  525. });
  526. }
  527. },
  528. remove: function (element) {
  529. //Find the box parent
  530. var box = element.parents(".box").first();
  531. box.slideUp();
  532. }
  533. };
  534. }
  535. /* ------------------
  536. * - Custom Plugins -
  537. * ------------------
  538. * All custom plugins are defined below.
  539. */
  540. /*
  541. * BOX REFRESH BUTTON
  542. * ------------------
  543. * This is a custom plugin to use with the compenet BOX. It allows you to add
  544. * a refresh button to the box. It converts the box's state to a loading state.
  545. *
  546. * @type plugin
  547. * @usage $("#box-widget").boxRefresh( options );
  548. */
  549. (function ($) {
  550. $.fn.boxRefresh = function (options) {
  551. // Render options
  552. var settings = $.extend({
  553. //Refressh button selector
  554. trigger: ".refresh-btn",
  555. //File source to be loaded (e.g: ajax/src.php)
  556. source: "",
  557. //Callbacks
  558. onLoadStart: function (box) {
  559. }, //Right after the button has been clicked
  560. onLoadDone: function (box) {
  561. } //When the source has been loaded
  562. }, options);
  563. //The overlay
  564. var overlay = $('<div class="overlay"><div class="fa fa-refresh fa-spin"></div></div>');
  565. return this.each(function () {
  566. //if a source is specified
  567. if (settings.source === "") {
  568. if (console) {
  569. console.log("Please specify a source first - boxRefresh()");
  570. }
  571. return;
  572. }
  573. //the box
  574. var box = $(this);
  575. //the button
  576. var rBtn = box.find(settings.trigger).first();
  577. //On trigger click
  578. rBtn.on('click', function (e) {
  579. e.preventDefault();
  580. //Add loading overlay
  581. start(box);
  582. //Perform ajax call
  583. box.find(".box-body").load(settings.source, function () {
  584. done(box);
  585. });
  586. });
  587. });
  588. function start(box) {
  589. //Add overlay and loading img
  590. box.append(overlay);
  591. settings.onLoadStart.call(box);
  592. }
  593. function done(box) {
  594. //Remove overlay and loading img
  595. box.find(overlay).remove();
  596. settings.onLoadDone.call(box);
  597. }
  598. };
  599. })(jQuery);
  600. /*
  601. * TODO LIST CUSTOM PLUGIN
  602. * -----------------------
  603. * This plugin depends on iCheck plugin for checkbox and radio inputs
  604. *
  605. * @type plugin
  606. * @usage $("#todo-widget").todolist( options );
  607. */
  608. (function ($) {
  609. $.fn.todolist = function (options) {
  610. // Render options
  611. var settings = $.extend({
  612. //When the user checks the input
  613. onCheck: function (ele) {
  614. },
  615. //When the user unchecks the input
  616. onUncheck: function (ele) {
  617. }
  618. }, options);
  619. return this.each(function () {
  620. if (typeof $.fn.iCheck != 'undefined') {
  621. $('input', this).on('ifChecked', function (event) {
  622. var ele = $(this).parents("li").first();
  623. ele.toggleClass("done");
  624. settings.onCheck.call(ele);
  625. });
  626. $('input', this).on('ifUnchecked', function (event) {
  627. var ele = $(this).parents("li").first();
  628. ele.toggleClass("done");
  629. settings.onUncheck.call(ele);
  630. });
  631. } else {
  632. $('input', this).on('change', function (event) {
  633. var ele = $(this).parents("li").first();
  634. ele.toggleClass("done");
  635. settings.onCheck.call(ele);
  636. });
  637. }
  638. });
  639. };
  640. }(jQuery));