adminlte.js 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130
  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 <https://www.almsaeedstudio.com>
  9. * @Email <abdullah@almsaeedstudio.com>
  10. * @version 2.4.8
  11. * @repository git://github.com/almasaeed2010/AdminLTE.git
  12. * @license MIT <http://opensource.org/licenses/MIT>
  13. */
  14. // Make sure jQuery has been loaded
  15. if (typeof jQuery === 'undefined') {
  16. throw new Error('AdminLTE requires jQuery')
  17. }
  18. /* BoxRefresh()
  19. * =========
  20. * Adds AJAX content control to a box.
  21. *
  22. * @Usage: $('#my-box').boxRefresh(options)
  23. * or add [data-widget="box-refresh"] to the box element
  24. * Pass any option as data-option="value"
  25. */
  26. +function ($) {
  27. 'use strict';
  28. var DataKey = 'lte.boxrefresh';
  29. var Default = {
  30. source : '',
  31. params : {},
  32. trigger : '.refresh-btn',
  33. content : '.box-body',
  34. loadInContent : true,
  35. responseType : '',
  36. overlayTemplate: '<div class="overlay"><div class="fa fa-refresh fa-spin"></div></div>',
  37. onLoadStart : function () {
  38. },
  39. onLoadDone : function (response) {
  40. return response;
  41. }
  42. };
  43. var Selector = {
  44. data: '[data-widget="box-refresh"]'
  45. };
  46. // BoxRefresh Class Definition
  47. // =========================
  48. var BoxRefresh = function (element, options) {
  49. this.element = element;
  50. this.options = options;
  51. this.$overlay = $(options.overlayTemplate);
  52. if (options.source === '') {
  53. throw new Error('Source url was not defined. Please specify a url in your BoxRefresh source option.');
  54. }
  55. this._setUpListeners();
  56. this.load();
  57. };
  58. BoxRefresh.prototype.load = function () {
  59. this._addOverlay();
  60. this.options.onLoadStart.call($(this));
  61. $.get(this.options.source, this.options.params, function (response) {
  62. if (this.options.loadInContent) {
  63. $(this.element).find(this.options.content).html(response);
  64. }
  65. this.options.onLoadDone.call($(this), response);
  66. this._removeOverlay();
  67. }.bind(this), this.options.responseType !== '' && this.options.responseType);
  68. };
  69. // Private
  70. BoxRefresh.prototype._setUpListeners = function () {
  71. $(this.element).on('click', this.options.trigger, function (event) {
  72. if (event) event.preventDefault();
  73. this.load();
  74. }.bind(this));
  75. };
  76. BoxRefresh.prototype._addOverlay = function () {
  77. $(this.element).append(this.$overlay);
  78. };
  79. BoxRefresh.prototype._removeOverlay = function () {
  80. $(this.$overlay).remove();
  81. };
  82. // Plugin Definition
  83. // =================
  84. function Plugin(option) {
  85. return this.each(function () {
  86. var $this = $(this);
  87. var data = $this.data(DataKey);
  88. if (!data) {
  89. var options = $.extend({}, Default, $this.data(), typeof option == 'object' && option);
  90. $this.data(DataKey, (data = new BoxRefresh($this, options)));
  91. }
  92. if (typeof data == 'string') {
  93. if (typeof data[option] == 'undefined') {
  94. throw new Error('No method named ' + option);
  95. }
  96. data[option]();
  97. }
  98. });
  99. }
  100. var old = $.fn.boxRefresh;
  101. $.fn.boxRefresh = Plugin;
  102. $.fn.boxRefresh.Constructor = BoxRefresh;
  103. // No Conflict Mode
  104. // ================
  105. $.fn.boxRefresh.noConflict = function () {
  106. $.fn.boxRefresh = old;
  107. return this;
  108. };
  109. // BoxRefresh Data API
  110. // =================
  111. $(window).on('load', function () {
  112. $(Selector.data).each(function () {
  113. Plugin.call($(this));
  114. });
  115. });
  116. }(jQuery);
  117. /* BoxWidget()
  118. * ======
  119. * Adds box widget functions to boxes.
  120. *
  121. * @Usage: $('.my-box').boxWidget(options)
  122. * This plugin auto activates on any element using the `.box` class
  123. * Pass any option as data-option="value"
  124. */
  125. +function ($) {
  126. 'use strict';
  127. var DataKey = 'lte.boxwidget';
  128. var Default = {
  129. animationSpeed : 500,
  130. collapseTrigger: '[data-widget="collapse"]',
  131. removeTrigger : '[data-widget="remove"]',
  132. collapseIcon : 'fa-minus',
  133. expandIcon : 'fa-plus',
  134. removeIcon : 'fa-times'
  135. };
  136. var Selector = {
  137. data : '.box',
  138. collapsed: '.collapsed-box',
  139. header : '.box-header',
  140. body : '.box-body',
  141. footer : '.box-footer',
  142. tools : '.box-tools'
  143. };
  144. var ClassName = {
  145. collapsed: 'collapsed-box'
  146. };
  147. var Event = {
  148. collapsed: 'collapsed.boxwidget',
  149. expanded : 'expanded.boxwidget',
  150. removed : 'removed.boxwidget'
  151. };
  152. // BoxWidget Class Definition
  153. // =====================
  154. var BoxWidget = function (element, options) {
  155. this.element = element;
  156. this.options = options;
  157. this._setUpListeners();
  158. };
  159. BoxWidget.prototype.toggle = function () {
  160. var isOpen = !$(this.element).is(Selector.collapsed);
  161. if (isOpen) {
  162. this.collapse();
  163. } else {
  164. this.expand();
  165. }
  166. };
  167. BoxWidget.prototype.expand = function () {
  168. var expandedEvent = $.Event(Event.expanded);
  169. var collapseIcon = this.options.collapseIcon;
  170. var expandIcon = this.options.expandIcon;
  171. $(this.element).removeClass(ClassName.collapsed);
  172. $(this.element)
  173. .children(Selector.header + ', ' + Selector.body + ', ' + Selector.footer)
  174. .children(Selector.tools)
  175. .find('.' + expandIcon)
  176. .removeClass(expandIcon)
  177. .addClass(collapseIcon);
  178. $(this.element).children(Selector.body + ', ' + Selector.footer)
  179. .slideDown(this.options.animationSpeed, function () {
  180. $(this.element).trigger(expandedEvent);
  181. }.bind(this));
  182. };
  183. BoxWidget.prototype.collapse = function () {
  184. var collapsedEvent = $.Event(Event.collapsed);
  185. var collapseIcon = this.options.collapseIcon;
  186. var expandIcon = this.options.expandIcon;
  187. $(this.element)
  188. .children(Selector.header + ', ' + Selector.body + ', ' + Selector.footer)
  189. .children(Selector.tools)
  190. .find('.' + collapseIcon)
  191. .removeClass(collapseIcon)
  192. .addClass(expandIcon);
  193. $(this.element).children(Selector.body + ', ' + Selector.footer)
  194. .slideUp(this.options.animationSpeed, function () {
  195. $(this.element).addClass(ClassName.collapsed);
  196. $(this.element).trigger(collapsedEvent);
  197. }.bind(this));
  198. };
  199. BoxWidget.prototype.remove = function () {
  200. var removedEvent = $.Event(Event.removed);
  201. $(this.element).slideUp(this.options.animationSpeed, function () {
  202. $(this.element).trigger(removedEvent);
  203. $(this.element).remove();
  204. }.bind(this));
  205. };
  206. // Private
  207. BoxWidget.prototype._setUpListeners = function () {
  208. var that = this;
  209. $(this.element).on('click', this.options.collapseTrigger, function (event) {
  210. if (event) event.preventDefault();
  211. that.toggle($(this));
  212. return false;
  213. });
  214. $(this.element).on('click', this.options.removeTrigger, function (event) {
  215. if (event) event.preventDefault();
  216. that.remove($(this));
  217. return false;
  218. });
  219. };
  220. // Plugin Definition
  221. // =================
  222. function Plugin(option) {
  223. return this.each(function () {
  224. var $this = $(this);
  225. var data = $this.data(DataKey);
  226. if (!data) {
  227. var options = $.extend({}, Default, $this.data(), typeof option == 'object' && option);
  228. $this.data(DataKey, (data = new BoxWidget($this, options)));
  229. }
  230. if (typeof option == 'string') {
  231. if (typeof data[option] == 'undefined') {
  232. throw new Error('No method named ' + option);
  233. }
  234. data[option]();
  235. }
  236. });
  237. }
  238. var old = $.fn.boxWidget;
  239. $.fn.boxWidget = Plugin;
  240. $.fn.boxWidget.Constructor = BoxWidget;
  241. // No Conflict Mode
  242. // ================
  243. $.fn.boxWidget.noConflict = function () {
  244. $.fn.boxWidget = old;
  245. return this;
  246. };
  247. // BoxWidget Data API
  248. // ==================
  249. $(window).on('load', function () {
  250. $(Selector.data).each(function () {
  251. Plugin.call($(this));
  252. });
  253. });
  254. }(jQuery);
  255. /* ControlSidebar()
  256. * ===============
  257. * Toggles the state of the control sidebar
  258. *
  259. * @Usage: $('#control-sidebar-trigger').controlSidebar(options)
  260. * or add [data-toggle="control-sidebar"] to the trigger
  261. * Pass any option as data-option="value"
  262. */
  263. +function ($) {
  264. 'use strict';
  265. var DataKey = 'lte.controlsidebar';
  266. var Default = {
  267. slide: true
  268. };
  269. var Selector = {
  270. sidebar: '.control-sidebar',
  271. data : '[data-toggle="control-sidebar"]',
  272. open : '.control-sidebar-open',
  273. bg : '.control-sidebar-bg',
  274. wrapper: '.wrapper',
  275. content: '.content-wrapper',
  276. boxed : '.layout-boxed'
  277. };
  278. var ClassName = {
  279. open : 'control-sidebar-open',
  280. fixed: 'fixed'
  281. };
  282. var Event = {
  283. collapsed: 'collapsed.controlsidebar',
  284. expanded : 'expanded.controlsidebar'
  285. };
  286. // ControlSidebar Class Definition
  287. // ===============================
  288. var ControlSidebar = function (element, options) {
  289. this.element = element;
  290. this.options = options;
  291. this.hasBindedResize = false;
  292. this.init();
  293. };
  294. ControlSidebar.prototype.init = function () {
  295. // Add click listener if the element hasn't been
  296. // initialized using the data API
  297. if (!$(this.element).is(Selector.data)) {
  298. $(this).on('click', this.toggle);
  299. }
  300. this.fix();
  301. $(window).resize(function () {
  302. this.fix();
  303. }.bind(this));
  304. };
  305. ControlSidebar.prototype.toggle = function (event) {
  306. if (event) event.preventDefault();
  307. this.fix();
  308. if (!$(Selector.sidebar).is(Selector.open) && !$('body').is(Selector.open)) {
  309. this.expand();
  310. } else {
  311. this.collapse();
  312. }
  313. };
  314. ControlSidebar.prototype.expand = function () {
  315. if (!this.options.slide) {
  316. $('body').addClass(ClassName.open);
  317. } else {
  318. $(Selector.sidebar).addClass(ClassName.open);
  319. }
  320. $(this.element).trigger($.Event(Event.expanded));
  321. };
  322. ControlSidebar.prototype.collapse = function () {
  323. $('body, ' + Selector.sidebar).removeClass(ClassName.open);
  324. $(this.element).trigger($.Event(Event.collapsed));
  325. };
  326. ControlSidebar.prototype.fix = function () {
  327. if ($('body').is(Selector.boxed)) {
  328. this._fixForBoxed($(Selector.bg));
  329. }
  330. };
  331. // Private
  332. ControlSidebar.prototype._fixForBoxed = function (bg) {
  333. bg.css({
  334. position: 'absolute',
  335. height : $(Selector.wrapper).height()
  336. });
  337. };
  338. // Plugin Definition
  339. // =================
  340. function Plugin(option) {
  341. return this.each(function () {
  342. var $this = $(this);
  343. var data = $this.data(DataKey);
  344. if (!data) {
  345. var options = $.extend({}, Default, $this.data(), typeof option == 'object' && option);
  346. $this.data(DataKey, (data = new ControlSidebar($this, options)));
  347. }
  348. if (typeof option == 'string') data.toggle();
  349. });
  350. }
  351. var old = $.fn.controlSidebar;
  352. $.fn.controlSidebar = Plugin;
  353. $.fn.controlSidebar.Constructor = ControlSidebar;
  354. // No Conflict Mode
  355. // ================
  356. $.fn.controlSidebar.noConflict = function () {
  357. $.fn.controlSidebar = old;
  358. return this;
  359. };
  360. // ControlSidebar Data API
  361. // =======================
  362. $(document).on('click', Selector.data, function (event) {
  363. if (event) event.preventDefault();
  364. Plugin.call($(this), 'toggle');
  365. });
  366. }(jQuery);
  367. /* DirectChat()
  368. * ===============
  369. * Toggles the state of the control sidebar
  370. *
  371. * @Usage: $('#my-chat-box').directChat()
  372. * or add [data-widget="direct-chat"] to the trigger
  373. */
  374. +function ($) {
  375. 'use strict';
  376. var DataKey = 'lte.directchat';
  377. var Selector = {
  378. data: '[data-widget="chat-pane-toggle"]',
  379. box : '.direct-chat'
  380. };
  381. var ClassName = {
  382. open: 'direct-chat-contacts-open'
  383. };
  384. // DirectChat Class Definition
  385. // ===========================
  386. var DirectChat = function (element) {
  387. this.element = element;
  388. };
  389. DirectChat.prototype.toggle = function ($trigger) {
  390. $trigger.parents(Selector.box).first().toggleClass(ClassName.open);
  391. };
  392. // Plugin Definition
  393. // =================
  394. function Plugin(option) {
  395. return this.each(function () {
  396. var $this = $(this);
  397. var data = $this.data(DataKey);
  398. if (!data) {
  399. $this.data(DataKey, (data = new DirectChat($this)));
  400. }
  401. if (typeof option == 'string') data.toggle($this);
  402. });
  403. }
  404. var old = $.fn.directChat;
  405. $.fn.directChat = Plugin;
  406. $.fn.directChat.Constructor = DirectChat;
  407. // No Conflict Mode
  408. // ================
  409. $.fn.directChat.noConflict = function () {
  410. $.fn.directChat = old;
  411. return this;
  412. };
  413. // DirectChat Data API
  414. // ===================
  415. $(document).on('click', Selector.data, function (event) {
  416. if (event) event.preventDefault();
  417. Plugin.call($(this), 'toggle');
  418. });
  419. }(jQuery);
  420. /* Layout()
  421. * ========
  422. * Implements AdminLTE layout.
  423. * Fixes the layout height in case min-height fails.
  424. *
  425. * @usage activated automatically upon window load.
  426. * Configure any options by passing data-option="value"
  427. * to the body tag.
  428. */
  429. +function ($) {
  430. 'use strict';
  431. var DataKey = 'lte.layout';
  432. var Default = {
  433. slimscroll : true,
  434. resetHeight: true
  435. };
  436. var Selector = {
  437. wrapper : '.wrapper',
  438. contentWrapper: '.content-wrapper',
  439. layoutBoxed : '.layout-boxed',
  440. mainFooter : '.main-footer',
  441. mainHeader : '.main-header',
  442. sidebar : '.sidebar',
  443. controlSidebar: '.control-sidebar',
  444. fixed : '.fixed',
  445. sidebarMenu : '.sidebar-menu',
  446. logo : '.main-header .logo'
  447. };
  448. var ClassName = {
  449. fixed : 'fixed',
  450. holdTransition: 'hold-transition'
  451. };
  452. var Layout = function (options) {
  453. this.options = options;
  454. this.bindedResize = false;
  455. this.activate();
  456. };
  457. Layout.prototype.activate = function () {
  458. this.fix();
  459. this.fixSidebar();
  460. $('body').removeClass(ClassName.holdTransition);
  461. if (this.options.resetHeight) {
  462. $('body, html, ' + Selector.wrapper).css({
  463. 'height' : 'auto',
  464. 'min-height': '100%'
  465. });
  466. }
  467. if (!this.bindedResize) {
  468. $(window).resize(function () {
  469. this.fix();
  470. this.fixSidebar();
  471. $(Selector.logo + ', ' + Selector.sidebar).one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function () {
  472. this.fix();
  473. this.fixSidebar();
  474. }.bind(this));
  475. }.bind(this));
  476. this.bindedResize = true;
  477. }
  478. $(Selector.sidebarMenu).on('expanded.tree', function () {
  479. this.fix();
  480. this.fixSidebar();
  481. }.bind(this));
  482. $(Selector.sidebarMenu).on('collapsed.tree', function () {
  483. this.fix();
  484. this.fixSidebar();
  485. }.bind(this));
  486. };
  487. Layout.prototype.fix = function () {
  488. // Remove overflow from .wrapper if layout-boxed exists
  489. $(Selector.layoutBoxed + ' > ' + Selector.wrapper).css('overflow', 'hidden');
  490. // Get window height and the wrapper height
  491. var footerHeight = $(Selector.mainFooter).outerHeight() || 0;
  492. var headerHeight = $(Selector.mainHeader).outerHeight() || 0;
  493. var neg = headerHeight + footerHeight;
  494. var windowHeight = $(window).height();
  495. var sidebarHeight = $(Selector.sidebar).height() || 0;
  496. // Set the min-height of the content and sidebar based on
  497. // the height of the document.
  498. if ($('body').hasClass(ClassName.fixed)) {
  499. $(Selector.contentWrapper).css('min-height', windowHeight - footerHeight);
  500. } else {
  501. var postSetHeight;
  502. if (windowHeight >= sidebarHeight + headerHeight) {
  503. $(Selector.contentWrapper).css('min-height', windowHeight - neg);
  504. postSetHeight = windowHeight - neg;
  505. } else {
  506. $(Selector.contentWrapper).css('min-height', sidebarHeight);
  507. postSetHeight = sidebarHeight;
  508. }
  509. // Fix for the control sidebar height
  510. var $controlSidebar = $(Selector.controlSidebar);
  511. if (typeof $controlSidebar !== 'undefined') {
  512. if ($controlSidebar.height() > postSetHeight)
  513. $(Selector.contentWrapper).css('min-height', $controlSidebar.height());
  514. }
  515. }
  516. };
  517. Layout.prototype.fixSidebar = function () {
  518. // Make sure the body tag has the .fixed class
  519. if (!$('body').hasClass(ClassName.fixed)) {
  520. if (typeof $.fn.slimScroll !== 'undefined') {
  521. $(Selector.sidebar).slimScroll({ destroy: true }).height('auto');
  522. }
  523. return;
  524. }
  525. // Enable slimscroll for fixed layout
  526. if (this.options.slimscroll) {
  527. if (typeof $.fn.slimScroll !== 'undefined') {
  528. // Destroy if it exists
  529. // $(Selector.sidebar).slimScroll({ destroy: true }).height('auto')
  530. // Add slimscroll
  531. $(Selector.sidebar).slimScroll({
  532. height: ($(window).height() - $(Selector.mainHeader).height()) + 'px'
  533. });
  534. }
  535. }
  536. };
  537. // Plugin Definition
  538. // =================
  539. function Plugin(option) {
  540. return this.each(function () {
  541. var $this = $(this);
  542. var data = $this.data(DataKey);
  543. if (!data) {
  544. var options = $.extend({}, Default, $this.data(), typeof option === 'object' && option);
  545. $this.data(DataKey, (data = new Layout(options)));
  546. }
  547. if (typeof option === 'string') {
  548. if (typeof data[option] === 'undefined') {
  549. throw new Error('No method named ' + option);
  550. }
  551. data[option]();
  552. }
  553. });
  554. }
  555. var old = $.fn.layout;
  556. $.fn.layout = Plugin;
  557. $.fn.layout.Constuctor = Layout;
  558. // No conflict mode
  559. // ================
  560. $.fn.layout.noConflict = function () {
  561. $.fn.layout = old;
  562. return this;
  563. };
  564. // Layout DATA-API
  565. // ===============
  566. $(window).on('load', function () {
  567. Plugin.call($('body'));
  568. });
  569. }(jQuery);
  570. /* PushMenu()
  571. * ==========
  572. * Adds the push menu functionality to the sidebar.
  573. *
  574. * @usage: $('.btn').pushMenu(options)
  575. * or add [data-toggle="push-menu"] to any button
  576. * Pass any option as data-option="value"
  577. */
  578. +function ($) {
  579. 'use strict';
  580. var DataKey = 'lte.pushmenu';
  581. var Default = {
  582. collapseScreenSize : 767,
  583. expandOnHover : false,
  584. expandTransitionDelay: 200
  585. };
  586. var Selector = {
  587. collapsed : '.sidebar-collapse',
  588. open : '.sidebar-open',
  589. mainSidebar : '.main-sidebar',
  590. contentWrapper: '.content-wrapper',
  591. searchInput : '.sidebar-form .form-control',
  592. button : '[data-toggle="push-menu"]',
  593. mini : '.sidebar-mini',
  594. expanded : '.sidebar-expanded-on-hover',
  595. layoutFixed : '.fixed'
  596. };
  597. var ClassName = {
  598. collapsed : 'sidebar-collapse',
  599. open : 'sidebar-open',
  600. mini : 'sidebar-mini',
  601. expanded : 'sidebar-expanded-on-hover',
  602. expandFeature: 'sidebar-mini-expand-feature',
  603. layoutFixed : 'fixed'
  604. };
  605. var Event = {
  606. expanded : 'expanded.pushMenu',
  607. collapsed: 'collapsed.pushMenu'
  608. };
  609. // PushMenu Class Definition
  610. // =========================
  611. var PushMenu = function (options) {
  612. this.options = options;
  613. this.init();
  614. };
  615. PushMenu.prototype.init = function () {
  616. if (this.options.expandOnHover
  617. || ($('body').is(Selector.mini + Selector.layoutFixed))) {
  618. this.expandOnHover();
  619. $('body').addClass(ClassName.expandFeature);
  620. }
  621. $(Selector.contentWrapper).click(function () {
  622. // Enable hide menu when clicking on the content-wrapper on small screens
  623. if ($(window).width() <= this.options.collapseScreenSize && $('body').hasClass(ClassName.open)) {
  624. this.close();
  625. }
  626. }.bind(this));
  627. // __Fix for android devices
  628. $(Selector.searchInput).click(function (e) {
  629. e.stopPropagation();
  630. });
  631. };
  632. PushMenu.prototype.toggle = function () {
  633. var windowWidth = $(window).width();
  634. var isOpen = !$('body').hasClass(ClassName.collapsed);
  635. if (windowWidth <= this.options.collapseScreenSize) {
  636. isOpen = $('body').hasClass(ClassName.open);
  637. }
  638. if (!isOpen) {
  639. this.open();
  640. } else {
  641. this.close();
  642. }
  643. };
  644. PushMenu.prototype.open = function () {
  645. var windowWidth = $(window).width();
  646. if (windowWidth > this.options.collapseScreenSize) {
  647. $('body').removeClass(ClassName.collapsed)
  648. .trigger($.Event(Event.expanded));
  649. }
  650. else {
  651. $('body').addClass(ClassName.open)
  652. .trigger($.Event(Event.expanded));
  653. }
  654. };
  655. PushMenu.prototype.close = function () {
  656. var windowWidth = $(window).width();
  657. if (windowWidth > this.options.collapseScreenSize) {
  658. $('body').addClass(ClassName.collapsed)
  659. .trigger($.Event(Event.collapsed));
  660. } else {
  661. $('body').removeClass(ClassName.open + ' ' + ClassName.collapsed)
  662. .trigger($.Event(Event.collapsed));
  663. }
  664. };
  665. PushMenu.prototype.expandOnHover = function () {
  666. $(Selector.mainSidebar).hover(function () {
  667. if ($('body').is(Selector.mini + Selector.collapsed)
  668. && $(window).width() > this.options.collapseScreenSize) {
  669. this.expand();
  670. }
  671. }.bind(this), function () {
  672. if ($('body').is(Selector.expanded)) {
  673. this.collapse();
  674. }
  675. }.bind(this));
  676. };
  677. PushMenu.prototype.expand = function () {
  678. setTimeout(function () {
  679. $('body').removeClass(ClassName.collapsed)
  680. .addClass(ClassName.expanded);
  681. }, this.options.expandTransitionDelay);
  682. };
  683. PushMenu.prototype.collapse = function () {
  684. setTimeout(function () {
  685. $('body').removeClass(ClassName.expanded)
  686. .addClass(ClassName.collapsed);
  687. }, this.options.expandTransitionDelay);
  688. };
  689. // PushMenu Plugin Definition
  690. // ==========================
  691. function Plugin(option) {
  692. return this.each(function () {
  693. var $this = $(this);
  694. var data = $this.data(DataKey);
  695. if (!data) {
  696. var options = $.extend({}, Default, $this.data(), typeof option == 'object' && option);
  697. $this.data(DataKey, (data = new PushMenu(options)));
  698. }
  699. if (option === 'toggle') data.toggle();
  700. });
  701. }
  702. var old = $.fn.pushMenu;
  703. $.fn.pushMenu = Plugin;
  704. $.fn.pushMenu.Constructor = PushMenu;
  705. // No Conflict Mode
  706. // ================
  707. $.fn.pushMenu.noConflict = function () {
  708. $.fn.pushMenu = old;
  709. return this;
  710. };
  711. // Data API
  712. // ========
  713. $(document).on('click', Selector.button, function (e) {
  714. e.preventDefault();
  715. Plugin.call($(this), 'toggle');
  716. });
  717. $(window).on('load', function () {
  718. Plugin.call($(Selector.button));
  719. });
  720. }(jQuery);
  721. /* TodoList()
  722. * =========
  723. * Converts a list into a todoList.
  724. *
  725. * @Usage: $('.my-list').todoList(options)
  726. * or add [data-widget="todo-list"] to the ul element
  727. * Pass any option as data-option="value"
  728. */
  729. +function ($) {
  730. 'use strict';
  731. var DataKey = 'lte.todolist';
  732. var Default = {
  733. onCheck : function (item) {
  734. return item;
  735. },
  736. onUnCheck: function (item) {
  737. return item;
  738. }
  739. };
  740. var Selector = {
  741. data: '[data-widget="todo-list"]'
  742. };
  743. var ClassName = {
  744. done: 'done'
  745. };
  746. // TodoList Class Definition
  747. // =========================
  748. var TodoList = function (element, options) {
  749. this.element = element;
  750. this.options = options;
  751. this._setUpListeners();
  752. };
  753. TodoList.prototype.toggle = function (item) {
  754. item.parents(Selector.li).first().toggleClass(ClassName.done);
  755. if (!item.prop('checked')) {
  756. this.unCheck(item);
  757. return;
  758. }
  759. this.check(item);
  760. };
  761. TodoList.prototype.check = function (item) {
  762. this.options.onCheck.call(item);
  763. };
  764. TodoList.prototype.unCheck = function (item) {
  765. this.options.onUnCheck.call(item);
  766. };
  767. // Private
  768. TodoList.prototype._setUpListeners = function () {
  769. var that = this;
  770. $(this.element).on('change ifChanged', 'input:checkbox', function () {
  771. that.toggle($(this));
  772. });
  773. };
  774. // Plugin Definition
  775. // =================
  776. function Plugin(option) {
  777. return this.each(function () {
  778. var $this = $(this);
  779. var data = $this.data(DataKey);
  780. if (!data) {
  781. var options = $.extend({}, Default, $this.data(), typeof option == 'object' && option);
  782. $this.data(DataKey, (data = new TodoList($this, options)));
  783. }
  784. if (typeof data == 'string') {
  785. if (typeof data[option] == 'undefined') {
  786. throw new Error('No method named ' + option);
  787. }
  788. data[option]();
  789. }
  790. });
  791. }
  792. var old = $.fn.todoList;
  793. $.fn.todoList = Plugin;
  794. $.fn.todoList.Constructor = TodoList;
  795. // No Conflict Mode
  796. // ================
  797. $.fn.todoList.noConflict = function () {
  798. $.fn.todoList = old;
  799. return this;
  800. };
  801. // TodoList Data API
  802. // =================
  803. $(window).on('load', function () {
  804. $(Selector.data).each(function () {
  805. Plugin.call($(this));
  806. });
  807. });
  808. }(jQuery);
  809. /* Tree()
  810. * ======
  811. * Converts a nested list into a multilevel
  812. * tree view menu.
  813. *
  814. * @Usage: $('.my-menu').tree(options)
  815. * or add [data-widget="tree"] to the ul element
  816. * Pass any option as data-option="value"
  817. */
  818. +function ($) {
  819. 'use strict';
  820. var DataKey = 'lte.tree';
  821. var Default = {
  822. animationSpeed: 500,
  823. accordion : true,
  824. followLink : false,
  825. trigger : '.treeview a'
  826. };
  827. var Selector = {
  828. tree : '.tree',
  829. treeview : '.treeview',
  830. treeviewMenu: '.treeview-menu',
  831. open : '.menu-open, .active',
  832. li : 'li',
  833. data : '[data-widget="tree"]',
  834. active : '.active'
  835. };
  836. var ClassName = {
  837. open: 'menu-open',
  838. tree: 'tree'
  839. };
  840. var Event = {
  841. collapsed: 'collapsed.tree',
  842. expanded : 'expanded.tree'
  843. };
  844. // Tree Class Definition
  845. // =====================
  846. var Tree = function (element, options) {
  847. this.element = element;
  848. this.options = options;
  849. $(this.element).addClass(ClassName.tree);
  850. $(Selector.treeview + Selector.active, this.element).addClass(ClassName.open);
  851. this._setUpListeners();
  852. };
  853. Tree.prototype.toggle = function (link, event) {
  854. var treeviewMenu = link.next(Selector.treeviewMenu);
  855. var parentLi = link.parent();
  856. var isOpen = parentLi.hasClass(ClassName.open);
  857. if (!parentLi.is(Selector.treeview)) {
  858. return;
  859. }
  860. if (!this.options.followLink || link.attr('href') === '#') {
  861. event.preventDefault();
  862. }
  863. if (isOpen) {
  864. this.collapse(treeviewMenu, parentLi);
  865. } else {
  866. this.expand(treeviewMenu, parentLi);
  867. }
  868. };
  869. Tree.prototype.expand = function (tree, parent) {
  870. var expandedEvent = $.Event(Event.expanded);
  871. if (this.options.accordion) {
  872. var openMenuLi = parent.siblings(Selector.open);
  873. var openTree = openMenuLi.children(Selector.treeviewMenu);
  874. this.collapse(openTree, openMenuLi);
  875. }
  876. parent.addClass(ClassName.open);
  877. tree.slideDown(this.options.animationSpeed, function () {
  878. $(this.element).trigger(expandedEvent);
  879. }.bind(this));
  880. };
  881. Tree.prototype.collapse = function (tree, parentLi) {
  882. var collapsedEvent = $.Event(Event.collapsed);
  883. //tree.find(Selector.open).removeClass(ClassName.open);
  884. parentLi.removeClass(ClassName.open);
  885. tree.slideUp(this.options.animationSpeed, function () {
  886. //tree.find(Selector.open + ' > ' + Selector.treeview).slideUp();
  887. $(this.element).trigger(collapsedEvent);
  888. }.bind(this));
  889. };
  890. // Private
  891. Tree.prototype._setUpListeners = function () {
  892. var that = this;
  893. $(this.element).on('click', this.options.trigger, function (event) {
  894. that.toggle($(this), event);
  895. });
  896. };
  897. // Plugin Definition
  898. // =================
  899. function Plugin(option) {
  900. return this.each(function () {
  901. var $this = $(this);
  902. var data = $this.data(DataKey);
  903. if (!data) {
  904. var options = $.extend({}, Default, $this.data(), typeof option == 'object' && option);
  905. $this.data(DataKey, new Tree($this, options));
  906. }
  907. });
  908. }
  909. var old = $.fn.tree;
  910. $.fn.tree = Plugin;
  911. $.fn.tree.Constructor = Tree;
  912. // No Conflict Mode
  913. // ================
  914. $.fn.tree.noConflict = function () {
  915. $.fn.tree = old;
  916. return this;
  917. };
  918. // Tree Data API
  919. // =============
  920. $(window).on('load', function () {
  921. $(Selector.data).each(function () {
  922. Plugin.call($(this));
  923. });
  924. });
  925. }(jQuery);