app.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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.0
  11. * @license MIT <http://opensource.org/licenses/MIT>
  12. */
  13. 'use strict';
  14. //Make sure jQuery has been loaded before app.js
  15. if (typeof jQuery === "undefined") {
  16. throw new Error("AdminLTE requires jQuery");
  17. }
  18. /* AdminLTE
  19. *
  20. * @type Object
  21. * @description $.AdminLTE is the main object for the template's app.
  22. * It's used for implementing functions and options related
  23. * to the template. Keeping everything wrapped in an object
  24. * prevents conflict with other plugins and is a better
  25. * way to organize our code.
  26. */
  27. $.AdminLTE = {};
  28. /* --------------------
  29. * - AdminLTE Options -
  30. * --------------------
  31. * Modify these options to suit your implementation
  32. */
  33. $.AdminLTE.options = {
  34. //Add slimscroll to navbar menus
  35. //This requires you to load the slimscroll plugin
  36. //in every page before app.js
  37. navbarMenuSlimscroll: true,
  38. navbarMenuSlimscrollWidth: "3px", //The width of the scroll bar
  39. navbarMenuHeight: "200px", //The height of the inner menu
  40. //General animation speed for JS animated elements such as box collapse/expand and
  41. //sidebar treeview slide up/down. This options accepts an integer as milliseconds,
  42. //'fast', 'normal', or 'slow'
  43. animationSpeed: 500,
  44. //Sidebar push menu toggle button selector
  45. sidebarToggleSelector: "[data-toggle='offcanvas']",
  46. //Activate sidebar push menu
  47. sidebarPushMenu: true,
  48. //Activate sidebar slimscroll if the fixed layout is set (requires SlimScroll Plugin)
  49. sidebarSlimScroll: true,
  50. //Enable sidebar expand on hover effect for sidebar mini
  51. //This option is forced to true if both the fixed layout and sidebar mini
  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. //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. $(o.directChat.contactToggleSelector).on('click', 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. /* Layout
  209. * ======
  210. * Fixes the layout height in case min-height fails.
  211. *
  212. * @type Object
  213. * @usage $.AdminLTE.layout.activate()
  214. * $.AdminLTE.layout.fix()
  215. * $.AdminLTE.layout.fixSidebar()
  216. */
  217. $.AdminLTE.layout = {
  218. activate: function () {
  219. var _this = this;
  220. _this.fix();
  221. _this.fixSidebar();
  222. $(window, ".wrapper").resize(function () {
  223. _this.fix();
  224. _this.fixSidebar();
  225. });
  226. },
  227. fix: function () {
  228. //Get window height and the wrapper height
  229. var neg = $('.main-header').outerHeight() + $('.main-footer').outerHeight();
  230. var window_height = $(window).height();
  231. var sidebar_height = $(".sidebar").height();
  232. //Set the min-height of the content and sidebar based on the
  233. //the height of the document.
  234. if ($("body").hasClass("fixed")) {
  235. $(".content-wrapper, .right-side").css('min-height', window_height - $('.main-footer').outerHeight());
  236. } else {
  237. var postSetWidth;
  238. if (window_height >= sidebar_height) {
  239. $(".content-wrapper, .right-side").css('min-height', window_height - neg);
  240. postSetWidth = window_height - neg;
  241. } else {
  242. $(".content-wrapper, .right-side").css('min-height', sidebar_height);
  243. postSetWidth = sidebar_height;
  244. }
  245. //Fix for the control sidebar height
  246. var controlSidebar = $($.AdminLTE.options.controlSidebarOptions.selector);
  247. if (typeof controlSidebar !== "undefined") {
  248. if (controlSidebar.height() > postSetWidth)
  249. $(".content-wrapper, .right-side").css('min-height', controlSidebar.height());
  250. }
  251. }
  252. },
  253. fixSidebar: function () {
  254. //Make sure the body tag has the .fixed class
  255. if (!$("body").hasClass("fixed")) {
  256. if (typeof $.fn.slimScroll != 'undefined') {
  257. $(".sidebar").slimScroll({destroy: true}).height("auto");
  258. }
  259. return;
  260. } else if (typeof $.fn.slimScroll == 'undefined' && console) {
  261. console.error("Error: the fixed layout requires the slimscroll plugin!");
  262. }
  263. //Enable slimscroll for fixed layout
  264. if ($.AdminLTE.options.sidebarSlimScroll) {
  265. if (typeof $.fn.slimScroll != 'undefined') {
  266. //Destroy if it exists
  267. $(".sidebar").slimScroll({destroy: true}).height("auto");
  268. //Add slimscroll
  269. $(".sidebar").slimscroll({
  270. height: ($(window).height() - $(".main-header").height()) + "px",
  271. color: "rgba(0,0,0,0.2)",
  272. size: "3px"
  273. });
  274. }
  275. }
  276. }
  277. };
  278. /* PushMenu()
  279. * ==========
  280. * Adds the push menu functionality to the sidebar.
  281. *
  282. * @type Function
  283. * @usage: $.AdminLTE.pushMenu("[data-toggle='offcanvas']")
  284. */
  285. $.AdminLTE.pushMenu = {
  286. activate: function (toggleBtn) {
  287. //Get the screen sizes
  288. var screenSizes = $.AdminLTE.options.screenSizes;
  289. //Enable sidebar toggle
  290. $(toggleBtn).on('click', function (e) {
  291. e.preventDefault();
  292. //Enable sidebar push menu
  293. if ($(window).width() > (screenSizes.sm - 1)) {
  294. $("body").toggleClass('sidebar-collapse');
  295. }
  296. //Handle sidebar push menu for small screens
  297. else {
  298. if ($("body").hasClass('sidebar-open')) {
  299. $("body").removeClass('sidebar-open');
  300. $("body").removeClass('sidebar-collapse')
  301. } else {
  302. $("body").addClass('sidebar-open');
  303. }
  304. }
  305. });
  306. $(".content-wrapper").click(function () {
  307. //Enable hide menu when clicking on the content-wrapper on small screens
  308. if ($(window).width() <= (screenSizes.sm - 1) && $("body").hasClass("sidebar-open")) {
  309. $("body").removeClass('sidebar-open');
  310. }
  311. });
  312. //Enable expand on hover for sidebar mini
  313. if ($.AdminLTE.options.sidebarExpandOnHover
  314. || ($('body').hasClass('fixed')
  315. && $('body').hasClass('sidebar-mini'))) {
  316. this.expandOnHover();
  317. }
  318. },
  319. expandOnHover: function () {
  320. var _this = this;
  321. var screenWidth = $.AdminLTE.options.screenSizes.sm - 1;
  322. //Expand sidebar on hover
  323. $('.main-sidebar').hover(function () {
  324. if ($('body').hasClass('sidebar-mini')
  325. && $("body").hasClass('sidebar-collapse')
  326. && $(window).width() > screenWidth) {
  327. _this.expand();
  328. }
  329. }, function () {
  330. if ($('body').hasClass('sidebar-mini')
  331. && $('body').hasClass('sidebar-expanded-on-hover')
  332. && $(window).width() > screenWidth) {
  333. _this.collapse();
  334. }
  335. });
  336. },
  337. expand: function () {
  338. $("body").removeClass('sidebar-collapse').addClass('sidebar-expanded-on-hover');
  339. },
  340. collapse: function () {
  341. if ($('body').hasClass('sidebar-expanded-on-hover')) {
  342. $('body').removeClass('sidebar-expanded-on-hover').addClass('sidebar-collapse');
  343. }
  344. }
  345. };
  346. /* Tree()
  347. * ======
  348. * Converts the sidebar into a multilevel
  349. * tree view menu.
  350. *
  351. * @type Function
  352. * @Usage: $.AdminLTE.tree('.sidebar')
  353. */
  354. $.AdminLTE.tree = function (menu) {
  355. var _this = this;
  356. var animationSpeed = $.AdminLTE.options.animationSpeed;
  357. $("li a", $(menu)).on('click', function (e) {
  358. //Get the clicked link and the next element
  359. var $this = $(this);
  360. var checkElement = $this.next();
  361. //Check if the next element is a menu and is visible
  362. if ((checkElement.is('.treeview-menu')) && (checkElement.is(':visible'))) {
  363. //Close the menu
  364. checkElement.slideUp(animationSpeed, function () {
  365. checkElement.removeClass('menu-open');
  366. //Fix the layout in case the sidebar stretches over the height of the window
  367. //_this.layout.fix();
  368. });
  369. checkElement.parent("li").removeClass("active");
  370. }
  371. //If the menu is not visible
  372. else if ((checkElement.is('.treeview-menu')) && (!checkElement.is(':visible'))) {
  373. //Get the parent menu
  374. var parent = $this.parents('ul').first();
  375. //Close all open menus within the parent
  376. var ul = parent.find('ul:visible').slideUp(animationSpeed);
  377. //Remove the menu-open class from the parent
  378. ul.removeClass('menu-open');
  379. //Get the parent li
  380. var parent_li = $this.parent("li");
  381. //Open the target menu and add the menu-open class
  382. checkElement.slideDown(animationSpeed, function () {
  383. //Add the class active to the parent li
  384. checkElement.addClass('menu-open');
  385. parent.find('li.active').removeClass('active');
  386. parent_li.addClass('active');
  387. //Fix the layout in case the sidebar stretches over the height of the window
  388. _this.layout.fix();
  389. });
  390. }
  391. //if this isn't a link, prevent the page from being redirected
  392. if (checkElement.is('.treeview-menu')) {
  393. e.preventDefault();
  394. }
  395. });
  396. };
  397. /* ControlSidebar
  398. * ==============
  399. * Adds functionality to the right sidebar
  400. *
  401. * @type Object
  402. * @usage $.AdminLTE.controlSidebar.activate(options)
  403. */
  404. $.AdminLTE.controlSidebar = {
  405. //instantiate the object
  406. activate: function () {
  407. //Get the object
  408. var _this = this;
  409. //Update options
  410. var o = $.AdminLTE.options.controlSidebarOptions;
  411. //Get the sidebar
  412. var sidebar = $(o.selector);
  413. //The toggle button
  414. var btn = $(o.toggleBtnSelector);
  415. //Listen to the click event
  416. btn.on('click', function (e) {
  417. e.preventDefault();
  418. //If the sidebar is not open
  419. if (!sidebar.hasClass('control-sidebar-open')
  420. && !$('body').hasClass('control-sidebar-open')) {
  421. //Open the sidebar
  422. _this.open(sidebar, o.slide);
  423. } else {
  424. _this.close(sidebar, o.slide);
  425. }
  426. });
  427. //If the body has a boxed layout, fix the sidebar bg position
  428. var bg = $(".control-sidebar-bg");
  429. _this._fix(bg);
  430. //If the body has a fixed layout, make the control sidebar fixed
  431. if ($('body').hasClass('fixed')) {
  432. _this._fixForFixed(sidebar);
  433. } else {
  434. //If the content height is less than the sidebar's height, force max height
  435. if ($('.content-wrapper, .right-side').height() < sidebar.height()) {
  436. _this._fixForContent(sidebar);
  437. }
  438. }
  439. },
  440. //Open the control sidebar
  441. open: function (sidebar, slide) {
  442. var _this = this;
  443. //Slide over content
  444. if (slide) {
  445. sidebar.addClass('control-sidebar-open');
  446. } else {
  447. //Push the content by adding the open class to the body instead
  448. //of the sidebar itself
  449. $('body').addClass('control-sidebar-open');
  450. }
  451. },
  452. //Close the control sidebar
  453. close: function (sidebar, slide) {
  454. if (slide) {
  455. sidebar.removeClass('control-sidebar-open');
  456. } else {
  457. $('body').removeClass('control-sidebar-open');
  458. }
  459. },
  460. _fix: function (sidebar) {
  461. var _this = this;
  462. if ($("body").hasClass('layout-boxed')) {
  463. sidebar.css('position', 'absolute');
  464. sidebar.height($(".wrapper").height());
  465. $(window).resize(function () {
  466. _this._fix(sidebar);
  467. });
  468. } else {
  469. sidebar.css({
  470. 'position': 'fixed',
  471. 'height': 'auto'
  472. });
  473. }
  474. },
  475. _fixForFixed: function (sidebar) {
  476. sidebar.css({
  477. 'position': 'fixed',
  478. 'max-height': '100%',
  479. 'overflow': 'auto',
  480. 'padding-bottom': '50px'
  481. });
  482. },
  483. _fixForContent: function (sidebar) {
  484. $(".content-wrapper, .right-side").css('min-height', sidebar.height());
  485. }
  486. };
  487. /* BoxWidget
  488. * =========
  489. * BoxWidget is a plugin to handle collapsing and
  490. * removing boxes from the screen.
  491. *
  492. * @type Object
  493. * @usage $.AdminLTE.boxWidget.activate()
  494. * Set all your options in the main $.AdminLTE.options object
  495. */
  496. $.AdminLTE.boxWidget = {
  497. selectors: $.AdminLTE.options.boxWidgetOptions.boxWidgetSelectors,
  498. icons: $.AdminLTE.options.boxWidgetOptions.boxWidgetIcons,
  499. animationSpeed: $.AdminLTE.options.animationSpeed,
  500. activate: function (_box) {
  501. var _this = this;
  502. if (! _box) {
  503. _box = document; // activate all boxes per default
  504. }
  505. //Listen for collapse event triggers
  506. $(_box).find(_this.selectors.collapse).on('click', function (e) {
  507. e.preventDefault();
  508. _this.collapse($(this));
  509. });
  510. //Listen for remove event triggers
  511. $(_box).find(_this.selectors.remove).on('click', function (e) {
  512. e.preventDefault();
  513. _this.remove($(this));
  514. });
  515. },
  516. collapse: function (element) {
  517. var _this = this;
  518. //Find the box parent
  519. var box = element.parents(".box").first();
  520. //Find the body and the footer
  521. var box_content = box.find("> .box-body, > .box-footer");
  522. if (!box.hasClass("collapsed-box")) {
  523. //Convert minus into plus
  524. element.children(":first")
  525. .removeClass(_this.icons.collapse)
  526. .addClass(_this.icons.open);
  527. //Hide the content
  528. box_content.slideUp(_this.animationSpeed, function () {
  529. box.addClass("collapsed-box");
  530. });
  531. } else {
  532. //Convert plus into minus
  533. element.children(":first")
  534. .removeClass(_this.icons.open)
  535. .addClass(_this.icons.collapse);
  536. //Show the content
  537. box_content.slideDown(_this.animationSpeed, function () {
  538. box.removeClass("collapsed-box");
  539. });
  540. }
  541. },
  542. remove: function (element) {
  543. //Find the box parent
  544. var box = element.parents(".box").first();
  545. box.slideUp(this.animationSpeed);
  546. }
  547. };
  548. }
  549. /* ------------------
  550. * - Custom Plugins -
  551. * ------------------
  552. * All custom plugins are defined below.
  553. */
  554. /*
  555. * BOX REFRESH BUTTON
  556. * ------------------
  557. * This is a custom plugin to use with the component BOX. It allows you to add
  558. * a refresh button to the box. It converts the box's state to a loading state.
  559. *
  560. * @type plugin
  561. * @usage $("#box-widget").boxRefresh( options );
  562. */
  563. (function ($) {
  564. $.fn.boxRefresh = function (options) {
  565. // Render options
  566. var settings = $.extend({
  567. //Refresh button selector
  568. trigger: ".refresh-btn",
  569. //File source to be loaded (e.g: ajax/src.php)
  570. source: "",
  571. //Callbacks
  572. onLoadStart: function (box) {
  573. }, //Right after the button has been clicked
  574. onLoadDone: function (box) {
  575. } //When the source has been loaded
  576. }, options);
  577. //The overlay
  578. var overlay = $('<div class="overlay"><div class="fa fa-refresh fa-spin"></div></div>');
  579. return this.each(function () {
  580. //if a source is specified
  581. if (settings.source === "") {
  582. if (console) {
  583. console.log("Please specify a source first - boxRefresh()");
  584. }
  585. return;
  586. }
  587. //the box
  588. var box = $(this);
  589. //the button
  590. var rBtn = box.find(settings.trigger).first();
  591. //On trigger click
  592. rBtn.on('click', function (e) {
  593. e.preventDefault();
  594. //Add loading overlay
  595. start(box);
  596. //Perform ajax call
  597. box.find(".box-body").load(settings.source, function () {
  598. done(box);
  599. });
  600. });
  601. });
  602. function start(box) {
  603. //Add overlay and loading img
  604. box.append(overlay);
  605. settings.onLoadStart.call(box);
  606. }
  607. function done(box) {
  608. //Remove overlay and loading img
  609. box.find(overlay).remove();
  610. settings.onLoadDone.call(box);
  611. }
  612. };
  613. })(jQuery);
  614. /*
  615. * EXPLICIT BOX ACTIVATION
  616. * -----------------------
  617. * This is a custom plugin to use with the component BOX. It allows you to activate
  618. * a box inserted in the DOM after the app.js was loaded.
  619. *
  620. * @type plugin
  621. * @usage $("#box-widget").activateBox();
  622. */
  623. (function ($) {
  624. $.fn.activateBox = function () {
  625. $.AdminLTE.boxWidget.activate(this);
  626. };
  627. })(jQuery);
  628. /*
  629. * TODO LIST CUSTOM PLUGIN
  630. * -----------------------
  631. * This plugin depends on iCheck plugin for checkbox and radio inputs
  632. *
  633. * @type plugin
  634. * @usage $("#todo-widget").todolist( options );
  635. */
  636. (function ($) {
  637. $.fn.todolist = function (options) {
  638. // Render options
  639. var settings = $.extend({
  640. //When the user checks the input
  641. onCheck: function (ele) {
  642. },
  643. //When the user unchecks the input
  644. onUncheck: function (ele) {
  645. }
  646. }, options);
  647. return this.each(function () {
  648. if (typeof $.fn.iCheck != 'undefined') {
  649. $('input', this).on('ifChecked', function (event) {
  650. var ele = $(this).parents("li").first();
  651. ele.toggleClass("done");
  652. settings.onCheck.call(ele);
  653. });
  654. $('input', this).on('ifUnchecked', function (event) {
  655. var ele = $(this).parents("li").first();
  656. ele.toggleClass("done");
  657. settings.onUncheck.call(ele);
  658. });
  659. } else {
  660. $('input', this).on('change', function (event) {
  661. var ele = $(this).parents("li").first();
  662. ele.toggleClass("done");
  663. settings.onCheck.call(ele);
  664. });
  665. }
  666. });
  667. };
  668. }(jQuery));