Ingen beskrivning

black-dashboard.js 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*!
  2. =========================================================
  3. * Black Dashboard - v1.0.1
  4. =========================================================
  5. * Product Page: https://www.creative-tim.com/product/black-dashboard
  6. * Copyright 2019 Creative Tim (https://www.creative-tim.com)
  7. * Coded by Creative Tim
  8. =========================================================
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  10. */
  11. var transparent = true;
  12. var transparentDemo = true;
  13. var fixedTop = false;
  14. var navbar_initialized = false;
  15. var backgroundOrange = false;
  16. var sidebar_mini_active = false;
  17. var toggle_initialized = false;
  18. var $html = $('html');
  19. var $body = $('body');
  20. var $navbar_minimize_fixed = $('.navbar-minimize-fixed');
  21. var $collapse = $('.collapse');
  22. var $navbar = $('.navbar');
  23. var $tagsinput = $('.tagsinput');
  24. var $selectpicker = $('.selectpicker');
  25. var $navbar_color = $('.navbar[color-on-scroll]');
  26. var $full_screen_map = $('.full-screen-map');
  27. var $datetimepicker = $('.datetimepicker');
  28. var $datepicker = $('.datepicker');
  29. var $timepicker = $('.timepicker');
  30. var seq = 0,
  31. delays = 80,
  32. durations = 500;
  33. var seq2 = 0,
  34. delays2 = 80,
  35. durations2 = 500;
  36. (function() {
  37. var isWindows = navigator.platform.indexOf('Win') > -1 ? true : false;
  38. if (isWindows) {
  39. // if we are on windows OS we activate the perfectScrollbar function
  40. if ($('.main-panel').length != 0) {
  41. var ps = new PerfectScrollbar('.main-panel', {
  42. wheelSpeed: 2,
  43. wheelPropagation: true,
  44. minScrollbarLength: 20,
  45. suppressScrollX: true
  46. });
  47. }
  48. if ($('.sidebar .sidebar-wrapper').length != 0) {
  49. var ps1 = new PerfectScrollbar('.sidebar .sidebar-wrapper');
  50. $('.table-responsive').each(function() {
  51. var ps2 = new PerfectScrollbar($(this)[0]);
  52. });
  53. }
  54. $html.addClass('perfect-scrollbar-on');
  55. } else {
  56. $html.addClass('perfect-scrollbar-off');
  57. }
  58. })();
  59. $(document).ready(function() {
  60. var scroll_start = 0;
  61. var startchange = $('.row');
  62. var offset = startchange.offset();
  63. var scrollElement = navigator.platform.indexOf('Win') > -1 ? $(".ps") : $(window);
  64. scrollElement.scroll(function() {
  65. scroll_start = $(this).scrollTop();
  66. if (scroll_start > 50) {
  67. $(".navbar-minimize-fixed").css('opacity', '1');
  68. } else {
  69. $(".navbar-minimize-fixed").css('opacity', '0');
  70. }
  71. });
  72. $(document).scroll(function() {
  73. scroll_start = $(this).scrollTop();
  74. if (scroll_start > offset.top) {
  75. $(".navbar-minimize-fixed").css('opacity', '1');
  76. } else {
  77. $(".navbar-minimize-fixed").css('opacity', '0');
  78. }
  79. });
  80. if ($('.full-screen-map').length == 0 && $('.bd-docs').length == 0) {
  81. // On click navbar-collapse the menu will be white not transparent
  82. $('.collapse').on('show.bs.collapse', function() {
  83. $(this).closest('.navbar').removeClass('navbar-transparent').addClass('bg-white');
  84. }).on('hide.bs.collapse', function() {
  85. $(this).closest('.navbar').addClass('navbar-transparent').removeClass('bg-white');
  86. });
  87. }
  88. blackDashboard.initMinimizeSidebar();
  89. $navbar = $('.navbar[color-on-scroll]');
  90. scroll_distance = $navbar.attr('color-on-scroll') || 500;
  91. // Check if we have the class "navbar-color-on-scroll" then add the function to remove the class "navbar-transparent" so it will transform to a plain color.
  92. if ($('.navbar[color-on-scroll]').length != 0) {
  93. blackDashboard.checkScrollForTransparentNavbar();
  94. $(window).on('scroll', blackDashboard.checkScrollForTransparentNavbar)
  95. }
  96. $('.form-control').on("focus", function() {
  97. $(this).parent('.input-group').addClass("input-group-focus");
  98. }).on("blur", function() {
  99. $(this).parent(".input-group").removeClass("input-group-focus");
  100. });
  101. // Activate bootstrapSwitch
  102. $('.bootstrap-switch').each(function() {
  103. $this = $(this);
  104. data_on_label = $this.data('on-label') || '';
  105. data_off_label = $this.data('off-label') || '';
  106. $this.bootstrapSwitch({
  107. onText: data_on_label,
  108. offText: data_off_label
  109. });
  110. });
  111. });
  112. $(document).on('click', '.navbar-toggle', function() {
  113. var $toggle = $(this);
  114. if (blackDashboard.misc.navbar_menu_visible == 1) {
  115. $html.removeClass('nav-open');
  116. blackDashboard.misc.navbar_menu_visible = 0;
  117. setTimeout(function() {
  118. $toggle.removeClass('toggled');
  119. $('.bodyClick').remove();
  120. }, 550);
  121. } else {
  122. setTimeout(function() {
  123. $toggle.addClass('toggled');
  124. }, 580);
  125. var div = '<div class="bodyClick"></div>';
  126. $(div).appendTo('body').click(function() {
  127. $html.removeClass('nav-open');
  128. blackDashboard.misc.navbar_menu_visible = 0;
  129. setTimeout(function() {
  130. $toggle.removeClass('toggled');
  131. $('.bodyClick').remove();
  132. }, 550);
  133. });
  134. $html.addClass('nav-open');
  135. blackDashboard.misc.navbar_menu_visible = 1;
  136. }
  137. });
  138. $(window).resize(function() {
  139. // reset the seq for charts drawing animations
  140. seq = seq2 = 0;
  141. if ($full_screen_map.length == 0 && $('.bd-docs').length == 0) {
  142. var isExpanded = $navbar.find('[data-toggle="collapse"]').attr("aria-expanded");
  143. if ($navbar.hasClass('bg-white') && $(window).width() > 991) {
  144. $navbar.removeClass('bg-white').addClass('navbar-transparent');
  145. } else if ($navbar.hasClass('navbar-transparent') && $(window).width() < 991 && isExpanded != "false") {
  146. $navbar.addClass('bg-white').removeClass('navbar-transparent');
  147. }
  148. }
  149. });
  150. blackDashboard = {
  151. misc: {
  152. navbar_menu_visible: 0
  153. },
  154. initMinimizeSidebar: function() {
  155. if ($('.sidebar-mini').length != 0) {
  156. sidebar_mini_active = true;
  157. }
  158. $('#minimizeSidebar').click(function() {
  159. var $btn = $(this);
  160. if (sidebar_mini_active == true) {
  161. $('body').removeClass('sidebar-mini');
  162. sidebar_mini_active = false;
  163. blackDashboard.showSidebarMessage('Sidebar mini deactivated...');
  164. } else {
  165. $('body').addClass('sidebar-mini');
  166. sidebar_mini_active = true;
  167. blackDashboard.showSidebarMessage('Sidebar mini activated...');
  168. }
  169. // we simulate the window Resize so the charts will get updated in realtime.
  170. var simulateWindowResize = setInterval(function() {
  171. window.dispatchEvent(new Event('resize'));
  172. }, 180);
  173. // we stop the simulation of Window Resize after the animations are completed
  174. setTimeout(function() {
  175. clearInterval(simulateWindowResize);
  176. }, 1000);
  177. });
  178. },
  179. showSidebarMessage: function(message) {
  180. try {
  181. $.notify({
  182. icon: "tim-icons ui-1_bell-53",
  183. message: message
  184. }, {
  185. type: 'info',
  186. timer: 4000,
  187. placement: {
  188. from: 'top',
  189. align: 'right'
  190. }
  191. });
  192. } catch (e) {
  193. console.log('Notify library is missing, please make sure you have the notifications library added.');
  194. }
  195. }
  196. };
  197. function hexToRGB(hex, alpha) {
  198. var r = parseInt(hex.slice(1, 3), 16),
  199. g = parseInt(hex.slice(3, 5), 16),
  200. b = parseInt(hex.slice(5, 7), 16);
  201. if (alpha) {
  202. return "rgba(" + r + ", " + g + ", " + b + ", " + alpha + ")";
  203. } else {
  204. return "rgb(" + r + ", " + g + ", " + b + ")";
  205. }
  206. }