Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. (function($, Drupal) {
  2. Drupal.behaviors.shptBlocksNavigation = {
  3. attach: function(context) {
  4.  
  5. $('#block-shpt-theme-branding a').attr('id', '#home');
  6. $('#block-navigation', context).once('block-navigation').each(function() {
  7. var secondaryNavigation = $('.secondary-navigation');
  8. var isExpandingCollapsing = false;
  9. var isLearnExpanded = false;
  10.  
  11. window.setTimeout(function() {
  12. $(window).trigger('resize');
  13. }, 500);
  14.  
  15. $(window).on('resize scroll', function() {
  16. var windowTop = parseInt($(window).scrollTop()) + parseInt($('#sticky-container-top').height());
  17. var windowBottom = windowTop + parseInt($(window).height()) - 50;
  18. var learn = $('#learn');
  19. var learnTop = learn.offset().top;
  20. var learnBottom = learnTop + learn.height() - 50;
  21. var learnLink = $('.header-bar a, #block-shpt-theme-branding a').eq(1);
  22.  
  23. if ($(this).width() < 640 && $('.main-menu').is(":visible")) {
  24. if ($(window).scrollTop() > 50) {
  25. $("button.menu-icon").css('box-shadow', '0 0 10px 1px #89939c');
  26. } else {
  27. $("button.menu-icon").css('box-shadow', 'none')
  28. }
  29. }
  30.  
  31. var scrolledToIt = ((learnTop - 10) <= windowTop && learnBottom >= windowTop);
  32. var inViewPort = (windowTop <= learnTop && windowBottom >= learnBottom);
  33. if (scrolledToIt || inViewPort) {
  34. isLearnExpanded = true;
  35. if (!isExpandingCollapsing) {
  36. isExpandingCollapsing = true;
  37. if (inViewPort) {
  38. $('#main-menu .navigation-ul a').removeClass('is-active');
  39. learnLink.addClass('is-active in-view-port');
  40. }
  41. secondaryNavigation.slideDown('fast', function () {
  42. isExpandingCollapsing = false;
  43. if (!isLearnExpanded) {
  44. $(window).trigger('resize');
  45. }
  46. });
  47. }
  48. } else {
  49. isLearnExpanded = false;
  50. if (!isExpandingCollapsing) {
  51. isExpandingCollapsing = true;
  52. if (learnLink.hasClass('in-view-port')) {
  53. learnLink.removeClass('is-active in-view-port');
  54. }
  55. secondaryNavigation.slideUp('fast', function () {
  56. isExpandingCollapsing = false;
  57. if (isLearnExpanded) {
  58. $(window).trigger('resize');
  59. }
  60. });
  61. }
  62. }
  63. });
  64. });
  65. },
  66. };
  67. })(jQuery, Drupal);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement