PageSourceSearch

https://www.andreanhs.org/pro/js/view.js?v=1

js andreanhs.org collected 2026-09-24 12:34:23 UTC 2,899 bytes, 72 lines download raw bytes

1//////////////////////////    view.js    //////////////////////////
2
3$(function() {
4    // fix header and named anchors/id target coordination for fragment scrolling
5    // really could be a class scroll in here someday? scroll.
6    (function() {
7        if(view.isHeaderFixed()) {
8            // QUESTION: adjust scroll margin of other target fragments?
9            $('a[name^="detailid_"], a:not([href]), #profile, #staffemail').each(function() {
10                $(this).css('scroll-margin', view.scrollOffset + 'px 0 0 0'); // scroll-margin-top
11                if($(this).is('a')) { // NOTE: could even forgo this add class and simply test if a in scrollTo()
12                    $(this).addClass('scroll-offset-exempt'); // for use later
13                }
14            });
15        }
16    }());
17});
18
19// view scope namespace architecture
20const view = {
21    // lazy getter properties:
22    /* pattern:
23        get property() {
24            delete this.property;
25            set this.property;
26            return this.property;
27        }
28    */
29    get $header() {
30        delete this.$header;
31        this.$header = $('header');
32        return this.$header;
33    },
34    get headerOffsetHeight() {
35        delete this.headerOffsetHeight;
36        this.headerOffsetHeight = this.$header.get(0).offsetHeight;
37        return this.headerOffsetHeight;
38    },
39
40    // variable (non-lazy) properties
41    get scrollOffset() {
42        return (function(view) {
43            return view.isHeaderFixed() ? view.headerOffsetHeight : 0;
44        })(this);
45    },
46
47    // functions:
48    isFixed: function($) {
49        $ = (typeof $ == 'undefined' ? this : $);
50        return $.css('position') == 'fixed';
51    },
52    isHeaderFixed: function() { // elementIdentifier argument polymorphic could be an element name, id, or jQuery object
53        return this.isFixed.call(this.$header);
54    },
55    scrollTo: function(elementIdentifier) { // call this for a good scroll; primary public function interface abstract, also reduction refactoring duplicate code elimination
56        var $element = (elementIdentifier instanceof jQuery ? elementIdentifier : $('[name="' + elementIdentifier + '"]')); // name given precedence over id in element identification
57
58        if($element.length > 1) {
59            $element = $element.first(); // safety
60        }
61        else if(!$element.length) {
62            $element = $('#' + elementIdentifier);
63            if($element.length != 1) {
64                console.log('element identification failure');
65                return; // short-circuit; element identification failure
66            }
67        }
68
69        var animationSpeed = 1000; // ms; 800|1000? const.
70        $('html,body').animate({scrollTop: $element.offset().top - (!$element.hasClass('scroll-offset-exempt') ? view.scrollOffset : 0)}, animationSpeed); // where scrollOffset [0,{the exact height of the fixed header in play}]
71    }
72};

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.