front.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. $(document).ready(function () {
  2. 'use strict';
  3. // ------------------------------------------------------- //
  4. // Search Box
  5. // ------------------------------------------------------ //
  6. $('#search').on('click', function (e) {
  7. e.preventDefault();
  8. $('.search-box').fadeIn();
  9. });
  10. $('.dismiss').on('click', function () {
  11. $('.search-box').fadeOut();
  12. });
  13. // ------------------------------------------------------- //
  14. // Card Close
  15. // ------------------------------------------------------ //
  16. $('.card-close a.remove').on('click', function (e) {
  17. e.preventDefault();
  18. $(this).parents('.card').fadeOut();
  19. });
  20. // ------------------------------------------------------- //
  21. // Tooltips init
  22. // ------------------------------------------------------ //
  23. $('[data-toggle="tooltip"]').tooltip()
  24. // ------------------------------------------------------- //
  25. // Adding fade effect to dropdowns
  26. // ------------------------------------------------------ //
  27. $('.dropdown').on('show.bs.dropdown', function () {
  28. $(this).find('.dropdown-menu').first().stop(true, true).fadeIn();
  29. });
  30. $('.dropdown').on('hide.bs.dropdown', function () {
  31. $(this).find('.dropdown-menu').first().stop(true, true).fadeOut();
  32. });
  33. // ------------------------------------------------------- //
  34. // Sidebar Functionality
  35. // ------------------------------------------------------ //
  36. $('#toggle-btn').on('click', function (e) {
  37. e.preventDefault();
  38. $(this).toggleClass('active');
  39. $('.side-navbar').toggleClass('shrinked');
  40. $('.content-inner').toggleClass('active');
  41. $(document).trigger('sidebarChanged');
  42. if ($(window).outerWidth() > 1183) {
  43. if ($('#toggle-btn').hasClass('active')) {
  44. $('.navbar-header .brand-small').hide();
  45. $('.navbar-header .brand-big').show();
  46. } else {
  47. $('.navbar-header .brand-small').show();
  48. $('.navbar-header .brand-big').hide();
  49. }
  50. }
  51. if ($(window).outerWidth() < 1183) {
  52. $('.navbar-header .brand-small').show();
  53. }
  54. });
  55. // ------------------------------------------------------- //
  56. // Universal Form Validation
  57. // ------------------------------------------------------ //
  58. $('.form-validate').each(function() {
  59. $(this).validate({
  60. errorElement: "div",
  61. errorClass: 'is-invalid',
  62. validClass: 'is-valid',
  63. ignore: ':hidden:not(.summernote, .checkbox-template, .form-control-custom),.note-editable.card-block',
  64. errorPlacement: function (error, element) {
  65. // Add the `invalid-feedback` class to the error element
  66. error.addClass("invalid-feedback");
  67. console.log(element);
  68. if (element.prop("type") === "checkbox") {
  69. error.insertAfter(element.siblings("label"));
  70. }
  71. else {
  72. error.insertAfter(element);
  73. }
  74. }
  75. });
  76. });
  77. // ------------------------------------------------------- //
  78. // Material Inputs
  79. // ------------------------------------------------------ //
  80. var materialInputs = $('input.input-material');
  81. // activate labels for prefilled values
  82. materialInputs.filter(function() { return $(this).val() !== ""; }).siblings('.label-material').addClass('active');
  83. // move label on focus
  84. materialInputs.on('focus', function () {
  85. $(this).siblings('.label-material').addClass('active');
  86. });
  87. // remove/keep label on blur
  88. materialInputs.on('blur', function () {
  89. $(this).siblings('.label-material').removeClass('active');
  90. if ($(this).val() !== '') {
  91. $(this).siblings('.label-material').addClass('active');
  92. } else {
  93. $(this).siblings('.label-material').removeClass('active');
  94. }
  95. });
  96. // ------------------------------------------------------- //
  97. // Footer
  98. // ------------------------------------------------------ //
  99. var contentInner = $('.content-inner');
  100. $(document).on('sidebarChanged', function () {
  101. adjustFooter();
  102. });
  103. $(window).on('resize', function () {
  104. adjustFooter();
  105. })
  106. function adjustFooter() {
  107. var footerBlockHeight = $('.main-footer').outerHeight();
  108. contentInner.css('padding-bottom', footerBlockHeight + 'px');
  109. }
  110. // ------------------------------------------------------- //
  111. // External links to new window
  112. // ------------------------------------------------------ //
  113. $('.external').on('click', function (e) {
  114. e.preventDefault();
  115. window.open($(this).attr("href"));
  116. });
  117. // ------------------------------------------------------ //
  118. // For demo purposes, can be deleted
  119. // ------------------------------------------------------ //
  120. var stylesheet = $('link#theme-stylesheet');
  121. $("<link id='new-stylesheet' rel='stylesheet'>").insertAfter(stylesheet);
  122. var alternateColour = $('link#new-stylesheet');
  123. if ($.cookie("theme_csspath")) {
  124. alternateColour.attr("href", $.cookie("theme_csspath"));
  125. }
  126. $("#colour").change(function () {
  127. if ($(this).val() !== '') {
  128. var theme_csspath = 'css/style.' + $(this).val() + '.css';
  129. alternateColour.attr("href", theme_csspath);
  130. $.cookie("theme_csspath", theme_csspath, {
  131. expires: 365,
  132. path: document.URL.substr(0, document.URL.lastIndexOf('/'))
  133. });
  134. }
  135. return false;
  136. });
  137. });