adminlte.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  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 <abdullah@almsaeedstudio.com>
  10. * @version 2.3.7
  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: 300,
  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: false,
  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. //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. var controlSidebar = $($.AdminLTE.options.controlSidebarOptions.selector);
  250. if (typeof controlSidebar !== "undefined") {
  251. if (controlSidebar.height() > postSetWidth)
  252. $(".content-wrapper, .right-side").css('min-height', controlSidebar.height());
  253. }
  254. }
  255. },
  256. fixSidebar: function () {
  257. //Make sure the body tag has the .fixed class
  258. if (!$("body").hasClass("fixed")) {
  259. if (typeof $.fn.slimScroll != 'undefined') {
  260. $(".sidebar").slimScroll({destroy: true}).height("auto");
  261. }
  262. return;
  263. } else if (typeof $.fn.slimScroll == 'undefined' && window.console) {
  264. window.console.error("Error: the fixed layout requires the slimscroll plugin!");
  265. }
  266. //Enable slimscroll for fixed layout
  267. if ($.AdminLTE.options.sidebarSlimScroll) {
  268. if (typeof $.fn.slimScroll != 'undefined') {
  269. //Destroy if it exists
  270. $(".sidebar").slimScroll({destroy: true}).height("auto");
  271. //Add slimscroll
  272. $(".sidebar").slimscroll({
  273. height: ($(window).height() - $(".main-header").height()) + "px",
  274. color: "rgba(0,0,0,0.2)",
  275. size: "3px"
  276. });
  277. }
  278. }
  279. }
  280. };
  281. /* PushMenu()
  282. * ==========
  283. * Adds the push menu functionality to the sidebar.
  284. *
  285. * @type Function
  286. * @usage: $.AdminLTE.pushMenu("[data-toggle='offcanvas']")
  287. */
  288. $.AdminLTE.pushMenu = {
  289. activate: function (toggleBtn) {
  290. //Get the screen sizes
  291. var screenSizes = $.AdminLTE.options.screenSizes;
  292. //Enable sidebar toggle
  293. $(document).on('click', toggleBtn, function (e) {
  294. e.preventDefault();
  295. //Enable sidebar push menu
  296. if ($(window).width() > (screenSizes.sm - 1)) {
  297. if ($("body").hasClass('sidebar-collapse')) {
  298. $("body").removeClass('sidebar-collapse').trigger('expanded.pushMenu');
  299. } else {
  300. $("body").addClass('sidebar-collapse').trigger('collapsed.pushMenu');
  301. }
  302. }
  303. //Handle sidebar push menu for small screens
  304. else {
  305. if ($("body").hasClass('sidebar-open')) {
  306. $("body").removeClass('sidebar-open').removeClass('sidebar-collapse').trigger('collapsed.pushMenu');
  307. } else {
  308. $("body").addClass('sidebar-open').trigger('expanded.pushMenu');
  309. }
  310. }
  311. });
  312. $(".content-wrapper").click(function () {
  313. //Enable hide menu when clicking on the content-wrapper on small screens
  314. if ($(window).width() <= (screenSizes.sm - 1) && $("body").hasClass("sidebar-open")) {
  315. $("body").removeClass('sidebar-open');
  316. }
  317. });
  318. //Enable expand on hover for sidebar mini
  319. if ($.AdminLTE.options.sidebarExpandOnHover
  320. || ($('body').hasClass('fixed')
  321. && $('body').hasClass('sidebar-mini'))) {
  322. this.expandOnHover();
  323. }
  324. },
  325. expandOnHover: function () {
  326. var _this = this;
  327. var screenWidth = $.AdminLTE.options.screenSizes.sm - 1;
  328. //Expand sidebar on hover
  329. $('.main-sidebar').hover(function () {
  330. if ($('body').hasClass('sidebar-mini')
  331. && $("body").hasClass('sidebar-collapse')
  332. && $(window).width() > screenWidth) {
  333. _this.expand();
  334. }
  335. }, function () {
  336. if ($('body').hasClass('sidebar-mini')
  337. && $('body').hasClass('sidebar-expanded-on-hover')
  338. && $(window).width() > screenWidth) {
  339. _this.collapse();
  340. }
  341. });
  342. },
  343. expand: function () {
  344. $("body").removeClass('sidebar-collapse').addClass('sidebar-expanded-on-hover');
  345. },
  346. collapse: function () {
  347. if ($('body').hasClass('sidebar-expanded-on-hover')) {
  348. $('body').removeClass('sidebar-expanded-on-hover').addClass('sidebar-collapse');
  349. }
  350. }
  351. };
  352. /* Tree()
  353. * ======
  354. * Converts the sidebar into a multilevel
  355. * tree view menu.
  356. *
  357. * @type Function
  358. * @Usage: $.AdminLTE.tree('.sidebar')
  359. */
  360. $.AdminLTE.tree = function (menu) {
  361. var _this = this;
  362. var animationSpeed = $.AdminLTE.options.animationSpeed;
  363. $(document).off('click', menu + ' li a')
  364. .on('click', menu + ' 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. if ($(".show-submenu", menu).size() == 0) {
  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. }
  388. //Get the parent li
  389. var parent_li = $this.parent("li");
  390. //Open the target menu and add the menu-open class
  391. checkElement.slideDown(animationSpeed, function () {
  392. //Add the class active to the parent li
  393. checkElement.addClass('menu-open');
  394. //parent.find('li.active').removeClass('active');
  395. //parent_li.addClass('active');
  396. //Fix the layout in case the sidebar stretches over the height of the window
  397. _this.layout.fix();
  398. });
  399. } else {
  400. if (!$this.parent().hasClass("active")) {
  401. $this.parent().addClass("active");
  402. }
  403. if ($(".show-submenu", menu).size() == 0) {
  404. $this.parent().siblings().find("ul.menu-open").slideUp();
  405. }
  406. }
  407. //if this isn't a link, prevent the page from being redirected
  408. if (checkElement.is('.treeview-menu')) {
  409. e.preventDefault();
  410. }
  411. });
  412. };
  413. /* ControlSidebar
  414. * ==============
  415. * Adds functionality to the right sidebar
  416. *
  417. * @type Object
  418. * @usage $.AdminLTE.controlSidebar.activate(options)
  419. */
  420. $.AdminLTE.controlSidebar = {
  421. //instantiate the object
  422. activate: function () {
  423. //Get the object
  424. var _this = this;
  425. //Update options
  426. var o = $.AdminLTE.options.controlSidebarOptions;
  427. //Get the sidebar
  428. var sidebar = $(o.selector);
  429. //The toggle button
  430. var btn = $(o.toggleBtnSelector);
  431. //Listen to the click event
  432. btn.on('click', function (e) {
  433. e.preventDefault();
  434. //If the sidebar is not open
  435. if (!sidebar.hasClass('control-sidebar-open')
  436. && !$('body').hasClass('control-sidebar-open')) {
  437. //Open the sidebar
  438. _this.open(sidebar, o.slide);
  439. } else {
  440. _this.close(sidebar, o.slide);
  441. }
  442. });
  443. //If the body has a boxed layout, fix the sidebar bg position
  444. var bg = $(".control-sidebar-bg");
  445. _this._fix(bg);
  446. //If the body has a fixed layout, make the control sidebar fixed
  447. if ($('body').hasClass('fixed')) {
  448. _this._fixForFixed(sidebar);
  449. } else {
  450. //If the content height is less than the sidebar's height, force max height
  451. if ($('.content-wrapper, .right-side').height() < sidebar.height()) {
  452. _this._fixForContent(sidebar);
  453. }
  454. }
  455. },
  456. //Open the control sidebar
  457. open: function (sidebar, slide) {
  458. //Slide over content
  459. if (slide) {
  460. sidebar.addClass('control-sidebar-open');
  461. } else {
  462. //Push the content by adding the open class to the body instead
  463. //of the sidebar itself
  464. $('body').addClass('control-sidebar-open');
  465. }
  466. },
  467. //Close the control sidebar
  468. close: function (sidebar, slide) {
  469. if (slide) {
  470. sidebar.removeClass('control-sidebar-open');
  471. } else {
  472. $('body').removeClass('control-sidebar-open');
  473. }
  474. },
  475. _fix: function (sidebar) {
  476. var _this = this;
  477. if ($("body").hasClass('layout-boxed')) {
  478. sidebar.css('position', 'absolute');
  479. sidebar.height($(".wrapper").height());
  480. if (_this.hasBindedResize) {
  481. return;
  482. }
  483. $(window).resize(function () {
  484. _this._fix(sidebar);
  485. });
  486. _this.hasBindedResize = true;
  487. } else {
  488. sidebar.css({
  489. 'position': 'fixed',
  490. 'height': 'auto'
  491. });
  492. }
  493. },
  494. _fixForFixed: function (sidebar) {
  495. sidebar.css({
  496. 'position': 'fixed',
  497. 'max-height': '100%',
  498. 'overflow': 'auto',
  499. });
  500. },
  501. _fixForContent: function (sidebar) {
  502. $(".content-wrapper, .right-side").css('min-height', sidebar.height());
  503. }
  504. };
  505. /* BoxWidget
  506. * =========
  507. * BoxWidget is a plugin to handle collapsing and
  508. * removing boxes from the screen.
  509. *
  510. * @type Object
  511. * @usage $.AdminLTE.boxWidget.activate()
  512. * Set all your options in the main $.AdminLTE.options object
  513. */
  514. $.AdminLTE.boxWidget = {
  515. selectors: $.AdminLTE.options.boxWidgetOptions.boxWidgetSelectors,
  516. icons: $.AdminLTE.options.boxWidgetOptions.boxWidgetIcons,
  517. animationSpeed: $.AdminLTE.options.animationSpeed,
  518. activate: function (_box) {
  519. var _this = this;
  520. if (!_box) {
  521. _box = document; // activate all boxes per default
  522. }
  523. //Listen for collapse event triggers
  524. $(_box).on('click', _this.selectors.collapse, function (e) {
  525. e.preventDefault();
  526. _this.collapse($(this));
  527. });
  528. //Listen for remove event triggers
  529. $(_box).on('click', _this.selectors.remove, function (e) {
  530. e.preventDefault();
  531. _this.remove($(this));
  532. });
  533. },
  534. collapse: function (element) {
  535. var _this = this;
  536. //Find the box parent
  537. var box = element.parents(".box").first();
  538. //Find the body and the footer
  539. var box_content = box.find("> .box-body, > .box-footer, > form >.box-body, > form > .box-footer");
  540. if (!box.hasClass("collapsed-box")) {
  541. //Convert minus into plus
  542. element.children(":first")
  543. .removeClass(_this.icons.collapse)
  544. .addClass(_this.icons.open);
  545. //Hide the content
  546. box_content.slideUp(_this.animationSpeed, function () {
  547. box.addClass("collapsed-box");
  548. });
  549. } else {
  550. //Convert plus into minus
  551. element.children(":first")
  552. .removeClass(_this.icons.open)
  553. .addClass(_this.icons.collapse);
  554. //Show the content
  555. box_content.slideDown(_this.animationSpeed, function () {
  556. box.removeClass("collapsed-box");
  557. });
  558. }
  559. },
  560. remove: function (element) {
  561. //Find the box parent
  562. var box = element.parents(".box").first();
  563. box.slideUp(this.animationSpeed);
  564. }
  565. };
  566. }
  567. /* ------------------
  568. * - Custom Plugins -
  569. * ------------------
  570. * All custom plugins are defined below.
  571. */
  572. /*
  573. * BOX REFRESH BUTTON
  574. * ------------------
  575. * This is a custom plugin to use with the component BOX. It allows you to add
  576. * a refresh button to the box. It converts the box's state to a loading state.
  577. *
  578. * @type plugin
  579. * @usage $("#box-widget").boxRefresh( options );
  580. */
  581. (function ($) {
  582. "use strict";
  583. $.fn.boxRefresh = function (options) {
  584. // Render options
  585. var settings = $.extend({
  586. //Refresh button selector
  587. trigger: ".refresh-btn",
  588. //File source to be loaded (e.g: ajax/src.php)
  589. source: "",
  590. //Callbacks
  591. onLoadStart: function (box) {
  592. return box;
  593. }, //Right after the button has been clicked
  594. onLoadDone: function (box) {
  595. return box;
  596. } //When the source has been loaded
  597. }, options);
  598. //The overlay
  599. var overlay = $('<div class="overlay"><div class="fa fa-refresh fa-spin"></div></div>');
  600. return this.each(function () {
  601. //if a source is specified
  602. if (settings.source === "") {
  603. if (window.console) {
  604. window.console.log("Please specify a source first - boxRefresh()");
  605. }
  606. return;
  607. }
  608. //the box
  609. var box = $(this);
  610. //the button
  611. var rBtn = box.find(settings.trigger).first();
  612. //On trigger click
  613. rBtn.on('click', function (e) {
  614. e.preventDefault();
  615. //Add loading overlay
  616. start(box);
  617. //Perform ajax call
  618. box.find(".box-body").load(settings.source, function () {
  619. done(box);
  620. });
  621. });
  622. });
  623. function start(box) {
  624. //Add overlay and loading img
  625. box.append(overlay);
  626. settings.onLoadStart.call(box);
  627. }
  628. function done(box) {
  629. //Remove overlay and loading img
  630. box.find(overlay).remove();
  631. settings.onLoadDone.call(box);
  632. }
  633. };
  634. })(jQuery);
  635. /*
  636. * EXPLICIT BOX CONTROLS
  637. * -----------------------
  638. * This is a custom plugin to use with the component BOX. It allows you to activate
  639. * a box inserted in the DOM after the app.js was loaded, toggle and remove box.
  640. *
  641. * @type plugin
  642. * @usage $("#box-widget").activateBox();
  643. * @usage $("#box-widget").toggleBox();
  644. * @usage $("#box-widget").removeBox();
  645. */
  646. (function ($) {
  647. 'use strict';
  648. $.fn.activateBox = function () {
  649. $.AdminLTE.boxWidget.activate(this);
  650. };
  651. $.fn.toggleBox = function () {
  652. var button = $($.AdminLTE.boxWidget.selectors.collapse, this);
  653. $.AdminLTE.boxWidget.collapse(button);
  654. };
  655. $.fn.removeBox = function () {
  656. var button = $($.AdminLTE.boxWidget.selectors.remove, this);
  657. $.AdminLTE.boxWidget.remove(button);
  658. };
  659. })(jQuery);
  660. /*
  661. * TODO LIST CUSTOM PLUGIN
  662. * -----------------------
  663. * This plugin depends on iCheck plugin for checkbox and radio inputs
  664. *
  665. * @type plugin
  666. * @usage $("#todo-widget").todolist( options );
  667. */
  668. (function ($) {
  669. 'use strict';
  670. $.fn.todolist = function (options) {
  671. // Render options
  672. var settings = $.extend({
  673. //When the user checks the input
  674. onCheck: function (ele) {
  675. return ele;
  676. },
  677. //When the user unchecks the input
  678. onUncheck: function (ele) {
  679. return ele;
  680. }
  681. }, options);
  682. return this.each(function () {
  683. if (typeof $.fn.iCheck != 'undefined') {
  684. $('input', this).on('ifChecked', function () {
  685. var ele = $(this).parents("li").first();
  686. ele.toggleClass("done");
  687. settings.onCheck.call(ele);
  688. });
  689. $('input', this).on('ifUnchecked', function () {
  690. var ele = $(this).parents("li").first();
  691. ele.toggleClass("done");
  692. settings.onUncheck.call(ele);
  693. });
  694. } else {
  695. $('input', this).on('change', function () {
  696. var ele = $(this).parents("li").first();
  697. ele.toggleClass("done");
  698. if ($('input', ele).is(":checked")) {
  699. settings.onCheck.call(ele);
  700. } else {
  701. settings.onUncheck.call(ele);
  702. }
  703. });
  704. }
  705. });
  706. };
  707. //set/get form element value
  708. $.fn.field = function (name, value)
  709. {
  710. if (typeof name !== "string")
  711. return false;
  712. var element = $(this).find("[name='" + name + "']");
  713. if (typeof value === "undefined" && element.length >= 1)
  714. {
  715. switch (element.attr("type"))
  716. {
  717. case "checkbox":
  718. var result = new Array();
  719. element.each(function (i, val) {
  720. if ($(this).is(":checked")) {
  721. result.push($(this).val());
  722. }
  723. });
  724. return result;
  725. break;
  726. case "radio":
  727. var result;
  728. element.each(function (i, val) {
  729. if ($(this).is(":checked")) {
  730. result = $(this).val();
  731. }
  732. });
  733. return result;
  734. break;
  735. default:
  736. return element.val();
  737. break;
  738. }
  739. } else
  740. {
  741. switch (element.attr("type"))
  742. {
  743. case "checkbox":
  744. case "radio":
  745. value = $.isArray(value) ? value : [value];
  746. element.each(function (i) {
  747. $(this).prop({
  748. checked: $.inArray($(this).val(), value) > -1
  749. });
  750. });
  751. break;
  752. case undefined:
  753. default:
  754. element.val(value);
  755. break;
  756. }
  757. return element;
  758. }
  759. };
  760. }(jQuery));