PageSourceSearch

https://www.playemotions.it/wp-content/themes/one-page-express/assets/js/smoothscroll.js?ver=1.3.21

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

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.