app.js 22 KB

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