/src/js/partials/basic_scripts.js

https://gitlab.com/sheep-fish-vert/coldAsfAlt · JavaScript · 154 lines · 111 code · 36 blank · 7 comment · 12 complexity · 36544748d93939671e0604a882901cb9 MD5 · raw file

  1. jQuery.browser = {};
  2. jQuery.browser.mozilla = /mozilla/.test(navigator.userAgent.toLowerCase()) && !/webkit/.test(navigator.userAgent.toLowerCase());
  3. jQuery.browser.webkit = /webkit/.test(navigator.userAgent.toLowerCase());
  4. jQuery.browser.opera = /opera/.test(navigator.userAgent.toLowerCase());
  5. jQuery.browser.msie = /msie/.test(navigator.userAgent.toLowerCase());
  6. var scroller=jQuery.browser.webkit ? "body": "html";
  7. $.scrollbarWidth=function(){var a,b,c;if(c===undefined){a=$('<div style="width:50px;height:50px;overflow:auto"><div/></div>').appendTo('body');b=a.children();c=b.innerWidth()-b.height(99).innerWidth();a.remove()}return c};
  8. /* scrollUp */
  9. function scrollUp(block,targetBlock) {
  10. $(block).click(function(e){
  11. var target = $(targetBlock).offset().top;
  12. $(scroller).animate({scrollTop:target},800);
  13. return false;
  14. e.preventDefault();
  15. });
  16. }
  17. function oneHeightItems(){
  18. function oneHeight(block){
  19. var height=0;
  20. block.removeAttr('style');
  21. block.each(function(){
  22. if($(this).height()>height){
  23. height=$(this).height();
  24. }
  25. });
  26. block.css('height', height);
  27. }
  28. oneHeight($('.oneHeight'));
  29. oneHeight($('.street-repairds-text'));
  30. oneHeight($('.top-block-wrap .text'));
  31. $(window).load(function(){
  32. oneHeight($('.street-repairds-text'));
  33. oneHeight($('.top-block-wrap .text'));
  34. });
  35. $(window).resize(function(){
  36. oneHeight($('.street-repairds-text'));
  37. oneHeight($('.top-block-wrap .text'));
  38. });
  39. }
  40. /*scroll animation*/
  41. function animationBlock(item){
  42. $(window).scroll(function(){
  43. checkForAnimate();
  44. });
  45. function checkForAnimate(){
  46. var bottomCheck = $(window).height()+$(window).scrollTop();
  47. var windowTop = $(window).scrollTop()+($(window).height()/1.5);
  48. item.each(function(){
  49. if(windowTop>$(this).offset().top || bottomCheck > $('body').height()*0.98){
  50. var itemSect = $(this);
  51. var point = 0;
  52. itemSect.find('.animate-it').addClass('animated');
  53. var timer = setInterval(function(){
  54. itemSect.find('.animate-delay').eq(point).addClass('animated');
  55. point++;
  56. if(itemSect.find('.animate-delay').length == point){
  57. clearInterval(timer);
  58. }
  59. },200);
  60. }
  61. });
  62. }
  63. checkForAnimate();
  64. }
  65. /*GO TO href*/
  66. function goTo(){
  67. $('.navigation_menu a').click(function(e){
  68. e.preventDefault();
  69. var href = $(this).attr('href');
  70. var target = $(href).offset().top-65;
  71. $(scroller).animate({scrollTop:target},500,function(){
  72. $('.navigation_menu').slideUp(200);
  73. $('.menu-button').removeClass('active');
  74. $('.top-main').removeClass('active');
  75. });
  76. });
  77. }
  78. // cut text script
  79. function cutText(){
  80. var filler = '...';
  81. var filler_length = filler.length;
  82. $('.cut-text').each(function(){
  83. var value = $(this).data('cut') - filler_length;
  84. var text = $.trim($(this).text());
  85. if(text.length > value && value > 0){
  86. var newText = text.substring(0,value) + filler;
  87. $(this).text(newText);
  88. }
  89. });
  90. };
  91. /*header buter*/
  92. function headeButer(menuMobile,toggleMenu){
  93. menuMobile.click(function(event) {
  94. $(this).toggleClass('active');
  95. $('.top-main').toggleClass('active');
  96. toggleMenu.stop().slideToggle(200);
  97. });
  98. $(document).on('click',function (event){
  99. var div = toggleMenu;
  100. if (!div.is(event.target) && div.has(event.target).length === 0 && !menuMobile.is(event.target) && menuMobile.has(event.target).length === 0)
  101. {
  102. toggleMenu.slideUp(200);
  103. menuMobile.removeClass('active');
  104. $('.top-main').removeClass('active');
  105. }
  106. });
  107. }
  108. /* DOCUMENT READY */
  109. $(document).ready(function() {
  110. headeButer($('.menu-button'),$('.navigation_menu'));
  111. $('.footer_placeholder').height($('.footer').outerHeight());
  112. goTo();
  113. //animationBlock($('.setion-animate'));
  114. oneHeightItems();
  115. });
  116. $(window).resize(function() {
  117. $('.footer_placeholder').height($('.footer').outerHeight());
  118. });