app.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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
  11. * @license MIT <http://opensource.org/licenses/MIT>
  12. */
  13. //Make sure jQuery has been loaded before app.js
  14. if (typeof jQuery === "undefined") {
  15. throw new Error("AdminLTE requires jQuery");
  16. }
  17. 'use strict';
  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 = new Object();
  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
  45. sidebarSlimScroll: true,
  46. //BoxRefresh Plugin
  47. enableBoxRefresh: true,
  48. //Bootstrap.js tooltip
  49. enableBSToppltip: true,
  50. BSTooltipSelector: "[data-toggle='tooltip']",
  51. //Box Widget Plugin. Enable this plugin
  52. //to allow boxes to be collapsed and/or removed
  53. enableBoxWidget: true,
  54. //Box Widget plugin options
  55. boxWidgetOptions: {
  56. boxWidgetIcons: {
  57. //The icon that triggers the collapse event
  58. collapse: 'fa fa-minus',
  59. //The icon that trigger the opening event
  60. open: 'fa fa-plus',
  61. //The icon that triggers the removing event
  62. remove: 'fa fa-times'
  63. },
  64. boxWidgetSelectors: {
  65. //Remove button selector
  66. remove: '[data-widget="remove"]',
  67. //Collapse button selector
  68. collapse: '[data-widget="collapse"]'
  69. }
  70. },
  71. //Define the set of colors to use globally around the website
  72. colors: {
  73. lightBlue: "#3c8dbc",
  74. red: "#f56954",
  75. green: "#00a65a",
  76. aqua: "#00c0ef",
  77. yellow: "#f39c12",
  78. blue: "#0073b7",
  79. navy: "#001F3F",
  80. teal: "#39CCCC",
  81. olive: "#3D9970",
  82. lime: "#01FF70",
  83. orange: "#FF851B",
  84. fuchsia: "#F012BE",
  85. purple: "#8E24AA",
  86. maroon: "#D81B60",
  87. black: "#222222",
  88. gray: "#eaeaec"
  89. }
  90. };
  91. /* ------------------
  92. * - Implementation -
  93. * ------------------
  94. * The next block of code implements AdminLTE's
  95. * functions and plugins as specified by the
  96. * options above.
  97. */
  98. $(function () {
  99. //Easy access to options
  100. var o = $.AdminLTE.options;
  101. //Enable sidebar tree view controls
  102. $.AdminLTE.tree('.sidebar');
  103. //Activate the layout maker
  104. $.AdminLTE.layout.activate();
  105. //Add slimscroll to navbar dropdown
  106. if (o.navbarMenuSlimscroll && typeof $.fn.slimscroll != 'undefined') {
  107. $(".navbar .menu").slimscroll({
  108. height: "200px",
  109. alwaysVisible: false,
  110. size: "3px"
  111. }).css("width", "100%");
  112. }
  113. //Activate sidebar push menu
  114. if (o.sidebarPushMenu) {
  115. $.AdminLTE.pushMenu(o.sidebarToggleSelector);
  116. }
  117. //Activate Bootstrap tooltip
  118. if (o.enableBSToppltip) {
  119. $(o.BSTooltipSelector).tooltip();
  120. }
  121. //Activate box widget
  122. if (o.enableBoxWidget) {
  123. $.AdminLTE.boxWidget.activate();
  124. }
  125. /*
  126. * INITIALIZE BUTTON TOGGLE
  127. * ------------------------
  128. */
  129. $('.btn-group[data-toggle="btn-toggle"]').each(function () {
  130. var group = $(this);
  131. $(this).find(".btn").click(function (e) {
  132. group.find(".btn.active").removeClass("active");
  133. $(this).addClass("active");
  134. e.preventDefault();
  135. });
  136. });
  137. });
  138. /* ----------------------
  139. * - AdminLTE Functions -
  140. * ----------------------
  141. * All AdminLTE functions are implemented below.
  142. */
  143. /* prepareLayout
  144. * =============
  145. * Fixes the layout height in case min-height fails.
  146. *
  147. * @type Object
  148. * @usage $.AdminLTE.layout.activate()
  149. * $.AdminLTE.layout.fix()
  150. * $.AdminLTE.layout.fixSidebar()
  151. */
  152. $.AdminLTE.layout = {
  153. activate: function () {
  154. var _this = this;
  155. _this.fix();
  156. _this.fixSidebar();
  157. $(".wrapper").resize(function () {
  158. _this.fix();
  159. _this.fixSidebar();
  160. });
  161. },
  162. fix: function () {
  163. //Get window height and the wrapper height
  164. var neg = $('.main-header').height() + $('.main-footer').height();
  165. var window_height = $(window).height();
  166. var sidebar_height = $(".main-sidebar, .left-side").height();
  167. //Set the min-height of the content and sidebar based on the
  168. //the maximum height of the document.
  169. if (window_height >= sidebar_height) {
  170. $(".content-wrapper, .main-sidebar, .left-side, .right-side").css('min-height', window_height - neg);
  171. } else {
  172. $(".content-wrapper, .main-sidebar, .left-side, .right-side").css('min-height', sidebar_height);
  173. }
  174. },
  175. fixSidebar: function () {
  176. //Make sure the body tag has the .fixed class
  177. if (!$("body").hasClass("fixed")) {
  178. if (typeof $.fn.slimScroll != 'undefined') {
  179. $(".sidebar").slimScroll({destroy: true}).height("auto");
  180. }
  181. return;
  182. }
  183. //Enable slimscroll for fixed layout
  184. if ($.AdminLTE.options.sidebarSlimScroll) {
  185. if (typeof $.fn.slimScroll != 'undefined') {
  186. //Add slimscroll
  187. $(".sidebar").slimscroll({
  188. height: ($(window).height() - $(".main-header").height()) + "px",
  189. color: "rgba(0,0,0,0.2)",
  190. size: "3px"
  191. });
  192. }
  193. }
  194. }
  195. };
  196. /* PushMenu()
  197. * ==========
  198. * Adds the push menu functionality to the sidebar.
  199. *
  200. * @type Function
  201. * @usage: $.AdminLTE.pushMenu("[data-toggle='offcanvas']")
  202. */
  203. $.AdminLTE.pushMenu = function (toggleBtn) {
  204. //Enable sidebar toggle
  205. $(toggleBtn).click(function (e) {
  206. e.preventDefault();
  207. //Enable sidebar push menu
  208. $("body").toggleClass('sidebar-collapse');
  209. $("body").toggleClass('sidebar-open');
  210. });
  211. };
  212. /* Tree()
  213. * ======
  214. * Converts the sidebar into a multilevel
  215. * tree view menu.
  216. *
  217. * @type Function
  218. * @Usage: $.AdminLTE.tree('.sidebar')
  219. */
  220. $.AdminLTE.tree = function (menu) {
  221. $("li a", $(menu)).click(function (e) {
  222. //Get the clicked link and the next element
  223. var $this = $(this);
  224. var checkElement = $this.next();
  225. //Check if the next element is a menu and is visible
  226. if ((checkElement.is('.treeview-menu')) && (checkElement.is(':visible'))) {
  227. //Close the menu
  228. checkElement.slideUp('normal', function () {
  229. checkElement.removeClass('menu-open');
  230. });
  231. checkElement.parent("li").removeClass("active");
  232. }
  233. //If the menu is not visible
  234. else if ((checkElement.is('.treeview-menu')) && (!checkElement.is(':visible'))) {
  235. //Get the parent menu
  236. var parent = $this.parents('ul').first();
  237. //Close all open menus within the parent
  238. var ul = parent.find('ul:visible').slideUp('normal');
  239. //Remove the menu-open class from the parent
  240. ul.removeClass('menu-open');
  241. //Get the parent li
  242. var parent_li = $this.parent("li");
  243. //Open the target menu and add the menu-open class
  244. checkElement.slideDown('normal', function () {
  245. //Add the class active to the parent li
  246. checkElement.addClass('menu-open');
  247. parent.find('li.active').removeClass('active');
  248. parent_li.addClass('active');
  249. });
  250. }
  251. //if this isn't a link, prevent the page from being redirected
  252. if (checkElement.is('.treeview-menu')) {
  253. e.preventDefault();
  254. }
  255. });
  256. };
  257. /* BoxWidget
  258. * =========
  259. * BoxWidget is plugin to handle collapsing and
  260. * removing boxes from the screen.
  261. *
  262. * @type Object
  263. * @usage $.AdminLTE.boxWidget.activate()
  264. * Set all of your option in the main $.AdminLTE.options object
  265. */
  266. $.AdminLTE.boxWidget = {
  267. activate: function () {
  268. var o = $.AdminLTE.options;
  269. var _this = this;
  270. //Listen for collapse event triggers
  271. $(o.boxWidgetOptions.boxWidgetSelectors.collapse).click(function (e) {
  272. e.preventDefault();
  273. _this.collapse($(this));
  274. });
  275. //Listen for remove event triggers
  276. $(o.boxWidgetOptions.boxWidgetSelectors.remove).click(function (e) {
  277. e.preventDefault();
  278. _this.remove($(this));
  279. });
  280. },
  281. collapse: function (element) {
  282. //Find the box parent
  283. var box = element.parents(".box").first();
  284. //Find the body and the footer
  285. var bf = box.find(".box-body, .box-footer");
  286. if (!box.hasClass("collapsed-box")) {
  287. //Convert minus into plus
  288. element.children(".fa-minus").removeClass("fa-minus").addClass("fa-plus");
  289. bf.slideUp(300, function () {
  290. box.addClass("collapsed-box");
  291. });
  292. } else {
  293. //Convert plus into minus
  294. element.children(".fa-plus").removeClass("fa-plus").addClass("fa-minus");
  295. bf.slideDown(300, function () {
  296. box.removeClass("collapsed-box");
  297. });
  298. }
  299. },
  300. remove: function (element) {
  301. //Find the box parent
  302. var box = element.parents(".box").first();
  303. box.slideUp();
  304. },
  305. options: $.AdminLTE.options.boxWidgetOptions
  306. };
  307. /* ------------------
  308. * - Custom Plugins -
  309. * ------------------
  310. * All custom plugins are defined below.
  311. */
  312. /*
  313. * BOX REFRESH BUTTON
  314. * ------------------
  315. * This is a custom plugin to use with the compenet BOX. It allows you to add
  316. * a refresh button to the box. It converts the box's state to a loading state.
  317. *
  318. * @type plugin
  319. * @usage $("#box-widget").boxRefresh( options );
  320. */
  321. (function ($) {
  322. $.fn.boxRefresh = function (options) {
  323. // Render options
  324. var settings = $.extend({
  325. //Refressh button selector
  326. trigger: ".refresh-btn",
  327. //File source to be loaded (e.g: ajax/src.php)
  328. source: "",
  329. //Callbacks
  330. onLoadStart: function (box) {
  331. }, //Right after the button has been clicked
  332. onLoadDone: function (box) {
  333. } //When the source has been loaded
  334. }, options);
  335. //The overlay
  336. var overlay = $('<div class="overlay"></div><div class="loading-img"></div>');
  337. return this.each(function () {
  338. //if a source is specified
  339. if (settings.source === "") {
  340. if (console) {
  341. console.log("Please specify a source first - boxRefresh()");
  342. }
  343. return;
  344. }
  345. //the box
  346. var box = $(this);
  347. //the button
  348. var rBtn = box.find(settings.trigger).first();
  349. //On trigger click
  350. rBtn.click(function (e) {
  351. e.preventDefault();
  352. //Add loading overlay
  353. start(box);
  354. //Perform ajax call
  355. box.find(".box-body").load(settings.source, function () {
  356. done(box);
  357. });
  358. });
  359. });
  360. function start(box) {
  361. //Add overlay and loading img
  362. box.append(overlay);
  363. settings.onLoadStart.call(box);
  364. }
  365. function done(box) {
  366. //Remove overlay and loading img
  367. box.find(overlay).remove();
  368. settings.onLoadDone.call(box);
  369. }
  370. };
  371. })(jQuery);
  372. /*
  373. * TODO LIST CUSTOM PLUGIN
  374. * -----------------------
  375. * This plugin depends on iCheck plugin for checkbox and radio inputs
  376. *
  377. * @type plugin
  378. * @usage $("#todo-widget").todolist( options );
  379. */
  380. (function ($) {
  381. $.fn.todolist = function (options) {
  382. // Render options
  383. var settings = $.extend({
  384. //When the user checks the input
  385. onCheck: function (ele) {
  386. },
  387. //When the user unchecks the input
  388. onUncheck: function (ele) {
  389. }
  390. }, options);
  391. return this.each(function () {
  392. if (typeof $.fn.iCheck != 'undefined') {
  393. $('input', this).on('ifChecked', function (event) {
  394. var ele = $(this).parents("li").first();
  395. ele.toggleClass("done");
  396. settings.onCheck.call(ele);
  397. });
  398. $('input', this).on('ifUnchecked', function (event) {
  399. var ele = $(this).parents("li").first();
  400. ele.toggleClass("done");
  401. settings.onUncheck.call(ele);
  402. });
  403. } else {
  404. $('input', this).on('change', function (event) {
  405. var ele = $(this).parents("li").first();
  406. ele.toggleClass("done");
  407. settings.onCheck.call(ele);
  408. });
  409. }
  410. });
  411. };
  412. }(jQuery));