admin.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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. var activeItemOffsetTop = $('.menu .list li.active')[0].offsetTop
  113. if (activeItemOffsetTop > 150) $el.slimscroll({ scrollTo: activeItemOffsetTop + 'px' });
  114. }
  115. }
  116. },
  117. checkStatuForResize: function (firstTime) {
  118. var $body = $('body');
  119. var $openCloseBar = $('.navbar .navbar-header .bars');
  120. var width = $body.width();
  121. if (firstTime) {
  122. $body.find('.content, .sidebar').addClass('no-animate').delay(1000).queue(function () {
  123. $(this).removeClass('no-animate').dequeue();
  124. });
  125. }
  126. if (width < $.AdminBSB.options.leftSideBar.breakpointWidth) {
  127. $body.addClass('ls-closed');
  128. $openCloseBar.fadeIn();
  129. }
  130. else {
  131. $body.removeClass('ls-closed');
  132. $openCloseBar.fadeOut();
  133. }
  134. },
  135. isOpen: function () {
  136. return $('body').hasClass('overlay-open');
  137. }
  138. };
  139. //==========================================================================================================================
  140. /* Right Sidebar - Function ================================================================================================
  141. * You can manage the right sidebar menu options
  142. *
  143. */
  144. $.AdminBSB.rightSideBar = {
  145. activate: function () {
  146. var _this = this;
  147. var $sidebar = $('#rightsidebar');
  148. var $overlay = $('.overlay');
  149. //Close sidebar
  150. $(window).click(function (e) {
  151. var $target = $(e.target);
  152. if (e.target.nodeName.toLowerCase() === 'i') { $target = $(e.target).parent(); }
  153. if (!$target.hasClass('js-right-sidebar') && _this.isOpen() && $target.parents('#rightsidebar').length === 0) {
  154. if (!$target.hasClass('bars')) $overlay.fadeOut();
  155. $sidebar.removeClass('open');
  156. }
  157. });
  158. $('.js-right-sidebar').on('click', function () {
  159. $sidebar.toggleClass('open');
  160. if (_this.isOpen()) { $overlay.fadeIn(); } else { $overlay.fadeOut(); }
  161. });
  162. },
  163. isOpen: function () {
  164. return $('.right-sidebar').hasClass('open');
  165. }
  166. }
  167. //==========================================================================================================================
  168. /* Searchbar - Function ================================================================================================
  169. * You can manage the search bar
  170. *
  171. */
  172. var $searchBar = $('.search-bar');
  173. $.AdminBSB.search = {
  174. activate: function () {
  175. var _this = this;
  176. //Search button click event
  177. $('.js-search').on('click', function () {
  178. _this.showSearchBar();
  179. });
  180. //Close search click event
  181. $searchBar.find('.close-search').on('click', function () {
  182. _this.hideSearchBar();
  183. });
  184. //ESC key on pressed
  185. $searchBar.find('input[type="text"]').on('keyup', function (e) {
  186. if (e.keyCode == 27) {
  187. _this.hideSearchBar();
  188. }
  189. });
  190. },
  191. showSearchBar: function () {
  192. $searchBar.addClass('open');
  193. $searchBar.find('input[type="text"]').focus();
  194. },
  195. hideSearchBar: function () {
  196. $searchBar.removeClass('open');
  197. $searchBar.find('input[type="text"]').val('');
  198. }
  199. }
  200. //==========================================================================================================================
  201. /* Navbar - Function =======================================================================================================
  202. * You can manage the navbar
  203. *
  204. */
  205. $.AdminBSB.navbar = {
  206. activate: function () {
  207. var $body = $('body');
  208. var $overlay = $('.overlay');
  209. //Open left sidebar panel
  210. $('.bars').on('click', function () {
  211. $body.toggleClass('overlay-open');
  212. if ($body.hasClass('overlay-open')) { $overlay.fadeIn(); } else { $overlay.fadeOut(); }
  213. });
  214. //Close collapse bar on click event
  215. $('.nav [data-close="true"]').on('click', function () {
  216. var isVisible = $('.navbar-toggle').is(':visible');
  217. var $navbarCollapse = $('.navbar-collapse');
  218. if (isVisible) {
  219. $navbarCollapse.slideUp(function () {
  220. $navbarCollapse.removeClass('in').removeAttr('style');
  221. });
  222. }
  223. });
  224. }
  225. }
  226. //==========================================================================================================================
  227. /* Input - Function ========================================================================================================
  228. * You can manage the inputs(also textareas) with name of class 'form-control'
  229. *
  230. */
  231. $.AdminBSB.input = {
  232. activate: function () {
  233. //On focus event
  234. $('.form-control').focus(function () {
  235. $(this).parent().addClass('focused');
  236. });
  237. //On focusout event
  238. $('.form-control').focusout(function () {
  239. var $this = $(this);
  240. if ($this.parents('.form-group').hasClass('form-float')) {
  241. if ($this.val() == '') { $this.parents('.form-line').removeClass('focused'); }
  242. }
  243. else {
  244. $this.parents('.form-line').removeClass('focused');
  245. }
  246. });
  247. //On label click
  248. $('body').on('click', '.form-float .form-line .form-label', function () {
  249. $(this).parent().find('input').focus();
  250. });
  251. //Not blank form
  252. $('.form-control').each(function () {
  253. if ($(this).val() !== '') {
  254. $(this).parents('.form-line').addClass('focused');
  255. }
  256. });
  257. }
  258. }
  259. //==========================================================================================================================
  260. /* Form - Select - Function ================================================================================================
  261. * You can manage the 'select' of form elements
  262. *
  263. */
  264. $.AdminBSB.select = {
  265. activate: function () {
  266. if ($.fn.selectpicker) { $('select:not(.ms)').selectpicker(); }
  267. }
  268. }
  269. //==========================================================================================================================
  270. /* DropdownMenu - Function =================================================================================================
  271. * You can manage the dropdown menu
  272. *
  273. */
  274. $.AdminBSB.dropdownMenu = {
  275. activate: function () {
  276. var _this = this;
  277. $('.dropdown, .dropup, .btn-group').on({
  278. "show.bs.dropdown": function () {
  279. var dropdown = _this.dropdownEffect(this);
  280. _this.dropdownEffectStart(dropdown, dropdown.effectIn);
  281. },
  282. "shown.bs.dropdown": function () {
  283. var dropdown = _this.dropdownEffect(this);
  284. if (dropdown.effectIn && dropdown.effectOut) {
  285. _this.dropdownEffectEnd(dropdown, function () { });
  286. }
  287. },
  288. "hide.bs.dropdown": function (e) {
  289. var dropdown = _this.dropdownEffect(this);
  290. if (dropdown.effectOut) {
  291. e.preventDefault();
  292. _this.dropdownEffectStart(dropdown, dropdown.effectOut);
  293. _this.dropdownEffectEnd(dropdown, function () {
  294. dropdown.dropdown.removeClass('open');
  295. });
  296. }
  297. }
  298. });
  299. //Set Waves
  300. Waves.attach('.dropdown-menu li a', ['waves-block']);
  301. Waves.init();
  302. },
  303. dropdownEffect: function (target) {
  304. var effectIn = $.AdminBSB.options.dropdownMenu.effectIn, effectOut = $.AdminBSB.options.dropdownMenu.effectOut;
  305. var dropdown = $(target), dropdownMenu = $('.dropdown-menu', target);
  306. if (dropdown.length > 0) {
  307. var udEffectIn = dropdown.data('effect-in');
  308. var udEffectOut = dropdown.data('effect-out');
  309. if (udEffectIn !== undefined) { effectIn = udEffectIn; }
  310. if (udEffectOut !== undefined) { effectOut = udEffectOut; }
  311. }
  312. return {
  313. target: target,
  314. dropdown: dropdown,
  315. dropdownMenu: dropdownMenu,
  316. effectIn: effectIn,
  317. effectOut: effectOut
  318. };
  319. },
  320. dropdownEffectStart: function (data, effectToStart) {
  321. if (effectToStart) {
  322. data.dropdown.addClass('dropdown-animating');
  323. data.dropdownMenu.addClass('animated dropdown-animated');
  324. data.dropdownMenu.addClass(effectToStart);
  325. }
  326. },
  327. dropdownEffectEnd: function (data, callback) {
  328. var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
  329. data.dropdown.one(animationEnd, function () {
  330. data.dropdown.removeClass('dropdown-animating');
  331. data.dropdownMenu.removeClass('animated dropdown-animated');
  332. data.dropdownMenu.removeClass(data.effectIn);
  333. data.dropdownMenu.removeClass(data.effectOut);
  334. if (typeof callback == 'function') {
  335. callback();
  336. }
  337. });
  338. }
  339. }
  340. //==========================================================================================================================
  341. /* Browser - Function ======================================================================================================
  342. * You can manage browser
  343. *
  344. */
  345. var edge = 'Microsoft Edge';
  346. var ie10 = 'Internet Explorer 10';
  347. var ie11 = 'Internet Explorer 11';
  348. var opera = 'Opera';
  349. var firefox = 'Mozilla Firefox';
  350. var chrome = 'Google Chrome';
  351. var safari = 'Safari';
  352. $.AdminBSB.browser = {
  353. activate: function () {
  354. var _this = this;
  355. var className = _this.getClassName();
  356. if (className !== '') $('html').addClass(_this.getClassName());
  357. },
  358. getBrowser: function () {
  359. var userAgent = navigator.userAgent.toLowerCase();
  360. if (/edge/i.test(userAgent)) {
  361. return edge;
  362. } else if (/rv:11/i.test(userAgent)) {
  363. return ie11;
  364. } else if (/msie 10/i.test(userAgent)) {
  365. return ie10;
  366. } else if (/opr/i.test(userAgent)) {
  367. return opera;
  368. } else if (/chrome/i.test(userAgent)) {
  369. return chrome;
  370. } else if (/firefox/i.test(userAgent)) {
  371. return firefox;
  372. } else if (!!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/)) {
  373. return safari;
  374. }
  375. return undefined;
  376. },
  377. getClassName: function () {
  378. var browser = this.getBrowser();
  379. if (browser === edge) {
  380. return 'edge';
  381. } else if (browser === ie11) {
  382. return 'ie11';
  383. } else if (browser === ie10) {
  384. return 'ie10';
  385. } else if (browser === opera) {
  386. return 'opera';
  387. } else if (browser === chrome) {
  388. return 'chrome';
  389. } else if (browser === firefox) {
  390. return 'firefox';
  391. } else if (browser === safari) {
  392. return 'safari';
  393. } else {
  394. return '';
  395. }
  396. }
  397. }
  398. //==========================================================================================================================
  399. $(function () {
  400. $.AdminBSB.browser.activate();
  401. $.AdminBSB.leftSideBar.activate();
  402. $.AdminBSB.rightSideBar.activate();
  403. $.AdminBSB.navbar.activate();
  404. $.AdminBSB.dropdownMenu.activate();
  405. $.AdminBSB.input.activate();
  406. $.AdminBSB.select.activate();
  407. $.AdminBSB.search.activate();
  408. setTimeout(function () { $('.page-loader-wrapper').fadeOut(); }, 50);
  409. });