PageSourceSearch

https://rrbuildings.com/wp-content/plugins/fixed-menu-anchor/js/fixed-menu-anchor.js?ver=1

js rrbuildings.com collected 2026-10-06 14:09:06 UTC 2,595 bytes, 78 lines download raw bytes

1/**
2 * That file is part of the fixed-menu-anchor plugin.
3 */
4if (typeof jQuery != 'undefined') {
5    jQuery(document).ready(function(){
6        // dive into click events for anchors
7        jQuery('a[href*="#"]').click(function(e){
8
9            // stop execution in case, the user wants to ignore elements with a certain
10            // CSS class.
11            if (jQuery(this).hasClass(fixedMenuAnchorCssClassesToBeIgnored)
12                && '' != fixedMenuAnchorCssClassesToBeIgnored) {
13                return;
14            }
15
16            // get top-left position of the target element on the screen
17            var top = fixedMenuAnchor_getTopValueOfAnchorTarget(jQuery, this);
18
19            // get distance(user defined) between anchor-target and screen-top.
20            var distance = fixedMenuAnchor_getDistance(window.innerWidth);
21
22            // move the screen to the top coordinate minus the user given distance
23            jQuery('html, body').animate({scrollTop: top - distance}, 500);
24        });
25    });
26} else {
27    console.log('jQuery is not loaded therefore the Fixed Menu Anchor plugin was set inactive.');
28}
29
30/**
31 * Based on the given window width, the according distance between anchor and top-window position gets returned.
32 *
33 * @param int windowWidth
34 * @returns int Distance set by user.
35 */
36function fixedMenuAnchor_getDistance(windowWidth)
37{
38    if (windowWidth <= fixedMenuAnchorMaximumViewportWidth) {
39        return fixedMenuAnchorMaximumViewportWidthDistance;
40    } else {
41        return fixedMenuAnchorUserDefinedDistance;
42    }
43}
44
45/**
46 * Get top value of anchor target.
47 *
48 * @param object jQ Referene to jQuery. In that way you can test that function without the need of jQuery.
49 * @param object anchorLink
50 * @return null|int Top position of anchor target, if available, null otherwise.
51 */
52function fixedMenuAnchor_getTopValueOfAnchorTarget(jQ, anchorLink)
53{
54    var href = jQ(anchorLink).attr('href');
55
56    // extract name of the anchor target (usually identified via ID or name).
57    var anchorName = href.substr(href.indexOf("#")+1);
58
59    // try to find element using name
60    var offset = jQ('[name="' + anchorName + '"]').offset();
61
62    // anchor target found by name
63    if (null != offset) {
64        return offset.top;
65
66    // anchor target was not found by name, try using ID
67    } else {
68        offset = jQ('[id="' + anchorName + '"]').offset();
69
70        // anchor target found by ID
71        if (null != offset) {
72            return offset.top;
73
74        } else {
75            // anchor target is whether to be found using id nor name.
76        }
77    }
78}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.