app.js 22 KB

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