PageSourceSearch

https://www.0564.ua/assets/2851b084/scrollSentry.js?v=1789825604

js 0564.ua collected 2026-10-02 08:24:32 UTC 4,416 bytes, 116 lines download raw bytes

1/**
2 * @typedef {Object} ScrollSentrySettings
3 * @property {string} scrollEvent
4 * @property {string} resizeEvent
5 * @property {string} triggerElement
6 * @property {number} triggerDeltaHeight
7 * @property {string} triggerEvent
8 */
9(function ($) {
10    var $document = $(document),
11        $window = $(window),
12        windowHeight = -1;
13
14    $.fn.scrollSentry = function (option) {
15
16        var ScrollSentry = function (element, options) {
17            /** @type {ScrollSentrySettings} */
18            this.settings = $.extend({}, ScrollSentry.defaultOptions, options);
19            this.$element = $(element);
20            this.isDocumentTriggerElement = "document" === this.settings.triggerElement;
21            if (this.settings.delay > 0) {
22                var self = this;
23                setTimeout(function () {
24                    self._init();
25                    $window.triggerHandler(self.settings.resizeEvent);
26                    $window.triggerHandler(self.settings.scrollEvent);
27                }, this.settings.delay);
28            } else {
29                this._init();
30            }
31        };
32
33        ScrollSentry.namespace = 'scrollSentry';
34
35        /** @type {ScrollSentrySettings} */
36        ScrollSentry.defaultOptions = {
37            scrollEvent: "scroll",
38            resizeEvent: "resize",
39            triggerElement: "document",
40            triggerDeltaHeight: 300,
41            triggerEvent: "scrollSentryTrigger",
42            delay: 0
43        };
44
45        ScrollSentry.prototype._getTriggerTop = function () {
46            var s = this.settings;
47            if (0 === this.$triggerElement.length) {
48                // Отключаем поведение
49                return -1;
50            }
51
52            return !this.isDocumentTriggerElement ?
53                this.$triggerElement.offset().top - s.triggerDeltaHeight :
54                $document.height() - Math.max(s.triggerDeltaHeight, windowHeight + 10);
55        };
56
57        ScrollSentry.prototype._init = function () {
58            this.$triggerElement = $(this.settings.triggerElement, this.$element);
59            this.triggerTop = !this.isDocumentTriggerElement ? this._getTriggerTop() : -1;
60
61            this._initEventHandlers();
62        };
63
64        ScrollSentry.prototype._initEventHandlers = function () {
65            var self = this,
66                settings = this.settings;
67            $window
68                .on(settings.scrollEvent, function () {
69                    if (windowHeight < 0 || self.triggerTop < 0) {
70                        return;
71                    }
72                    var scrollBottom = $document.scrollTop() + windowHeight;
73                    if (scrollBottom >= self.triggerTop) {
74                        self.triggerTop = -1;
75                        self.$element.trigger(settings.triggerEvent, [self.$triggerElement]);
76                    }
77                })
78                .on(settings.resizeEvent, function () {
79                    windowHeight = $window.height();
80                    if (self.isDocumentTriggerElement) {
81                        self.triggerTop = self._getTriggerTop();
82                    }
83                });
84        };
85
86        ScrollSentry.prototype.reArm = function () {
87            this.$triggerElement = $(this.settings.triggerElement, this.$element);
88            this.triggerTop = this._getTriggerTop();
89        };
90
91        ScrollSentry.methods = {
92            reArm: ScrollSentry.prototype.reArm
93        };
94
95        var scopeArguments = arguments;
96        if ("string" === typeof option && "function" === typeof ScrollSentry.methods[option]) {
97            var data = this.data("cis." + ScrollSentry.namespace);
98            if (data) {
99                return ScrollSentry.methods[option].apply(data, Array.prototype.slice.call(scopeArguments, 1));
100            }
101        }
102
103        return this.each(function () {
104            var $this = $(this),
105                data = $this.data("cis." + ScrollSentry.namespace),
106                options = "object" === typeof option && option;
107
108            if (!data) {
109                $this.data("cis." + ScrollSentry.namespace, (data = new ScrollSentry(this, options)));
110            }
111            if ("string" === typeof option && "function" === typeof ScrollSentry.methods[option]) {
112                ScrollSentry.methods[option].apply(data, Array.prototype.slice.call(scopeArguments, 1));
113            }
114        });
115    };
116})(jQuery);

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.