app.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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.0.3
  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. //Activate the layout maker
  123. $.AdminLTE.layout.activate();
  124. //Enable sidebar tree view controls
  125. $.AdminLTE.tree('.sidebar');
  126. //Add slimscroll to navbar dropdown
  127. if (o.navbarMenuSlimscroll && typeof $.fn.slimscroll != 'undefined') {
  128. $(".navbar .menu").slimscroll({
  129. height: "200px",
  130. alwaysVisible: false,
  131. size: "3px"
  132. }).css("width", "100%");
  133. }
  134. //Activate sidebar push menu
  135. if (o.sidebarPushMenu) {
  136. $.AdminLTE.pushMenu(o.sidebarToggleSelector);
  137. }
  138. //Activate Bootstrap tooltip
  139. if (o.enableBSToppltip) {
  140. $(o.BSTooltipSelector).tooltip();
  141. }
  142. //Activate box widget
  143. if (o.enableBoxWidget) {
  144. $.AdminLTE.boxWidget.activate();
  145. }
  146. //Activate fast click
  147. if (o.enableFastclick && typeof FastClick != 'undefined') {
  148. FastClick.attach(document.body);
  149. }
  150. //Activate direct chat widget
  151. if (o.directChat.enable) {
  152. $(o.directChat.contactToggleSelector).click(function () {
  153. var box = $(this).parents('.direct-chat').first();
  154. box.toggleClass('direct-chat-contacts-open');
  155. });
  156. }
  157. /*
  158. * INITIALIZE BUTTON TOGGLE
  159. * ------------------------
  160. */
  161. $('.btn-group[data-toggle="btn-toggle"]').each(function () {
  162. var group = $(this);
  163. $(this).find(".btn").click(function (e) {
  164. group.find(".btn.active").removeClass("active");
  165. $(this).addClass("active");
  166. e.preventDefault();
  167. });
  168. });
  169. });
  170. /* ----------------------
  171. * - AdminLTE Functions -
  172. * ----------------------
  173. * All AdminLTE functions are implemented below.
  174. */
  175. /* prepareLayout
  176. * =============
  177. * Fixes the layout height in case min-height fails.
  178. *
  179. * @type Object
  180. * @usage $.AdminLTE.layout.activate()
  181. * $.AdminLTE.layout.fix()
  182. * $.AdminLTE.layout.fixSidebar()
  183. */
  184. $.AdminLTE.layout = {
  185. activate: function () {
  186. var _this = this;
  187. _this.fix();
  188. _this.fixSidebar();
  189. $(window, ".wrapper").resize(function () {
  190. _this.fix();
  191. _this.fixSidebar();
  192. });
  193. },
  194. fix: function () {
  195. //Get window height and the wrapper height
  196. var neg = $('.main-header').outerHeight() + $('.main-footer').outerHeight();
  197. var window_height = $(window).height();
  198. var sidebar_height = $(".sidebar").height();
  199. //Set the min-height of the content and sidebar based on the
  200. //the height of the document.
  201. if ($("body").hasClass("fixed")) {
  202. $(".content-wrapper, .right-side").css('min-height', window_height - $('.main-footer').outerHeight());
  203. } else {
  204. if (window_height >= sidebar_height) {
  205. $(".content-wrapper, .right-side").css('min-height', window_height - neg);
  206. } else {
  207. $(".content-wrapper, .right-side").css('min-height', sidebar_height);
  208. }
  209. }
  210. },
  211. fixSidebar: function () {
  212. //Make sure the body tag has the .fixed class
  213. if (!$("body").hasClass("fixed")) {
  214. if (typeof $.fn.slimScroll != 'undefined') {
  215. $(".sidebar").slimScroll({destroy: true}).height("auto");
  216. }
  217. return;
  218. } else if (typeof $.fn.slimScroll == 'undefined' && console) {
  219. console.error("Error: the fixed layout requires the slimscroll plugin!");
  220. }
  221. //Enable slimscroll for fixed layout
  222. if ($.AdminLTE.options.sidebarSlimScroll) {
  223. if (typeof $.fn.slimScroll != 'undefined') {
  224. //Distroy if it exists
  225. $(".sidebar").slimScroll({destroy: true}).height("auto");
  226. //Add slimscroll
  227. $(".sidebar").slimscroll({
  228. height: ($(window).height() - $(".main-header").height()) + "px",
  229. color: "rgba(0,0,0,0.2)",
  230. size: "3px"
  231. });
  232. }
  233. }
  234. }
  235. };
  236. /* PushMenu()
  237. * ==========
  238. * Adds the push menu functionality to the sidebar.
  239. *
  240. * @type Function
  241. * @usage: $.AdminLTE.pushMenu("[data-toggle='offcanvas']")
  242. */
  243. $.AdminLTE.pushMenu = function (toggleBtn) {
  244. //Get the screen sizes
  245. var screenSizes = this.options.screenSizes;
  246. //Enable sidebar toggle
  247. $(toggleBtn).click(function (e) {
  248. e.preventDefault();
  249. //Enable sidebar push menu
  250. if ($(window).width() > (screenSizes.sm - 1)) {
  251. $("body").toggleClass('sidebar-collapse');
  252. }
  253. //Handle sidebar push menu for small screens
  254. else {
  255. if ($("body").hasClass('sidebar-open')) {
  256. $("body").removeClass('sidebar-open');
  257. $("body").removeClass('sidebar-collapse')
  258. } else {
  259. $("body").addClass('sidebar-open');
  260. }
  261. }
  262. });
  263. $(".content-wrapper").click(function () {
  264. //Enable hide menu when clicking on the content-wrapper on small screens
  265. if ($(window).width() <= (screenSizes.sm - 1) && $("body").hasClass("sidebar-open")) {
  266. $("body").removeClass('sidebar-open');
  267. }
  268. });
  269. };
  270. /* Tree()
  271. * ======
  272. * Converts the sidebar into a multilevel
  273. * tree view menu.
  274. *
  275. * @type Function
  276. * @Usage: $.AdminLTE.tree('.sidebar')
  277. */
  278. $.AdminLTE.tree = function (menu) {
  279. var _this = this;
  280. $("li a", $(menu)).click(function (e) {
  281. //Get the clicked link and the next element
  282. var $this = $(this);
  283. var checkElement = $this.next();
  284. //Check if the next element is a menu and is visible
  285. if ((checkElement.is('.treeview-menu')) && (checkElement.is(':visible'))) {
  286. //Close the menu
  287. checkElement.slideUp('normal', function () {
  288. checkElement.removeClass('menu-open');
  289. //Fix the layout in case the sidebar stretches over the height of the window
  290. //_this.layout.fix();
  291. });
  292. checkElement.parent("li").removeClass("active");
  293. }
  294. //If the menu is not visible
  295. else if ((checkElement.is('.treeview-menu')) && (!checkElement.is(':visible'))) {
  296. //Get the parent menu
  297. var parent = $this.parents('ul').first();
  298. //Close all open menus within the parent
  299. var ul = parent.find('ul:visible').slideUp('normal');
  300. //Remove the menu-open class from the parent
  301. ul.removeClass('menu-open');
  302. //Get the parent li
  303. var parent_li = $this.parent("li");
  304. //Open the target menu and add the menu-open class
  305. checkElement.slideDown('normal', function () {
  306. //Add the class active to the parent li
  307. checkElement.addClass('menu-open');
  308. parent.find('li.active').removeClass('active');
  309. parent_li.addClass('active');
  310. //Fix the layout in case the sidebar stretches over the height of the window
  311. _this.layout.fix();
  312. });
  313. }
  314. //if this isn't a link, prevent the page from being redirected
  315. if (checkElement.is('.treeview-menu')) {
  316. e.preventDefault();
  317. }
  318. });
  319. };
  320. /* BoxWidget
  321. * =========
  322. * BoxWidget is plugin to handle collapsing and
  323. * removing boxes from the screen.
  324. *
  325. * @type Object
  326. * @usage $.AdminLTE.boxWidget.activate()
  327. * Set all of your option in the main $.AdminLTE.options object
  328. */
  329. $.AdminLTE.boxWidget = {
  330. activate: function () {
  331. var o = $.AdminLTE.options;
  332. var _this = this;
  333. //Listen for collapse event triggers
  334. $(o.boxWidgetOptions.boxWidgetSelectors.collapse).click(function (e) {
  335. e.preventDefault();
  336. _this.collapse($(this));
  337. });
  338. //Listen for remove event triggers
  339. $(o.boxWidgetOptions.boxWidgetSelectors.remove).click(function (e) {
  340. e.preventDefault();
  341. _this.remove($(this));
  342. });
  343. },
  344. collapse: function (element) {
  345. //Find the box parent
  346. var box = element.parents(".box").first();
  347. //Find the body and the footer
  348. var bf = box.find(".box-body, .box-footer");
  349. if (!box.hasClass("collapsed-box")) {
  350. //Convert minus into plus
  351. element.children(".fa-minus").removeClass("fa-minus").addClass("fa-plus");
  352. bf.slideUp(300, function () {
  353. box.addClass("collapsed-box");
  354. });
  355. } else {
  356. //Convert plus into minus
  357. element.children(".fa-plus").removeClass("fa-plus").addClass("fa-minus");
  358. bf.slideDown(300, function () {
  359. box.removeClass("collapsed-box");
  360. });
  361. }
  362. },
  363. remove: function (element) {
  364. //Find the box parent
  365. var box = element.parents(".box").first();
  366. box.slideUp();
  367. },
  368. options: $.AdminLTE.options.boxWidgetOptions
  369. };
  370. /* ------------------
  371. * - Custom Plugins -
  372. * ------------------
  373. * All custom plugins are defined below.
  374. */
  375. /*
  376. * BOX REFRESH BUTTON
  377. * ------------------
  378. * This is a custom plugin to use with the compenet BOX. It allows you to add
  379. * a refresh button to the box. It converts the box's state to a loading state.
  380. *
  381. * @type plugin
  382. * @usage $("#box-widget").boxRefresh( options );
  383. */
  384. (function ($) {
  385. $.fn.boxRefresh = function (options) {
  386. // Render options
  387. var settings = $.extend({
  388. //Refressh button selector
  389. trigger: ".refresh-btn",
  390. //File source to be loaded (e.g: ajax/src.php)
  391. source: "",
  392. //Callbacks
  393. onLoadStart: function (box) {
  394. }, //Right after the button has been clicked
  395. onLoadDone: function (box) {
  396. } //When the source has been loaded
  397. }, options);
  398. //The overlay
  399. var overlay = $('<div class="overlay"><div class="fa fa-refresh fa-spin"></div></div>');
  400. return this.each(function () {
  401. //if a source is specified
  402. if (settings.source === "") {
  403. if (console) {
  404. console.log("Please specify a source first - boxRefresh()");
  405. }
  406. return;
  407. }
  408. //the box
  409. var box = $(this);
  410. //the button
  411. var rBtn = box.find(settings.trigger).first();
  412. //On trigger click
  413. rBtn.click(function (e) {
  414. e.preventDefault();
  415. //Add loading overlay
  416. start(box);
  417. //Perform ajax call
  418. box.find(".box-body").load(settings.source, function () {
  419. done(box);
  420. });
  421. });
  422. });
  423. function start(box) {
  424. //Add overlay and loading img
  425. box.append(overlay);
  426. settings.onLoadStart.call(box);
  427. }
  428. function done(box) {
  429. //Remove overlay and loading img
  430. box.find(overlay).remove();
  431. settings.onLoadDone.call(box);
  432. }
  433. };
  434. })(jQuery);
  435. /*
  436. * TODO LIST CUSTOM PLUGIN
  437. * -----------------------
  438. * This plugin depends on iCheck plugin for checkbox and radio inputs
  439. *
  440. * @type plugin
  441. * @usage $("#todo-widget").todolist( options );
  442. */
  443. (function ($) {
  444. $.fn.todolist = function (options) {
  445. // Render options
  446. var settings = $.extend({
  447. //When the user checks the input
  448. onCheck: function (ele) {
  449. },
  450. //When the user unchecks the input
  451. onUncheck: function (ele) {
  452. }
  453. }, options);
  454. return this.each(function () {
  455. if (typeof $.fn.iCheck != 'undefined') {
  456. $('input', this).on('ifChecked', function (event) {
  457. var ele = $(this).parents("li").first();
  458. ele.toggleClass("done");
  459. settings.onCheck.call(ele);
  460. });
  461. $('input', this).on('ifUnchecked', function (event) {
  462. var ele = $(this).parents("li").first();
  463. ele.toggleClass("done");
  464. settings.onUncheck.call(ele);
  465. });
  466. } else {
  467. $('input', this).on('change', function (event) {
  468. var ele = $(this).parents("li").first();
  469. ele.toggleClass("done");
  470. settings.onCheck.call(ele);
  471. });
  472. }
  473. });
  474. };
  475. }(jQuery));