admin.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. if (typeof jQuery === "undefined") {
  2. throw new Error("jQuery plugins need to be before this file");
  3. }
  4. $.AdminBSB = {};
  5. $.AdminBSB.options = {
  6. colors: {
  7. red: '#F44336',
  8. pink: '#E91E63',
  9. purple: '#9C27B0',
  10. deepPurple: '#673AB7',
  11. indigo: '#3F51B5',
  12. blue: '#2196F3',
  13. lightBlue: '#03A9F4',
  14. cyan: '#00BCD4',
  15. teal: '#009688',
  16. green: '#4CAF50',
  17. lightGreen: '#8BC34A',
  18. lime: '#CDDC39',
  19. yellow: '#ffe821',
  20. amber: '#FFC107',
  21. orange: '#FF9800',
  22. deepOrange: '#FF5722',
  23. brown: '#795548',
  24. grey: '#9E9E9E',
  25. blueGrey: '#607D8B',
  26. black: '#000000',
  27. white: '#ffffff'
  28. },
  29. leftSideBar: {
  30. scrollColor: 'rgba(0,0,0,0.5)',
  31. scrollWidth: '4px',
  32. scrollAlwaysVisible: false,
  33. scrollBorderRadius: '0',
  34. scrollRailBorderRadius: '0',
  35. scrollActiveItemWhenPageLoad: true,
  36. breakpointWidth: 1170
  37. },
  38. dropdownMenu: {
  39. effectIn: 'fadeIn',
  40. effectOut: 'fadeOut'
  41. }
  42. }
  43. /* Left Sidebar - Function =================================================================================================
  44. * You can manage the left sidebar menu options
  45. *
  46. */
  47. $.AdminBSB.leftSideBar = {
  48. activate: function () {
  49. var _this = this;
  50. var $body = $('body');
  51. var $overlay = $('.overlay');
  52. //Close sidebar
  53. $(window).click(function (e) {
  54. var $target = $(e.target);
  55. if (e.target.nodeName.toLowerCase() === 'i') { $target = $(e.target).parent(); }
  56. if (!$target.hasClass('bars') && _this.isOpen() && $target.parents('#leftsidebar').length === 0) {
  57. if (!$target.hasClass('js-right-sidebar')) $overlay.fadeOut();
  58. $body.removeClass('overlay-open');
  59. }
  60. });
  61. $.each($('.menu-toggle.toggled'), function (i, val) {
  62. $(val).next().slideToggle(0);
  63. });
  64. //When page load
  65. $.each($('.menu .list li.active'), function (i, val) {
  66. var $activeAnchors = $(val).find('a:eq(0)');
  67. $activeAnchors.addClass('toggled');
  68. $activeAnchors.next().show();
  69. });
  70. //Collapse or Expand Menu
  71. $('.menu-toggle').on('click', function (e) {
  72. var $this = $(this);
  73. var $content = $this.next();
  74. if ($($this.parents('ul')[0]).hasClass('list')) {
  75. var $not = $(e.target).hasClass('menu-toggle') ? e.target : $(e.target).parents('.menu-toggle');
  76. $.each($('.menu-toggle.toggled').not($not).next(), function (i, val) {
  77. if ($(val).is(':visible')) {
  78. $(val).prev().toggleClass('toggled');
  79. $(val).slideUp();
  80. }
  81. });
  82. }
  83. $this.toggleClass('toggled');
  84. $content.slideToggle(320);
  85. });
  86. //Set menu height
  87. _this.setMenuHeight();
  88. _this.checkStatuForResize(true);
  89. $(window).resize(function () {
  90. _this.setMenuHeight();
  91. _this.checkStatuForResize(false);
  92. });
  93. //Set Waves
  94. Waves.attach('.menu .list a', ['waves-block']);
  95. Waves.init();
  96. },
  97. setMenuHeight: function (isFirstTime) {
  98. if (typeof $.fn.slimScroll != 'undefined') {
  99. var configs = $.AdminBSB.options.leftSideBar;
  100. var height = ($(window).height() - ($('.legal').outerHeight() + $('.user-info').outerHeight() + $('.navbar').innerHeight()));
  101. var $el = $('.list');
  102. $el.slimscroll({
  103. height: height + "px",
  104. color: configs.scrollColor,
  105. size: configs.scrollWidth,
  106. alwaysVisible: configs.scrollAlwaysVisible,
  107. borderRadius: configs.scrollBorderRadius,
  108. railBorderRadius: configs.scrollRailBorderRadius
  109. });
  110. //Scroll active menu item when page load, if option set = true
  111. if ($.AdminBSB.options.leftSideBar.scrollActiveItemWhenPageLoad) {
  112. if($('.menu .list li.active')[0] !== undefined) {
  113. var activeItemOffsetTop = $('.menu .list li.active')[0].offsetTop
  114. if (activeItemOffsetTop > 150) $el.slimscroll({scrollTo: activeItemOffsetTop + 'px'});
  115. }
  116. }
  117. }
  118. },
  119. checkStatuForResize: function (firstTime) {
  120. var $body = $('body');
  121. var $openCloseBar = $('.navbar .navbar-header .bars');
  122. var width = $body.width();
  123. if (firstTime) {
  124. $body.find('.content, .sidebar').addClass('no-animate').delay(1000).queue(function () {
  125. $(this).removeClass('no-animate').dequeue();
  126. });
  127. }
  128. if (width < $.AdminBSB.options.leftSideBar.breakpointWidth) {
  129. $body.addClass('ls-closed');
  130. $openCloseBar.fadeIn();
  131. }
  132. else {
  133. $body.removeClass('ls-closed');
  134. $openCloseBar.fadeOut();
  135. }
  136. },
  137. isOpen: function () {
  138. return $('body').hasClass('overlay-open');
  139. }
  140. };
  141. //==========================================================================================================================
  142. /* Right Sidebar - Function ================================================================================================
  143. * You can manage the right sidebar menu options
  144. *
  145. */
  146. $.AdminBSB.rightSideBar = {
  147. activate: function () {
  148. var _this = this;
  149. var $sidebar = $('#rightsidebar');
  150. var $overlay = $('.overlay');
  151. //Close sidebar
  152. $(window).click(function (e) {
  153. var $target = $(e.target);
  154. if (e.target.nodeName.toLowerCase() === 'i') { $target = $(e.target).parent(); }
  155. if (!$target.hasClass('js-right-sidebar') && _this.isOpen() && $target.parents('#rightsidebar').length === 0) {
  156. if (!$target.hasClass('bars')) $overlay.fadeOut();
  157. $sidebar.removeClass('open');
  158. }
  159. });
  160. $('.js-right-sidebar').on('click', function () {
  161. $sidebar.toggleClass('open');
  162. if (_this.isOpen()) { $overlay.fadeIn(); } else { $overlay.fadeOut(); }
  163. });
  164. },
  165. isOpen: function () {
  166. return $('.right-sidebar').hasClass('open');
  167. }
  168. }
  169. //==========================================================================================================================
  170. /* Searchbar - Function ================================================================================================
  171. * You can manage the search bar
  172. *
  173. */
  174. var $searchBar = $('.search-bar');
  175. $.AdminBSB.search = {
  176. activate: function () {
  177. var _this = this;
  178. //Search button click event
  179. $('.js-search').on('click', function () {
  180. _this.showSearchBar();
  181. });
  182. //Close search click event
  183. $searchBar.find('.close-search').on('click', function () {
  184. _this.hideSearchBar();
  185. });
  186. //ESC key on pressed
  187. $searchBar.find('input[type="text"]').on('keyup', function (e) {
  188. if (e.keyCode == 27) {
  189. _this.hideSearchBar();
  190. }
  191. });
  192. },
  193. showSearchBar: function () {
  194. $searchBar.addClass('open');
  195. $searchBar.find('input[type="text"]').focus();
  196. },
  197. hideSearchBar: function () {
  198. $searchBar.removeClass('open');
  199. $searchBar.find('input[type="text"]').val('');
  200. }
  201. }
  202. //==========================================================================================================================
  203. /* Navbar - Function =======================================================================================================
  204. * You can manage the navbar
  205. *
  206. */
  207. $.AdminBSB.navbar = {
  208. activate: function () {
  209. var $body = $('body');
  210. var $overlay = $('.overlay');
  211. //Open left sidebar panel
  212. $('.bars').on('click', function () {
  213. $body.toggleClass('overlay-open');
  214. if ($body.hasClass('overlay-open')) { $overlay.fadeIn(); } else { $overlay.fadeOut(); }
  215. });
  216. //Close collapse bar on click event
  217. $('.nav [data-close="true"]').on('click', function () {
  218. var isVisible = $('.navbar-toggle').is(':visible');
  219. var $navbarCollapse = $('.navbar-collapse');
  220. if (isVisible) {
  221. $navbarCollapse.slideUp(function () {
  222. $navbarCollapse.removeClass('in').removeAttr('style');
  223. });
  224. }
  225. });
  226. }
  227. }
  228. //==========================================================================================================================
  229. /* Input - Function ========================================================================================================
  230. * You can manage the inputs(also textareas) with name of class 'form-control'
  231. *
  232. */
  233. $.AdminBSB.input = {
  234. activate: function () {
  235. //On focus event
  236. $('.form-control').focus(function () {
  237. $(this).parent().addClass('focused');
  238. });
  239. //On focusout event
  240. $('.form-control').focusout(function () {
  241. var $this = $(this);
  242. if ($this.parents('.form-group').hasClass('form-float')) {
  243. if ($this.val() == '') { $this.parents('.form-line').removeClass('focused'); }
  244. }
  245. else {
  246. $this.parents('.form-line').removeClass('focused');
  247. }
  248. });
  249. //On label click
  250. $('body').on('click', '.form-float .form-line .form-label', function () {
  251. $(this).parent().find('input').focus();
  252. });
  253. //Not blank form
  254. $('.form-control').each(function () {
  255. if ($(this).val() !== '') {
  256. $(this).parents('.form-line').addClass('focused');
  257. }
  258. });
  259. }
  260. }
  261. //==========================================================================================================================
  262. /* Form - Select - Function ================================================================================================
  263. * You can manage the 'select' of form elements
  264. *
  265. */
  266. $.AdminBSB.select = {
  267. activate: function () {
  268. if ($.fn.selectpicker) { $('select:not(.ms)').selectpicker(); }
  269. }
  270. }
  271. //==========================================================================================================================
  272. /* DropdownMenu - Function =================================================================================================
  273. * You can manage the dropdown menu
  274. *
  275. */
  276. $.AdminBSB.dropdownMenu = {
  277. activate: function () {
  278. var _this = this;
  279. $('.dropdown, .dropup, .btn-group').on({
  280. "show.bs.dropdown": function () {
  281. var dropdown = _this.dropdownEffect(this);
  282. _this.dropdownEffectStart(dropdown, dropdown.effectIn);
  283. },
  284. "shown.bs.dropdown": function () {
  285. var dropdown = _this.dropdownEffect(this);
  286. if (dropdown.effectIn && dropdown.effectOut) {
  287. _this.dropdownEffectEnd(dropdown, function () { });
  288. }
  289. },
  290. "hide.bs.dropdown": function (e) {
  291. var dropdown = _this.dropdownEffect(this);
  292. if (dropdown.effectOut) {
  293. e.preventDefault();
  294. _this.dropdownEffectStart(dropdown, dropdown.effectOut);
  295. _this.dropdownEffectEnd(dropdown, function () {
  296. dropdown.dropdown.removeClass('open');
  297. });
  298. }
  299. }
  300. });
  301. //Set Waves
  302. Waves.attach('.dropdown-menu li a', ['waves-block']);
  303. Waves.init();
  304. },
  305. dropdownEffect: function (target) {
  306. var effectIn = $.AdminBSB.options.dropdownMenu.effectIn, effectOut = $.AdminBSB.options.dropdownMenu.effectOut;
  307. var dropdown = $(target), dropdownMenu = $('.dropdown-menu', target);
  308. if (dropdown.length > 0) {
  309. var udEffectIn = dropdown.data('effect-in');
  310. var udEffectOut = dropdown.data('effect-out');
  311. if (udEffectIn !== undefined) { effectIn = udEffectIn; }
  312. if (udEffectOut !== undefined) { effectOut = udEffectOut; }
  313. }
  314. return {
  315. target: target,
  316. dropdown: dropdown,
  317. dropdownMenu: dropdownMenu,
  318. effectIn: effectIn,
  319. effectOut: effectOut
  320. };
  321. },
  322. dropdownEffectStart: function (data, effectToStart) {
  323. if (effectToStart) {
  324. data.dropdown.addClass('dropdown-animating');
  325. data.dropdownMenu.addClass('animated dropdown-animated');
  326. data.dropdownMenu.addClass(effectToStart);
  327. }
  328. },
  329. dropdownEffectEnd: function (data, callback) {
  330. var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
  331. data.dropdown.one(animationEnd, function () {
  332. data.dropdown.removeClass('dropdown-animating');
  333. data.dropdownMenu.removeClass('animated dropdown-animated');
  334. data.dropdownMenu.removeClass(data.effectIn);
  335. data.dropdownMenu.removeClass(data.effectOut);
  336. if (typeof callback == 'function') {
  337. callback();
  338. }
  339. });
  340. }
  341. }
  342. //==========================================================================================================================
  343. /* Browser - Function ======================================================================================================
  344. * You can manage browser
  345. *
  346. */
  347. var edge = 'Microsoft Edge';
  348. var ie10 = 'Internet Explorer 10';
  349. var ie11 = 'Internet Explorer 11';
  350. var opera = 'Opera';
  351. var firefox = 'Mozilla Firefox';
  352. var chrome = 'Google Chrome';
  353. var safari = 'Safari';
  354. $.AdminBSB.browser = {
  355. activate: function () {
  356. var _this = this;
  357. var className = _this.getClassName();
  358. if (className !== '') $('html').addClass(_this.getClassName());
  359. },
  360. getBrowser: function () {
  361. var userAgent = navigator.userAgent.toLowerCase();
  362. if (/edge/i.test(userAgent)) {
  363. return edge;
  364. } else if (/rv:11/i.test(userAgent)) {
  365. return ie11;
  366. } else if (/msie 10/i.test(userAgent)) {
  367. return ie10;
  368. } else if (/opr/i.test(userAgent)) {
  369. return opera;
  370. } else if (/chrome/i.test(userAgent)) {
  371. return chrome;
  372. } else if (/firefox/i.test(userAgent)) {
  373. return firefox;
  374. } else if (!!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/)) {
  375. return safari;
  376. }
  377. return undefined;
  378. },
  379. getClassName: function () {
  380. var browser = this.getBrowser();
  381. if (browser === edge) {
  382. return 'edge';
  383. } else if (browser === ie11) {
  384. return 'ie11';
  385. } else if (browser === ie10) {
  386. return 'ie10';
  387. } else if (browser === opera) {
  388. return 'opera';
  389. } else if (browser === chrome) {
  390. return 'chrome';
  391. } else if (browser === firefox) {
  392. return 'firefox';
  393. } else if (browser === safari) {
  394. return 'safari';
  395. } else {
  396. return '';
  397. }
  398. }
  399. }
  400. //==========================================================================================================================
  401. $(function () {
  402. $.AdminBSB.browser.activate();
  403. $.AdminBSB.leftSideBar.activate();
  404. $.AdminBSB.rightSideBar.activate();
  405. $.AdminBSB.navbar.activate();
  406. $.AdminBSB.dropdownMenu.activate();
  407. $.AdminBSB.input.activate();
  408. $.AdminBSB.select.activate();
  409. $.AdminBSB.search.activate();
  410. setTimeout(function () { $('.page-loader-wrapper').fadeOut(); }, 50);
  411. });