app.js 22 KB

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