app.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  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. //BoxRefresh Plugin
  47. enableBoxRefresh: true,
  48. //Bootstrap.js tooltip
  49. enableBSToppltip: true,
  50. BSTooltipSelector: "[data-toggle='tooltip']",
  51. //Enable Fast Click. Fastclick.js creates a more
  52. //native touch experience with touch devices. If you
  53. //choose to enable the plugin, make sure you load the script
  54. //before AdminLTE's app.js
  55. enableFastclick: true,
  56. //Control Sidebar Options
  57. enableControlSidebar: true,
  58. controlSidebarOptions: {
  59. //Which button should trigger the open/close event
  60. toggleBtnSelector: "[data-toggle='control-sidebar']",
  61. //The sidebar selector
  62. selector: ".control-sidebar",
  63. //Enable slide over content
  64. slide: true
  65. },
  66. //Box Widget Plugin. Enable this plugin
  67. //to allow boxes to be collapsed and/or removed
  68. enableBoxWidget: true,
  69. //Box Widget plugin options
  70. boxWidgetOptions: {
  71. boxWidgetIcons: {
  72. //The icon that triggers the collapse event
  73. collapse: 'fa fa-minus',
  74. //The icon that trigger the opening event
  75. open: 'fa fa-plus',
  76. //The icon that triggers the removing event
  77. remove: 'fa fa-times'
  78. },
  79. boxWidgetSelectors: {
  80. //Remove button selector
  81. remove: '[data-widget="remove"]',
  82. //Collapse button selector
  83. collapse: '[data-widget="collapse"]'
  84. }
  85. },
  86. //Direct Chat plugin options
  87. directChat: {
  88. //Enable direct chat by default
  89. enable: true,
  90. //The button to open and close the chat contacts pane
  91. contactToggleSelector: '[data-widget="chat-pane-toggle"]'
  92. },
  93. //Define the set of colors to use globally around the website
  94. colors: {
  95. lightBlue: "#3c8dbc",
  96. red: "#f56954",
  97. green: "#00a65a",
  98. aqua: "#00c0ef",
  99. yellow: "#f39c12",
  100. blue: "#0073b7",
  101. navy: "#001F3F",
  102. teal: "#39CCCC",
  103. olive: "#3D9970",
  104. lime: "#01FF70",
  105. orange: "#FF851B",
  106. fuchsia: "#F012BE",
  107. purple: "#8E24AA",
  108. maroon: "#D81B60",
  109. black: "#222222",
  110. gray: "#d2d6de"
  111. },
  112. //The standard screen sizes that bootstrap uses.
  113. //If you change these in the variables.less file, change
  114. //them here too.
  115. screenSizes: {
  116. xs: 480,
  117. sm: 768,
  118. md: 992,
  119. lg: 1200
  120. }
  121. };
  122. /* ------------------
  123. * - Implementation -
  124. * ------------------
  125. * The next block of code implements AdminLTE's
  126. * functions and plugins as specified by the
  127. * options above.
  128. */
  129. $(function () {
  130. //Easy access to options
  131. var o = $.AdminLTE.options;
  132. //Set up the object
  133. _init();
  134. //Activate the layout maker
  135. $.AdminLTE.layout.activate();
  136. //Enable sidebar tree view controls
  137. $.AdminLTE.tree('.sidebar');
  138. //Enable control sidebar
  139. if (o.enableControlSidebar) {
  140. $.AdminLTE.controlSidebar.activate();
  141. }
  142. //Add slimscroll to navbar dropdown
  143. if (o.navbarMenuSlimscroll && typeof $.fn.slimscroll != 'undefined') {
  144. $(".navbar .menu").slimscroll({
  145. height: "200px",
  146. alwaysVisible: false,
  147. size: "3px"
  148. }).css("width", "100%");
  149. }
  150. //Activate sidebar push menu
  151. if (o.sidebarPushMenu) {
  152. $.AdminLTE.pushMenu(o.sidebarToggleSelector);
  153. }
  154. //Activate Bootstrap tooltip
  155. if (o.enableBSToppltip) {
  156. $(o.BSTooltipSelector).tooltip();
  157. }
  158. //Activate box widget
  159. if (o.enableBoxWidget) {
  160. $.AdminLTE.boxWidget.activate();
  161. }
  162. //Activate fast click
  163. if (o.enableFastclick && typeof FastClick != 'undefined') {
  164. FastClick.attach(document.body);
  165. }
  166. //Activate direct chat widget
  167. if (o.directChat.enable) {
  168. $(o.directChat.contactToggleSelector).click(function () {
  169. var box = $(this).parents('.direct-chat').first();
  170. box.toggleClass('direct-chat-contacts-open');
  171. });
  172. }
  173. /*
  174. * INITIALIZE BUTTON TOGGLE
  175. * ------------------------
  176. */
  177. $('.btn-group[data-toggle="btn-toggle"]').each(function () {
  178. var group = $(this);
  179. $(this).find(".btn").click(function (e) {
  180. group.find(".btn.active").removeClass("active");
  181. $(this).addClass("active");
  182. e.preventDefault();
  183. });
  184. });
  185. });
  186. /* ----------------------------------
  187. * - Initialize the AdminLTE Object -
  188. * ----------------------------------
  189. * All AdminLTE functions are implemented below.
  190. */
  191. function _init() {
  192. /* Layout
  193. * ======
  194. * Fixes the layout height in case min-height fails.
  195. *
  196. * @type Object
  197. * @usage $.AdminLTE.layout.activate()
  198. * $.AdminLTE.layout.fix()
  199. * $.AdminLTE.layout.fixSidebar()
  200. */
  201. $.AdminLTE.layout = {
  202. activate: function () {
  203. var _this = this;
  204. _this.fix();
  205. _this.fixSidebar();
  206. $(window, ".wrapper").resize(function () {
  207. _this.fix();
  208. _this.fixSidebar();
  209. });
  210. },
  211. fix: function () {
  212. //Get window height and the wrapper height
  213. var neg = $('.main-header').outerHeight() + $('.main-footer').outerHeight();
  214. var window_height = $(window).height();
  215. var sidebar_height = $(".sidebar").height();
  216. //Set the min-height of the content and sidebar based on the
  217. //the height of the document.
  218. if ($("body").hasClass("fixed")) {
  219. $(".content-wrapper, .right-side").css('min-height', window_height - $('.main-footer').outerHeight());
  220. } else {
  221. if (window_height >= sidebar_height) {
  222. $(".content-wrapper, .right-side").css('min-height', window_height - neg);
  223. } else {
  224. $(".content-wrapper, .right-side").css('min-height', sidebar_height);
  225. }
  226. }
  227. },
  228. fixSidebar: function () {
  229. //Make sure the body tag has the .fixed class
  230. if (!$("body").hasClass("fixed")) {
  231. if (typeof $.fn.slimScroll != 'undefined') {
  232. $(".sidebar").slimScroll({destroy: true}).height("auto");
  233. }
  234. return;
  235. } else if (typeof $.fn.slimScroll == 'undefined' && console) {
  236. console.error("Error: the fixed layout requires the slimscroll plugin!");
  237. }
  238. //Enable slimscroll for fixed layout
  239. if ($.AdminLTE.options.sidebarSlimScroll) {
  240. if (typeof $.fn.slimScroll != 'undefined') {
  241. //Distroy if it exists
  242. $(".sidebar").slimScroll({destroy: true}).height("auto");
  243. //Add slimscroll
  244. $(".sidebar").slimscroll({
  245. height: ($(window).height() - $(".main-header").height()) + "px",
  246. color: "rgba(0,0,0,0.2)",
  247. size: "3px"
  248. });
  249. }
  250. }
  251. }
  252. };
  253. /* PushMenu()
  254. * ==========
  255. * Adds the push menu functionality to the sidebar.
  256. *
  257. * @type Function
  258. * @usage: $.AdminLTE.pushMenu("[data-toggle='offcanvas']")
  259. */
  260. $.AdminLTE.pushMenu = function (toggleBtn) {
  261. //Get the screen sizes
  262. var screenSizes = this.options.screenSizes;
  263. //Enable sidebar toggle
  264. $(toggleBtn).click(function (e) {
  265. e.preventDefault();
  266. //Enable sidebar push menu
  267. if ($(window).width() > (screenSizes.sm - 1)) {
  268. $("body").toggleClass('sidebar-collapse');
  269. }
  270. //Handle sidebar push menu for small screens
  271. else {
  272. if ($("body").hasClass('sidebar-open')) {
  273. $("body").removeClass('sidebar-open');
  274. $("body").removeClass('sidebar-collapse')
  275. } else {
  276. $("body").addClass('sidebar-open');
  277. }
  278. }
  279. });
  280. $(".content-wrapper").click(function () {
  281. //Enable hide menu when clicking on the content-wrapper on small screens
  282. if ($(window).width() <= (screenSizes.sm - 1) && $("body").hasClass("sidebar-open")) {
  283. $("body").removeClass('sidebar-open');
  284. }
  285. });
  286. };
  287. /* Tree()
  288. * ======
  289. * Converts the sidebar into a multilevel
  290. * tree view menu.
  291. *
  292. * @type Function
  293. * @Usage: $.AdminLTE.tree('.sidebar')
  294. */
  295. $.AdminLTE.tree = function (menu) {
  296. var _this = this;
  297. $("li a", $(menu)).click(function (e) {
  298. //Get the clicked link and the next element
  299. var $this = $(this);
  300. var checkElement = $this.next();
  301. //Check if the next element is a menu and is visible
  302. if ((checkElement.is('.treeview-menu')) && (checkElement.is(':visible'))) {
  303. //Close the menu
  304. checkElement.slideUp('normal', function () {
  305. checkElement.removeClass('menu-open');
  306. //Fix the layout in case the sidebar stretches over the height of the window
  307. //_this.layout.fix();
  308. });
  309. checkElement.parent("li").removeClass("active");
  310. }
  311. //If the menu is not visible
  312. else if ((checkElement.is('.treeview-menu')) && (!checkElement.is(':visible'))) {
  313. //Get the parent menu
  314. var parent = $this.parents('ul').first();
  315. //Close all open menus within the parent
  316. var ul = parent.find('ul:visible').slideUp('normal');
  317. //Remove the menu-open class from the parent
  318. ul.removeClass('menu-open');
  319. //Get the parent li
  320. var parent_li = $this.parent("li");
  321. //Open the target menu and add the menu-open class
  322. checkElement.slideDown('normal', function () {
  323. //Add the class active to the parent li
  324. checkElement.addClass('menu-open');
  325. parent.find('li.active').removeClass('active');
  326. parent_li.addClass('active');
  327. //Fix the layout in case the sidebar stretches over the height of the window
  328. _this.layout.fix();
  329. });
  330. }
  331. //if this isn't a link, prevent the page from being redirected
  332. if (checkElement.is('.treeview-menu')) {
  333. e.preventDefault();
  334. }
  335. });
  336. };
  337. /* ControlSidebar
  338. * ==============
  339. * Adds functionality to the right sidebar
  340. *
  341. * @type Object
  342. * @usage $.AdminLTE.controlSidebar.activate(options)
  343. */
  344. $.AdminLTE.controlSidebar = {
  345. //instantiate the object
  346. activate: function () {
  347. //Get the object
  348. var _this = this;
  349. //Update options
  350. var o = $.AdminLTE.options.controlSidebarOptions;
  351. //Get the sidebar
  352. var sidebar = $(o.selector);
  353. //The toggle button
  354. var btn = $(o.toggleBtnSelector);
  355. //Listen to the click event
  356. btn.click(function (e) {
  357. e.preventDefault();
  358. if (!sidebar.hasClass('control-sidebar-open')
  359. && !$('body').hasClass('control-sidebar-open')) {
  360. //Open the sidebar
  361. _this.open(sidebar, o.slide);
  362. } else {
  363. _this.close(sidebar, o.slide);
  364. }
  365. });
  366. },
  367. //Open the control sidebar
  368. open: function (sidebar, slide) {
  369. if (slide)
  370. sidebar.addClass('control-sidebar-open');
  371. else
  372. $('body').addClass('control-sidebar-open');
  373. },
  374. //Close the control sidebar
  375. close: function (sidebar, slide) {
  376. if (slide)
  377. sidebar.removeClass('control-sidebar-open');
  378. else
  379. $('body').removeClass('control-sidebar-open');
  380. }
  381. };
  382. /* BoxWidget
  383. * =========
  384. * BoxWidget is plugin to handle collapsing and
  385. * removing boxes from the screen.
  386. *
  387. * @type Object
  388. * @usage $.AdminLTE.boxWidget.activate()
  389. * Set all of your option in the main $.AdminLTE.options object
  390. */
  391. $.AdminLTE.boxWidget = {
  392. activate: function () {
  393. var o = $.AdminLTE.options;
  394. var _this = this;
  395. //Listen for collapse event triggers
  396. $(o.boxWidgetOptions.boxWidgetSelectors.collapse).click(function (e) {
  397. e.preventDefault();
  398. _this.collapse($(this));
  399. });
  400. //Listen for remove event triggers
  401. $(o.boxWidgetOptions.boxWidgetSelectors.remove).click(function (e) {
  402. e.preventDefault();
  403. _this.remove($(this));
  404. });
  405. },
  406. collapse: function (element) {
  407. //Find the box parent
  408. var box = element.parents(".box").first();
  409. //Find the body and the footer
  410. var bf = box.find(".box-body, .box-footer");
  411. if (!box.hasClass("collapsed-box")) {
  412. //Convert minus into plus
  413. element.children(".fa-minus").removeClass("fa-minus").addClass("fa-plus");
  414. bf.slideUp(300, function () {
  415. box.addClass("collapsed-box");
  416. });
  417. } else {
  418. //Convert plus into minus
  419. element.children(".fa-plus").removeClass("fa-plus").addClass("fa-minus");
  420. bf.slideDown(300, function () {
  421. box.removeClass("collapsed-box");
  422. });
  423. }
  424. },
  425. remove: function (element) {
  426. //Find the box parent
  427. var box = element.parents(".box").first();
  428. box.slideUp();
  429. },
  430. options: $.AdminLTE.options.boxWidgetOptions
  431. };
  432. }
  433. /* ------------------
  434. * - Custom Plugins -
  435. * ------------------
  436. * All custom plugins are defined below.
  437. */
  438. /*
  439. * BOX REFRESH BUTTON
  440. * ------------------
  441. * This is a custom plugin to use with the compenet BOX. It allows you to add
  442. * a refresh button to the box. It converts the box's state to a loading state.
  443. *
  444. * @type plugin
  445. * @usage $("#box-widget").boxRefresh( options );
  446. */
  447. (function ($) {
  448. $.fn.boxRefresh = function (options) {
  449. // Render options
  450. var settings = $.extend({
  451. //Refressh button selector
  452. trigger: ".refresh-btn",
  453. //File source to be loaded (e.g: ajax/src.php)
  454. source: "",
  455. //Callbacks
  456. onLoadStart: function (box) {
  457. }, //Right after the button has been clicked
  458. onLoadDone: function (box) {
  459. } //When the source has been loaded
  460. }, options);
  461. //The overlay
  462. var overlay = $('<div class="overlay"><div class="fa fa-refresh fa-spin"></div></div>');
  463. return this.each(function () {
  464. //if a source is specified
  465. if (settings.source === "") {
  466. if (console) {
  467. console.log("Please specify a source first - boxRefresh()");
  468. }
  469. return;
  470. }
  471. //the box
  472. var box = $(this);
  473. //the button
  474. var rBtn = box.find(settings.trigger).first();
  475. //On trigger click
  476. rBtn.click(function (e) {
  477. e.preventDefault();
  478. //Add loading overlay
  479. start(box);
  480. //Perform ajax call
  481. box.find(".box-body").load(settings.source, function () {
  482. done(box);
  483. });
  484. });
  485. });
  486. function start(box) {
  487. //Add overlay and loading img
  488. box.append(overlay);
  489. settings.onLoadStart.call(box);
  490. }
  491. function done(box) {
  492. //Remove overlay and loading img
  493. box.find(overlay).remove();
  494. settings.onLoadDone.call(box);
  495. }
  496. };
  497. })(jQuery);
  498. /*
  499. * TODO LIST CUSTOM PLUGIN
  500. * -----------------------
  501. * This plugin depends on iCheck plugin for checkbox and radio inputs
  502. *
  503. * @type plugin
  504. * @usage $("#todo-widget").todolist( options );
  505. */
  506. (function ($) {
  507. $.fn.todolist = function (options) {
  508. // Render options
  509. var settings = $.extend({
  510. //When the user checks the input
  511. onCheck: function (ele) {
  512. },
  513. //When the user unchecks the input
  514. onUncheck: function (ele) {
  515. }
  516. }, options);
  517. return this.each(function () {
  518. if (typeof $.fn.iCheck != 'undefined') {
  519. $('input', this).on('ifChecked', function (event) {
  520. var ele = $(this).parents("li").first();
  521. ele.toggleClass("done");
  522. settings.onCheck.call(ele);
  523. });
  524. $('input', this).on('ifUnchecked', function (event) {
  525. var ele = $(this).parents("li").first();
  526. ele.toggleClass("done");
  527. settings.onUncheck.call(ele);
  528. });
  529. } else {
  530. $('input', this).on('change', function (event) {
  531. var ele = $(this).parents("li").first();
  532. ele.toggleClass("done");
  533. settings.onCheck.call(ele);
  534. });
  535. }
  536. });
  537. };
  538. }(jQuery));