app.js 16 KB

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