default.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. var fixedTop = false;
  2. var transparent = true;
  3. var navbar_initialized = false;
  4. $(document).ready(function(){
  5. window_width = $(window).width();
  6. // Init navigation toggle for small screens
  7. if(window_width <= 991){
  8. pd.initRightMenu();
  9. }
  10. // Activate the tooltips
  11. $('[rel="tooltip"]').tooltip();
  12. });
  13. // activate collapse right menu when the windows is resized
  14. $(window).resize(function(){
  15. if($(window).width() <= 991){
  16. pd.initRightMenu();
  17. }
  18. });
  19. pd = {
  20. misc:{
  21. navbar_menu_visible: 0
  22. },
  23. checkScrollForTransparentNavbar: debounce(function() {
  24. if($(document).scrollTop() > 381 ) {
  25. if(transparent) {
  26. transparent = false;
  27. $('.navbar-color-on-scroll').removeClass('navbar-transparent');
  28. $('.navbar-title').removeClass('hidden');
  29. }
  30. } else {
  31. if( !transparent ) {
  32. transparent = true;
  33. $('.navbar-color-on-scroll').addClass('navbar-transparent');
  34. $('.navbar-title').addClass('hidden');
  35. }
  36. }
  37. }),
  38. initRightMenu: function(){
  39. if(!navbar_initialized){
  40. $off_canvas_sidebar = $('nav').find('.navbar-collapse').first().clone(true);
  41. $sidebar = $('.sidebar');
  42. sidebar_bg_color = $sidebar.data('background-color');
  43. sidebar_active_color = $sidebar.data('active-color');
  44. $logo = $sidebar.find('.logo').first();
  45. logo_content = $logo[0].outerHTML;
  46. ul_content = '';
  47. // set the bg color and active color from the default sidebar to the off canvas sidebar;
  48. $off_canvas_sidebar.attr('data-background-color',sidebar_bg_color);
  49. $off_canvas_sidebar.attr('data-active-color',sidebar_active_color);
  50. $off_canvas_sidebar.addClass('off-canvas-sidebar');
  51. //add the content from the regular header to the right menu
  52. $off_canvas_sidebar.children('ul').each(function(){
  53. content_buff = $(this).html();
  54. ul_content = ul_content + content_buff;
  55. });
  56. // add the content from the sidebar to the right menu
  57. content_buff = $sidebar.find('.nav').html();
  58. ul_content = ul_content + '<li class="divider"></li>'+ content_buff;
  59. ul_content = '<ul class="nav navbar-nav">' + ul_content + '</ul>';
  60. navbar_content = logo_content + ul_content;
  61. navbar_content = '<div class="sidebar-wrapper">' + navbar_content + '</div>';
  62. $off_canvas_sidebar.html(navbar_content);
  63. $('body').append($off_canvas_sidebar);
  64. $toggle = $('.navbar-toggle');
  65. $off_canvas_sidebar.find('a').removeClass('btn btn-round btn-default');
  66. $off_canvas_sidebar.find('button').removeClass('btn-round btn-fill btn-info btn-primary btn-success btn-danger btn-warning btn-neutral');
  67. $off_canvas_sidebar.find('button').addClass('btn-simple btn-block');
  68. $toggle.click(function (){
  69. if(pd.misc.navbar_menu_visible == 1) {
  70. $('html').removeClass('nav-open');
  71. pd.misc.navbar_menu_visible = 0;
  72. $('#bodyClick').remove();
  73. setTimeout(function(){
  74. $toggle.removeClass('toggled');
  75. }, 400);
  76. } else {
  77. setTimeout(function(){
  78. $toggle.addClass('toggled');
  79. }, 430);
  80. div = '<div id="bodyClick"></div>';
  81. $(div).appendTo("body").click(function() {
  82. $('html').removeClass('nav-open');
  83. pd.misc.navbar_menu_visible = 0;
  84. $('#bodyClick').remove();
  85. setTimeout(function(){
  86. $toggle.removeClass('toggled');
  87. }, 400);
  88. });
  89. $('html').addClass('nav-open');
  90. pd.misc.navbar_menu_visible = 1;
  91. }
  92. });
  93. navbar_initialized = true;
  94. }
  95. }
  96. }
  97. // Returns a function, that, as long as it continues to be invoked, will not
  98. // be triggered. The function will be called after it stops being called for
  99. // N milliseconds. If `immediate` is passed, trigger the function on the
  100. // leading edge, instead of the trailing.
  101. function debounce(func, wait, immediate) {
  102. var timeout;
  103. return function() {
  104. var context = this, args = arguments;
  105. clearTimeout(timeout);
  106. timeout = setTimeout(function() {
  107. timeout = null;
  108. if (!immediate) func.apply(context, args);
  109. }, wait);
  110. if (immediate && !timeout) func.apply(context, args);
  111. };
  112. };