adminlte.js 29 KB

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