Skip to content

Instantly share code, notes, and snippets.

@joshco
Last active April 30, 2020 06:31
Show Gist options
  • Save joshco/928cb93d81c696407e63b85c2053b7ce to your computer and use it in GitHub Desktop.
Save joshco/928cb93d81c696407e63b85c2053b7ce to your computer and use it in GitHub Desktop.
adv search box

On post pages, Menu Bar Search box doesnt open when search icon is clicked. (it works on main page)

Drupal.behaviors.advocateTheme... is only running on the main page.

If that is by design, the code that sets the click event listeners can be set in a document ready block instead of Drupal.behaviors... See Working Code below. (just like the section above it setting the load resize scroll event handlers)

(I'm using chrome on win10x64)

File

https://www.advocate.com/sites/advocate.com/files/advagg_js/js__pKeS74qEIK-ctkd14qdyisuErNkvLJuCt8aG79MHAg0__1ysaI47LG2Ste5LPPKcxkdjR4ne5qN72cTQSW23QPZk__sBAWPuKToWrtRrrp7wCojNXjukU8QlQoiaP2klXzo1k.js

At the end of the file, lines 1972-EOF (line numbers are from prettified version so may be inaccurate)

Non-Working code

;;(function($) {
    Drupal.behaviors.advocateTheme = {
        attach: function(context, settings) {
            var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ? true : false;
            $(".page-contact .tabs").append("<div class='contact-text-header'>You can leave a message using the contact form below. For all magazine subscription needs please use: <a href='subcontact' target='_blank' style='color: #980000;'>www.advocate.com/subcontact</a> </div>");
            $('iframe[src*="youtube.com"], iframe[src*="player.vimeo.com"]').each(function() {
                $(this).wrap('<div class="video-responsive"></div>');
            });
            $('.pager-current').wrapInner('<span></span>');
            $('.searchBox').click(function(e) {
                $(this).toggleClass('active');
                e.stopPropagation();
            });
            $('.searchForm').click(function(e) {
                $('.searchBox').addClass('locked');
                e.stopPropagation();
            });
            $(document).click(function(e) {
                $('.searchBox').removeClass('locked');
                $('.searchBox').removeClass('active');
                e.stopPropagation();
            });
            if (!isMobile) {
                $('.magazines .beanMagazine').hover(function() {
                    $('.hoverBox').animate({
                        'right': '0px'
                    }, 'slow');
                }, function() {
                    $('.hoverBox').animate({
                        'right': '129px'
                    }, 'slow');
                });
            }
        }
    };
}
)(jQuery);
;;

Working code

;;(function($) {
            
    var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ? true : false;
    $(document).ready(function($) {
        $(".page-contact .tabs").append("<div class='contact-text-header'>You can leave a message using the contact form below. For all magazine subscription needs please use: <a href='subcontact' target='_blank' style='color: #980000;'>www.advocate.com/subcontact</a> </div>");
        $('iframe[src*="youtube.com"], iframe[src*="player.vimeo.com"]').each(function() {
            $(this).wrap('<div class="video-responsive"></div>');
        });
        $('.pager-current').wrapInner('<span></span>');
        $('.searchBox').click(function(e) {
            $(this).toggleClass('active');
            e.stopPropagation();
        });
        $('.searchForm').click(function(e) {
            $('.searchBox').addClass('locked');
            e.stopPropagation();
        });
        $(document).click(function(e) {
            $('.searchBox').removeClass('locked');
            $('.searchBox').removeClass('active');
            e.stopPropagation();
        });
        if (!isMobile) {
            $('.magazines .beanMagazine').hover(function() {
                $('.hoverBox').animate({
                    'right': '0px'
                }, 'slow');
            }, function() {
                $('.hoverBox').animate({
                    'right': '129px'
                }, 'slow');
            });
        }
    })
}
)(jQuery);
;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment