soft-ui-dashboard.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. "use strict";
  2. (function() {
  3. var isWindows = navigator.platform.indexOf('Win') > -1 ? true : false;
  4. if (isWindows) {
  5. // if we are on windows OS we activate the perfectScrollbar function
  6. if (document.getElementsByClassName('main-content')[0]) {
  7. var mainpanel = document.querySelector('.main-content');
  8. var ps = new PerfectScrollbar(mainpanel);
  9. };
  10. if (document.getElementsByClassName('sidenav')[0]) {
  11. var sidebar = document.querySelector('.sidenav');
  12. var ps1 = new PerfectScrollbar(sidebar);
  13. };
  14. if (document.getElementsByClassName('navbar-collapse')[0]) {
  15. var fixedplugin = document.querySelector('.navbar:not(.navbar-expand-lg) .navbar-collapse');
  16. var ps2 = new PerfectScrollbar(fixedplugin);
  17. };
  18. if (document.getElementsByClassName('fixed-plugin')[0]) {
  19. var fixedplugin = document.querySelector('.fixed-plugin');
  20. var ps3 = new PerfectScrollbar(fixedplugin);
  21. };
  22. };
  23. })();
  24. // Verify navbar blur on scroll
  25. navbarBlurOnScroll('navbarBlur');
  26. // initialization of Tooltips
  27. var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
  28. var tooltipList = tooltipTriggerList.map(function(tooltipTriggerEl) {
  29. return new bootstrap.Tooltip(tooltipTriggerEl)
  30. })
  31. // Fixed Plugin
  32. if (document.querySelector('.fixed-plugin')) {
  33. var fixedPlugin = document.querySelector('.fixed-plugin');
  34. var fixedPluginButton = document.querySelector('.fixed-plugin-button');
  35. var fixedPluginButtonNav = document.querySelector('.fixed-plugin-button-nav');
  36. var fixedPluginCard = document.querySelector('.fixed-plugin .card');
  37. var fixedPluginCloseButton = document.querySelectorAll('.fixed-plugin-close-button');
  38. var navbar = document.getElementById('navbarBlur');
  39. var buttonNavbarFixed = document.getElementById('navbarFixed');
  40. if (fixedPluginButton) {
  41. fixedPluginButton.onclick = function() {
  42. if (!fixedPlugin.classList.contains('show')) {
  43. fixedPlugin.classList.add('show');
  44. } else {
  45. fixedPlugin.classList.remove('show');
  46. }
  47. }
  48. }
  49. if (fixedPluginButtonNav) {
  50. fixedPluginButtonNav.onclick = function() {
  51. if (!fixedPlugin.classList.contains('show')) {
  52. fixedPlugin.classList.add('show');
  53. } else {
  54. fixedPlugin.classList.remove('show');
  55. }
  56. }
  57. }
  58. fixedPluginCloseButton.forEach(function(el) {
  59. el.onclick = function() {
  60. fixedPlugin.classList.remove('show');
  61. }
  62. })
  63. document.querySelector('body').onclick = function(e) {
  64. if (e.target != fixedPluginButton && e.target != fixedPluginButtonNav && e.target.closest('.fixed-plugin .card') != fixedPluginCard) {
  65. fixedPlugin.classList.remove('show');
  66. }
  67. }
  68. if (navbar) {
  69. if (navbar.getAttribute('navbar-scroll') == 'true') {
  70. buttonNavbarFixed.setAttribute("checked", "true");
  71. }
  72. }
  73. }
  74. // Tabs navigation
  75. var total = document.querySelectorAll('.nav-pills');
  76. total.forEach(function(item, i) {
  77. var moving_div = document.createElement('div');
  78. var first_li = item.querySelector('li:first-child .nav-link');
  79. var tab = first_li.cloneNode();
  80. tab.innerHTML = "-";
  81. moving_div.classList.add('moving-tab', 'position-absolute', 'nav-link');
  82. moving_div.appendChild(tab);
  83. item.appendChild(moving_div);
  84. var list_length = item.getElementsByTagName("li").length;
  85. moving_div.style.padding = '0px';
  86. moving_div.style.width = item.querySelector('li:nth-child(1)').offsetWidth + 'px';
  87. moving_div.style.transform = 'translate3d(0px, 0px, 0px)';
  88. moving_div.style.transition = '.5s ease';
  89. item.onmouseover = function(event) {
  90. let target = getEventTarget(event);
  91. let li = target.closest('li'); // get reference
  92. if (li) {
  93. let nodes = Array.from(li.closest('ul').children); // get array
  94. let index = nodes.indexOf(li) + 1;
  95. item.querySelector('li:nth-child(' + index + ') .nav-link').onclick = function() {
  96. moving_div = item.querySelector('.moving-tab');
  97. let sum = 0;
  98. if (item.classList.contains('flex-column')) {
  99. for (var j = 1; j <= nodes.indexOf(li); j++) {
  100. sum += item.querySelector('li:nth-child(' + j + ')').offsetHeight;
  101. }
  102. moving_div.style.transform = 'translate3d(0px,' + sum + 'px, 0px)';
  103. moving_div.style.height = item.querySelector('li:nth-child(' + j + ')').offsetHeight;
  104. } else {
  105. for (var j = 1; j <= nodes.indexOf(li); j++) {
  106. sum += item.querySelector('li:nth-child(' + j + ')').offsetWidth;
  107. }
  108. moving_div.style.transform = 'translate3d(' + sum + 'px, 0px, 0px)';
  109. moving_div.style.width = item.querySelector('li:nth-child(' + index + ')').offsetWidth + 'px';
  110. }
  111. }
  112. }
  113. }
  114. });
  115. // Tabs navigation resize
  116. window.addEventListener('resize', function(event) {
  117. total.forEach(function(item, i) {
  118. item.querySelector('.moving-tab').remove();
  119. var moving_div = document.createElement('div');
  120. var tab = item.querySelector(".nav-link.active").cloneNode();
  121. tab.innerHTML = "-";
  122. moving_div.classList.add('moving-tab', 'position-absolute', 'nav-link');
  123. moving_div.appendChild(tab);
  124. item.appendChild(moving_div);
  125. moving_div.style.padding = '0px';
  126. moving_div.style.transition = '.5s ease';
  127. let li = item.querySelector(".nav-link.active").parentElement;
  128. if (li) {
  129. let nodes = Array.from(li.closest('ul').children); // get array
  130. let index = nodes.indexOf(li) + 1;
  131. let sum = 0;
  132. if (item.classList.contains('flex-column')) {
  133. for (var j = 1; j <= nodes.indexOf(li); j++) {
  134. sum += item.querySelector('li:nth-child(' + j + ')').offsetHeight;
  135. }
  136. moving_div.style.transform = 'translate3d(0px,' + sum + 'px, 0px)';
  137. moving_div.style.width = item.querySelector('li:nth-child(' + index + ')').offsetWidth + 'px';
  138. moving_div.style.height = item.querySelector('li:nth-child(' + j + ')').offsetHeight;
  139. } else {
  140. for (var j = 1; j <= nodes.indexOf(li); j++) {
  141. sum += item.querySelector('li:nth-child(' + j + ')').offsetWidth;
  142. }
  143. moving_div.style.transform = 'translate3d(' + sum + 'px, 0px, 0px)';
  144. moving_div.style.width = item.querySelector('li:nth-child(' + index + ')').offsetWidth + 'px';
  145. }
  146. }
  147. });
  148. if (window.innerWidth < 991) {
  149. total.forEach(function(item, i) {
  150. if (!item.classList.contains('flex-column')) {
  151. item.classList.add('flex-column', 'on-resize');
  152. }
  153. });
  154. } else {
  155. total.forEach(function(item, i) {
  156. if (item.classList.contains('on-resize')) {
  157. item.classList.remove('flex-column', 'on-resize');
  158. }
  159. })
  160. }
  161. });
  162. function getEventTarget(e) {
  163. e = e || window.event;
  164. return e.target || e.srcElement;
  165. }
  166. // End tabs navigation
  167. //Set Sidebar Color
  168. function sidebarColor(a) {
  169. var parent = a.parentElement.children;
  170. var color = a.getAttribute("data-color");
  171. for (var i = 0; i < parent.length; i++) {
  172. parent[i].classList.remove('active');
  173. }
  174. if (!a.classList.contains('active')) {
  175. a.classList.add('active');
  176. } else {
  177. a.classList.remove('active');
  178. }
  179. var sidebar = document.querySelector('.sidenav');
  180. sidebar.setAttribute("data-color", color);
  181. if (document.querySelector('#sidenavCard')) {
  182. var sidenavCard = document.querySelector('#sidenavCard');
  183. let sidenavCardClasses = ['card', 'card-background', 'shadow-none', 'card-background-mask-' + color];
  184. sidenavCard.className = '';
  185. sidenavCard.classList.add(...sidenavCardClasses);
  186. var sidenavCardIcon = document.querySelector('#sidenavCardIcon');
  187. let sidenavCardIconClasses = ['ni', 'ni-diamond', 'text-gradient', 'text-lg', 'top-0', 'text-' + color];
  188. sidenavCardIcon.className = '';
  189. sidenavCardIcon.classList.add(...sidenavCardIconClasses);
  190. }
  191. }
  192. // Set Navbar Fixed
  193. function navbarFixed(el) {
  194. let classes = ['position-sticky', 'blur', 'shadow-blur', 'mt-4', 'left-auto', 'top-1', 'z-index-sticky'];
  195. const navbar = document.getElementById('navbarBlur');
  196. if (!el.getAttribute("checked")) {
  197. navbar.classList.add(...classes);
  198. navbar.setAttribute('navbar-scroll', 'true');
  199. navbarBlurOnScroll('navbarBlur');
  200. el.setAttribute("checked", "true");
  201. } else {
  202. navbar.classList.remove(...classes);
  203. navbar.setAttribute('navbar-scroll', 'false');
  204. navbarBlurOnScroll('navbarBlur');
  205. el.removeAttribute("checked");
  206. }
  207. };
  208. // Navbar blur on scroll
  209. function navbarBlurOnScroll(id) {
  210. const navbar = document.getElementById(id);
  211. let navbarScrollActive = navbar ? navbar.getAttribute("navbar-scroll") : false;
  212. let scrollDistance = 5;
  213. let classes = ['position-sticky', 'blur', 'shadow-blur', 'mt-4', 'left-auto', 'top-1', 'z-index-sticky'];
  214. let toggleClasses = ['shadow-none'];
  215. if (navbarScrollActive == 'true') {
  216. window.onscroll = debounce(function() {
  217. if (window.scrollY > scrollDistance) {
  218. blurNavbar();
  219. } else {
  220. transparentNavbar();
  221. }
  222. }, 10);
  223. } else {
  224. window.onscroll = debounce(function() {
  225. transparentNavbar();
  226. }, 10);
  227. }
  228. function blurNavbar() {
  229. navbar.classList.add(...classes)
  230. navbar.classList.remove(...toggleClasses)
  231. toggleNavLinksColor('blur');
  232. }
  233. function transparentNavbar() {
  234. if (navbar) {
  235. navbar.classList.remove(...classes)
  236. navbar.classList.add(...toggleClasses)
  237. toggleNavLinksColor('transparent');
  238. }
  239. }
  240. function toggleNavLinksColor(type) {
  241. let navLinks = document.querySelectorAll('.navbar-main .nav-link')
  242. let navLinksToggler = document.querySelectorAll('.navbar-main .sidenav-toggler-line')
  243. if (type === "blur") {
  244. navLinks.forEach(element => {
  245. element.classList.remove('text-body')
  246. });
  247. navLinksToggler.forEach(element => {
  248. element.classList.add('bg-dark')
  249. });
  250. } else if (type === "transparent") {
  251. navLinks.forEach(element => {
  252. element.classList.add('text-body')
  253. });
  254. navLinksToggler.forEach(element => {
  255. element.classList.remove('bg-dark')
  256. });
  257. }
  258. }
  259. }
  260. // Debounce Function
  261. // Returns a function, that, as long as it continues to be invoked, will not
  262. // be triggered. The function will be called after it stops being called for
  263. // N milliseconds. If `immediate` is passed, trigger the function on the
  264. // leading edge, instead of the trailing.
  265. function debounce(func, wait, immediate) {
  266. var timeout;
  267. return function() {
  268. var context = this,
  269. args = arguments;
  270. var later = function() {
  271. timeout = null;
  272. if (!immediate) func.apply(context, args);
  273. };
  274. var callNow = immediate && !timeout;
  275. clearTimeout(timeout);
  276. timeout = setTimeout(later, wait);
  277. if (callNow) func.apply(context, args);
  278. };
  279. };
  280. //Set Sidebar Type
  281. function sidebarType(a) {
  282. var parent = a.parentElement.children;
  283. var color = a.getAttribute("data-class");
  284. var colors = [];
  285. for (var i = 0; i < parent.length; i++) {
  286. parent[i].classList.remove('active');
  287. colors.push(parent[i].getAttribute('data-class'));
  288. }
  289. if (!a.classList.contains('active')) {
  290. a.classList.add('active');
  291. } else {
  292. a.classList.remove('active');
  293. }
  294. var sidebar = document.querySelector('.sidenav');
  295. for (var i = 0; i < colors.length; i++) {
  296. sidebar.classList.remove(colors[i]);
  297. }
  298. sidebar.classList.add(color);
  299. }
  300. // Toggle Sidenav
  301. const iconNavbarSidenav = document.getElementById('iconNavbarSidenav');
  302. const iconSidenav = document.getElementById('iconSidenav');
  303. const sidenav = document.getElementById('sidenav-main');
  304. let body = document.getElementsByTagName('body')[0];
  305. let className = 'g-sidenav-pinned';
  306. if (iconNavbarSidenav) {
  307. iconNavbarSidenav.addEventListener("click", toggleSidenav);
  308. }
  309. if (iconSidenav) {
  310. iconSidenav.addEventListener("click", toggleSidenav);
  311. }
  312. function toggleSidenav() {
  313. if (body.classList.contains(className)) {
  314. body.classList.remove(className);
  315. setTimeout(function() {
  316. sidenav.classList.remove('bg-white');
  317. }, 100);
  318. sidenav.classList.remove('bg-transparent');
  319. } else {
  320. body.classList.add(className);
  321. sidenav.classList.add('bg-white');
  322. sidenav.classList.remove('bg-transparent');
  323. iconSidenav.classList.remove('d-none');
  324. }
  325. }
  326. // Resize navbar color depends on configurator active type of sidenav
  327. if (document.querySelector('[data-class]')) {
  328. let referenceButtons = document.querySelector('[data-class]');
  329. window.addEventListener("resize", navbarColorOnResize);
  330. function navbarColorOnResize() {
  331. if (window.innerWidth > 1200) {
  332. if (referenceButtons.classList.contains('active') && referenceButtons.getAttribute('data-class') === 'bg-transparent') {
  333. sidenav.classList.remove('bg-white');
  334. } else {
  335. sidenav.classList.add('bg-white');
  336. }
  337. } else {
  338. sidenav.classList.add('bg-white');
  339. sidenav.classList.remove('bg-transparent');
  340. }
  341. }
  342. }
  343. // Deactivate sidenav type buttons on resize and small screens
  344. window.addEventListener("resize", sidenavTypeOnResize);
  345. window.addEventListener("load", sidenavTypeOnResize);
  346. function sidenavTypeOnResize() {
  347. let elements = document.querySelectorAll('[onclick="sidebarType(this)"]');
  348. if (window.innerWidth < 1200) {
  349. elements.forEach(function(el) {
  350. el.classList.add('disabled');
  351. });
  352. } else {
  353. elements.forEach(function(el) {
  354. el.classList.remove('disabled');
  355. });
  356. }
  357. }