PageSourceSearch

https://www.emaantracker.com/wp-content/themes/one-page-express/assets/js/smoothscroll.js?ver=1.0.8

js emaantracker.com collected 2026-09-25 03:25:17 UTC 9,913 bytes, 286 lines download raw bytes

1var currentPageURL = document.location.toString();
2var isAnchor = false;
3if (location.hash) {
4    isAnchor = true;
5    window.scrollTo(0, 0);
6}
7jQuery(document).ready(function () {
8
9    if (window.useManagedSmoothScroll) {
10        return;
11    }
12
13    var duration = 1500;
14    var easing = 'easeInOutQuart';
15    var lastId, anchors, scrollItems;
16
17    function targetIsSamePage(target) {
18        return !target || target == "_self";
19    }
20
21    function getHash(url) {
22        if (!url) {
23            return false;
24        }
25        var indexOfHash = url.indexOf('#');
26        if (indexOfHash > -1) {
27            if (indexOfHash === 0) {
28                return url.replace('#', '');
29            }
30            var hash = url.substring(indexOfHash + 1);
31            var urlQuery = "";
32            if (url.indexOf('?') > -1) {
33                urlQuery = url.substring(url.indexOf('?'));
34            }
35            var absLinkRegExp = /(https?|file):\/\//;
36            var pageLocation = window.location.pathname;
37            var urlLocation = url.replace(urlQuery, '').replace('#' + hash, '').replace(absLinkRegExp, '');
38            if (url.match(absLinkRegExp)) {
39                pageLocation = window.location.host + pageLocation;
40            } else {
41                urlLocation = pageLocation.substring(0, pageLocation.lastIndexOf("/")) + "/" + urlLocation;
42            }
43            if (pageLocation == urlLocation || pageLocation == urlLocation + "/") {
44                return hash;
45            }
46        }
47        return false;
48    }
49
50    function change_url_hash(hash) {
51        setTimeout(function () {
52            if (hash) {
53                hash = "#" + hash;
54            } else {
55                hash = "";
56            }
57            if (history && history.replaceState) {
58                history.replaceState({}, "", hash);
59            } else {
60            }
61        }, 100);
62        /* safari issue fixed by throtteling the event */
63    }
64
65    var scrollStarted = false;
66
67
68    function scrollToSection(section, elem) {
69        if (scrollStarted) {
70            return;
71        }
72
73        try {
74            scrollStarted = true;
75
76            if (section) {
77                var parent;
78                if (elem) {
79                    parent = elem.parent().parentsUntil('body').filter(function () {
80                        if (jQuery(this).css('position') == "fixed" && !jQuery(this).is('.mobile-overlay')) return jQuery(this);
81                    }).eq(0);
82                }
83
84                var topDistance = 0;
85                if (parent && parent.length) {
86                    var parentClass = parent.attr("class");
87                    var flexiMenu = jQuery('div[class*="_menu_wrapper"]');
88                    if (parent.outerHeight() !== window.innerHeight || !parent.is('.full-sidebar')) {
89                        topDistance = parent.outerHeight() + parent.position().top;
90                    }
91                }
92                var scrollToValue = section.offset().top - topDistance;
93                if (scrollToValue < 0) {
94                    scrollToValue = 0;
95                }
96                var stickTo = jQuery("[data-cp-shrink=initial]");
97                if (scrollToValue > stickTo.height()) {
98                    scrollToValue -= jQuery('[data-cp-shrink=shrinked]').height();
99                }
100
101                var ratio = Math.max(0.5, scrollToValue / jQuery('body').height());
102
103                jQuery('html, body').animate({
104                    scrollTop: scrollToValue
105                }, duration * ratio, easing, function () {
106                    scrollStarted = false;
107                    jQuery(window).trigger('scroll');
108                    jQuery(document).trigger('scroll');
109                });
110
111                return true;
112            }
113        } catch (e) {
114            alert('error in xtd one page site script ' + e);
115        }
116    }
117
118    function linkClick(ev, elem) {
119
120        if (!targetIsSamePage(elem.attr("target"))) {
121            return;
122        }
123
124        var section = elem.data('onepage-section') ? elem.data('onepage-section') : false;
125
126        var scrolled = scrollToSection(section, elem);
127        if (scrolled && ev) {
128            ev.preventDefault();
129        }
130
131    }
132
133    function bubbleSortByTop(arr) {
134        var swapped;
135        do {
136            swapped = false;
137            for (var i = 0; i < arr.length - 1; i++) {
138                var elem = arr[i];
139                var elem2 = arr[i + 1];
140                if (elem.offset().top > elem2.offset().top) {
141                    var temp = arr[i];
142                    arr[i] = arr[i + 1];
143                    arr[i + 1] = temp;
144                    swapped = true;
145                }
146            }
147        } while (swapped);
148    }
149
150    function getAnchors() {
151        scrollItems = [];
152        anchors = jQuery('a').filter(function () {
153            var elem = jQuery(this);
154            var href = elem.attr('href');
155            var target = elem.attr('target');
156            var hash = getHash(href);
157            if (hash && hash !== 'wp-toolbar') {
158                var section = jQuery("#" + hash);
159                if (section.length > 0) {
160                    elem.data('onepage-section', section);
161                    if (elem.parent()[0].tagName == "LI") {
162                        section.data('onepage-anchor', elem);
163                    }
164                    scrollItems.push(section);
165                    return true;
166                }
167            }
168            return false;
169        }).unbind('click.onePage').bind("click.onePage", function (e) {
170            e.preventDefault();
171            e.stopPropagation();
172            linkClick(e, jQuery(this));
173        });
174        anchors.each(function () {
175            if (jQuery(this).parent()[0].tagName == "LI") {
176                var selfAnchor = this;
177                jQuery(this).unbind('click.onePage');
178                jQuery(this).attr('data-smoothscroll', 'true');
179                jQuery(this).parent().unbind('click.onePage').bind("click.onePage", function (e) {
180                    e.preventDefault();
181                    e.stopPropagation();
182                    linkClick(e, jQuery(selfAnchor));
183                });
184            }
185        });
186        try {
187            bubbleSortByTop(scrollItems);
188        } catch (e) {
189        }
190    }
191
192    var scrollTimeout;
193    var is_touch_device = 'ontouchstart' in document.documentElement;
194    if (!is_touch_device) {
195        jQuery(window).scroll(function () {
196            clearTimeout(scrollTimeout);
197            scrollTimeout = setTimeout(doneScrolling, 20);
198        });
199    }
200
201    function doneScrolling() {
202        var windowElem = jQuery(window);
203        var fromTop = windowElem.scrollTop() + window.innerHeight * 0.5;
204        var cur = [];
205        if (!scrollItems) {
206            getAnchors();
207        }
208        for (var i = 0; i < scrollItems.length; i++) {
209            if (scrollItems[i].offset().top < fromTop) {
210                cur.push(scrollItems[i]);
211            }
212        }
213        var lastItem = scrollItems[scrollItems.length - 1];
214        if ((windowElem.scrollTop() + windowElem.height() + 50) >= jQuery(document).height()) {
215            cur.push(lastItem);
216        }
217        cur = cur[cur.length - 1];
218        var id = cur && cur.length ? cur[0].id : "";
219        change_url_hash(id);
220        if (id.length === 0) {
221            // anchors.closest('ul').find('.current_page_item').removeClass('current_page_item');
222            anchors.parent().andSelf().removeClass('current_page_item');
223            loc = (window.location + "").split('#')[0].replace(/\/$/, "");
224            anchors.closest('ul').find('[href$="' + loc + '"]').eq(0).parent().andSelf().addClass('current_page_item');
225            if (!loc.length) {
226                anchors.closest('ul').find('[href$="' + window.location + '"]').eq(0).parent().andSelf().addClass('current_page_item');
227
228            }
229        }
230
231        if (lastId !== id && id.length) {
232            lastId = id;
233            try {
234                anchors.filter('.current_page_item').each(function () {
235                    jQuery(this).parent().andSelf().removeClass('current_page_item');
236
237                });
238                anchors.closest('ul').find('.current_page_item').removeClass('current_page_item');
239                cur.data('onepage-anchor').parent().andSelf().addClass('current_page_item');
240            } catch (e) {
241            }
242        }
243    }
244
245    var id;
246    jQuery(window).bind("resize orientationchange", function () {
247        clearTimeout(id);
248        id = setTimeout(doneResizing, 100);
249    });
250
251    function doneResizing() {
252        getAnchors();
253    }
254
255    getAnchors();
256
257    is_touch_device = 'ontouchstart' in document.documentElement;
258
259    if (!is_touch_device) {
260        doneScrolling();
261    }
262    if (isAnchor) {
263        if (jQuery.find('a[href^="' + currentPageURL + '"]').length > 0) {
264            jQuery(jQuery.find('a[href="' + currentPageURL + '"]')).trigger('click');
265        } else {
266            var hash = getHash(currentPageURL);
267            if (hash.length) {
268                jQuery(jQuery.find('a[href*="#' + hash + '"]')).trigger('click');
269            }
270        }
271    } else {
272        jQuery('a[href*="#"]').each(function (index, el) {
273            var parts = el.href.split('#'),
274                anchor = parts[parts.length - 1];
275
276            if (parts.length >= 2) {
277                if (anchor.length) {
278                    jQuery(this).parent().andSelf().removeClass('current_page_item');
279                }
280            }
281        });
282    }
283
284    window.scrollToSection = scrollToSection;
285    window.smoothScrollGetAnchors = getAnchors;
286});

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.