PageSourceSearch

https://alfamarmoraria.com.br/wp-content/themes/alfa-marmoraria/js/smoothscroll.js?ver=4.1.37

js alfamarmoraria.com.br collected 2026-10-04 20:42:26 UTC 22,891 bytes, 704 lines download raw bytes

1function browser() {
2    var browser = "Unknown browser";
3    if(!!window.chrome && !(!!window.opera))  browser = 'chrome'; // Chrome 1+
4    if(typeof InstallTrigger !== 'undefined')  browser = 'firefox'; // Firefox 1.0+
5    if(!!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0)  browser = 'opera'; // Opera 8.0+ (UA detection to detect Blink/v8-powered Opera)
6    if(/*@cc_on!@*/false || !!document.documentMode)  browser = 'ie'; // At least IE6
7    if(Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0)  browser = 'safari'; // At least Safari 3+: "[object HTMLElementConstructor]"
8    
9    return browser;
10}
11
12if(browser() === 'chrome' || browser() === 'ie_11') {    
13    // SmoothScroll for websites v1.2.1
14
15
16    // Licensed under the terms of the MIT license.
17
18    // People involved
19    //  - Balazs Galambosi (maintainer)  
20    //  - Michael Herf     (Pulse Algorithm)
21
22    (function(){
23
24        // Scroll Variables (tweakable)
25        var defaultOptions = {
26
27            // Scrolling Core
28            frameRate        : 150, // [Hz]
29            animationTime    : 400, // [px]
30            stepSize         : 120, // [px]
31
32            // Pulse (less tweakable)
33            // ratio of "tail" to "acceleration"
34            pulseAlgorithm   : true,
35            pulseScale       : 8,
36            pulseNormalize   : 1,
37
38            // Acceleration
39            accelerationDelta : 20,  // 20
40            accelerationMax   : 1,   // 1
41         
42            // Keyboard Settings
43            keyboardSupport   : true,  // option
44            arrowScroll       : 50,     // [px]
45
46            // Other
47            touchpadSupport   : true,
48            fixedBackground   : true, 
49            excluded          : ""    
50        };
51
52        var options = defaultOptions;
53
54
55        // Other Variables
56        var isExcluded = false;
57        var isFrame = false;
58        var direction = { x: 0, y: 0 };
59        var initDone  = false;
60        var root = document.documentElement;
61        var activeElement;
62        var observer;
63        var deltaBuffer = [ 120, 120, 120 ];
64
65        var key = { left: 37, up: 38, right: 39, down: 40, spacebar: 32, 
66                    pageup: 33, pagedown: 34, end: 35, home: 36 };
67
68
69        /***********************************************
70         * SETTINGS
71         ***********************************************/
72
73        var options = defaultOptions;
74
75
76        /***********************************************
77         * INITIALIZE
78         ***********************************************/
79
80        /**
81         * Tests if smooth scrolling is allowed. Shuts down everything if not.
82         */
83        function initTest() {
84
85            var disableKeyboard = false; 
86            
87            // disable keyboard support if anything above requested it
88            if (disableKeyboard) {
89                removeEvent("keydown", keydown);
90            }
91
92            if (options.keyboardSupport && !disableKeyboard) {
93                addEvent("keydown", keydown);
94            }
95        }
96
97        /**
98         * Sets up scrolls array, determines if frames are involved.
99         */
100
101
102        function init() {
103          
104            if (!document.body) return;
105
106            if(is_touch_device()) return;
107
108            var body = document.body;
109            var html = document.documentElement;
110            var windowHeight = window.innerHeight; 
111            var scrollHeight = body.scrollHeight;
112            
113            // check compat mode for root element
114            root = (document.compatMode.indexOf('CSS') >= 0) ? html : body;
115            activeElement = body;
116            
117            initTest();
118            initDone = true;
119
120            // Checks if this script is running in a frame
121            if (top != self) {
122                isFrame = true;
123            }
124
125            /**
126             * This fixes a bug where the areas left and right to 
127             * the content does not trigger the onmousewheel event
128             * on some pages. e.g.: html, body { height: 100% }
129             */
130            else if (scrollHeight > windowHeight &&
131                    (body.offsetHeight <= windowHeight || 
132                     html.offsetHeight <= windowHeight)) {
133
134                html.style.height = 'auto';
135                setTimeout(refresh, 10);
136
137                // clearfix
138                if (root.offsetHeight <= windowHeight) {
139                    var underlay = document.createElement("div");   
140                    underlay.style.clear = "both";
141                    body.appendChild(underlay);
142                }
143            }
144
145            // disable fixed background
146            if (!options.fixedBackground && !isExcluded) {
147                body.style.backgroundAttachment = "scroll";
148                html.style.backgroundAttachment = "scroll";
149            }
150        }
151
152
153        /************************************************
154         * SCROLLING 
155         ************************************************/
156         
157        var que = [];
158        var pending = false;
159        var lastScroll = +new Date;
160
161        /**
162         * Pushes scroll actions to the scrolling queue.
163         */
164        function scrollArray(elem, left, top, delay) {
165            
166            delay || (delay = 1000);
167            directionCheck(left, top);
168
169            if (options.accelerationMax != 1) {
170                var now = +new Date;
171                var elapsed = now - lastScroll;
172                if (elapsed < options.accelerationDelta) {
173                    var factor = (1 + (30 / elapsed)) / 2;
174                    if (factor > 1) {
175                        factor = Math.min(factor, options.accelerationMax);
176                        left *= factor;
177                        top  *= factor;
178                    }
179                }
180                lastScroll = +new Date;
181            }          
182            
183            // push a scroll command
184            que.push({
185                x: left, 
186                y: top, 
187                lastX: (left < 0) ? 0.99 : -0.99,
188                lastY: (top  < 0) ? 0.99 : -0.99, 
189                start: +new Date
190            });
191                
192            // don't act if there's a pending queue
193            if (pending) {
194                return;
195            }  
196
197            var scrollWindow = (elem === document.body);
198            
199            var step = function (time) {
200                
201                var now = +new Date;
202                var scrollX = 0;
203                var scrollY = 0; 
204            
205                for (var i = 0; i < que.length; i++) {
206                    
207                    var item = que[i];
208                    var elapsed  = now - item.start;
209                    var finished = (elapsed >= options.animationTime);
210                    
211                    // scroll position: [0, 1]
212                    var position = (finished) ? 1 : elapsed / options.animationTime;
213                    
214                    // easing [optional]
215                    if (options.pulseAlgorithm) {
216                        position = pulse(position);
217                    }
218                    
219                    // only need the difference
220                    var x = (item.x * position - item.lastX) >> 0;
221                    var y = (item.y * position - item.lastY) >> 0;
222                    
223                    // add this to the total scrolling
224                    scrollX += x;
225                    scrollY += y;            
226                    
227                    // update last values
228                    item.lastX += x;
229                    item.lastY += y;
230                
231                    // delete and step back if it's over
232                    if (finished) {
233                        que.splice(i, 1); i--;
234                    }           
235                }
236
237                // scroll left and top
238                if (scrollWindow) {
239                    window.scrollBy(scrollX, scrollY);
240                } 
241                else {
242                    if (scrollX) elem.scrollLeft += scrollX;
243                    if (scrollY) elem.scrollTop  += scrollY;                    
244                }
245                
246                // clean up if there's nothing left to do
247                if (!left && !top) {
248                    que = [];
249                }
250                
251                if (que.length) { 
252                    requestFrame(step, elem, (delay / options.frameRate + 1)); 
253                } else { 
254                    pending = false;
255                }
256            };
257            
258            // start a new queue of actions
259            requestFrame(step, elem, 0);
260            pending = true;
261        }
262
263
264        /***********************************************
265         * EVENTS
266         ***********************************************/
267
268        /**
269         * Mouse wheel handler.
270         * @param {Object} event
271         */
272        function wheel(event) {
273
274            if (!initDone) {
275                init();
276            }
277            
278            var target = event.target;
279            var overflowing = overflowingAncestor(target);
280            
281            // use default if there's no overflowing
282            // element or default action is prevented    
283            if (!overflowing || event.defaultPrevented ||
284                isNodeName(activeElement, "embed") ||
285               (isNodeName(target, "embed") && /\.pdf/i.test(target.src))) {
286                return true;
287            }
288
289            var deltaX = event.wheelDeltaX || 0;
290            var deltaY = event.wheelDeltaY || 0;
291            
292            // use wheelDelta if deltaX/Y is not available
293            if (!deltaX && !deltaY) {
294                deltaY = event.wheelDelta || 0;
295            }
296
297            // check if it's a touchpad scroll that should be ignored
298            if (!options.touchpadSupport && isTouchpad(deltaY)) {
299                return true;
300            }
301
302            // scale by step size
303            // delta is 120 most of the time
304            // synaptics seems to send 1 sometimes
305            if (Math.abs(deltaX) > 1.2) {
306                deltaX *= options.stepSize / 120;
307            }
308            if (Math.abs(deltaY) > 1.2) {
309                deltaY *= options.stepSize / 120;
310            }
311            
312            scrollArray(overflowing, -deltaX, -deltaY);
313            event.preventDefault();
314        }
315
316        /**
317         * Keydown event handler.
318         * @param {Object} event
319         */
320        function keydown(event) {
321
322            var target   = event.target;
323            var modifier = event.ctrlKey || event.altKey || event.metaKey || 
324                          (event.shiftKey && event.keyCode !== key.spacebar);
325            
326            // do nothing if user is editing text
327            // or using a modifier key (except shift)
328            // or in a dropdown
329            if ( /input|textarea|select|embed/i.test(target.nodeName) ||
330                 target.isContentEditable || 
331                 event.defaultPrevented   ||
332                 modifier ) {
333              return true;
334            }
335            // spacebar should trigger button press
336            if (isNodeName(target, "button") &&
337                event.keyCode === key.spacebar) {
338              return true;
339            }
340            
341            var shift, x = 0, y = 0;
342            var elem = overflowingAncestor(activeElement);
343            var clientHeight = elem.clientHeight;
344
345            if (elem == document.body) {
346                clientHeight = window.innerHeight;
347            }
348
349            switch (event.keyCode) {
350                case key.up:
351                    y = -options.arrowScroll;
352                    break;
353                case key.down:
354                    y = options.arrowScroll;
355                    break;         
356                case key.spacebar: // (+ shift)
357                    shift = event.shiftKey ? 1 : -1;
358                    y = -shift * clientHeight * 0.9;
359                    break;
360                case key.pageup:
361                    y = -clientHeight * 0.9;
362                    break;
363                case key.pagedown:
364                    y = clientHeight * 0.9;
365                    break;
366                case key.home:
367                    y = -elem.scrollTop;
368                    break;
369                case key.end:
370                    var damt = elem.scrollHeight - elem.scrollTop - clientHeight;
371                    y = (damt > 0) ? damt+10 : 0;
372                    break;
373                case key.left:
374                    x = -options.arrowScroll;
375                    break;
376                case key.right:
377                    x = options.arrowScroll;
378                    break;            
379                default:
380                    return true; // a key we don't care about
381            }
382
383            scrollArray(elem, x, y);
384            event.preventDefault();
385        }
386
387        /**
388         * Mousedown event only for updating activeElement
389         */
390        function mousedown(event) {
391            activeElement = event.target;
392        }
393
394
395        /***********************************************
396         * OVERFLOW
397         ***********************************************/
398         
399        var cache = {}; // cleared out every once in while
400        setInterval(function () { cache = {}; }, 10 * 1000);
401
402        var uniqueID = (function () {
403            var i = 0;
404            return function (el) {
405                return el.uniqueID || (el.uniqueID = i++);
406            };
407        })();
408
409        function setCache(elems, overflowing) {
410            for (var i = elems.length; i--;)
411                cache[uniqueID(elems[i])] = overflowing;
412            return overflowing;
413        }
414
415        function overflowingAncestor(el) {
416            var elems = [];
417            var rootScrollHeight = root.scrollHeight;
418            do {
419                var cached = cache[uniqueID(el)];
420                if (cached) {
421                    return setCache(elems, cached);
422                }
423                elems.push(el);
424                if (rootScrollHeight === el.scrollHeight) {
425                    if (!isFrame || root.clientHeight + 10 < rootScrollHeight) {
426                        return setCache(elems, document.body); // scrolling root in WebKit
427                    }
428                } else if (el.clientHeight + 10 < el.scrollHeight) {
429                    overflow = getComputedStyle(el, "").getPropertyValue("overflow-y");
430                    if (overflow === "scroll" || overflow === "auto") {
431                        return setCache(elems, el);
432                    }
433                }
434            } while (el = el.parentNode);
435        }
436
437
438        /***********************************************
439         * HELPERS
440         ***********************************************/
441
442        function addEvent(type, fn, bubble) {
443            window.addEventListener(type, fn, (bubble||false));
444        }
445
446        function removeEvent(type, fn, bubble) {
447            window.removeEventListener(type, fn, (bubble||false));  
448        }
449
450        function isNodeName(el, tag) {
451            return (el.nodeName||"").toLowerCase() === tag.toLowerCase();
452        }
453
454        function directionCheck(x, y) {
455            x = (x > 0) ? 1 : -1;
456            y = (y > 0) ? 1 : -1;
457            if (direction.x !== x || direction.y !== y) {
458                direction.x = x;
459                direction.y = y;
460                que = [];
461                lastScroll = 0;
462            }
463        }
464
465        var deltaBufferTimer;
466
467        function isTouchpad(deltaY) {
468            if (!deltaY) return;
469            deltaY = Math.abs(deltaY)
470            deltaBuffer.push(deltaY);
471            deltaBuffer.shift();
472            clearTimeout(deltaBufferTimer);
473
474            var allEquals    = (deltaBuffer[0] == deltaBuffer[1] && 
475                                deltaBuffer[1] == deltaBuffer[2]);
476            var allDivisable = (isDivisible(deltaBuffer[0], 120) &&
477                                isDivisible(deltaBuffer[1], 120) &&
478                                isDivisible(deltaBuffer[2], 120));
479            return !(allEquals || allDivisable);
480        } 
481
482        function isDivisible(n, divisor) {
483            return (Math.floor(n / divisor) == n / divisor);
484        }
485
486        var requestFrame = (function () {
487              return  window.requestAnimationFrame       || 
488                      window.webkitRequestAnimationFrame || 
489                      function (callback, element, delay) {
490                          window.setTimeout(callback, delay || (1000/60));
491                      };
492        })();
493
494
495        /***********************************************
496         * PULSE
497         ***********************************************/
498         
499        /**
500         * Viscous fluid with a pulse for part and decay for the rest.
501         * - Applies a fixed force over an interval (a damped acceleration), and
502         * - Lets the exponential bleed away the velocity over a longer interval
503         * - Michael Herf, http://stereopsis.com/stopping/
504         */
505        function pulse_(x) {
506            var val, start, expx;
507            // test
508            x = x * options.pulseScale;
509            if (x < 1) { // acceleartion
510                val = x - (1 - Math.exp(-x));
511            } else {     // tail
512                // the previous animation ended here:
513                start = Math.exp(-1);
514                // simple viscous drag
515                x -= 1;
516                expx = 1 - Math.exp(-x);
517                val = start + (expx * (1 - start));
518            }
519            return val * options.pulseNormalize;
520        }
521
522        function pulse(x) {
523            if (x >= 1) return 1;
524            if (x <= 0) return 0;
525
526            if (options.pulseNormalize == 1) {
527                options.pulseNormalize /= pulse_(1);
528            }
529            return pulse_(x);
530        }
531
532        var isChrome = /chrome/i.test(window.navigator.userAgent);
533        var isMouseWheelSupported = 'onmousewheel' in document; 
534
535        if (isMouseWheelSupported) {
536          addEvent("mousedown", mousedown);
537          addEvent("mousewheel", wheel);
538          addEvent("load", init);
539        };
540
541    })();
542}
543
544if(browser() === 'ie') {
545    /**
546     * Created by IntelliJ IDEA.
547     *
548     * User: phil
549     * Date: 15/11/12
550     * Time: 11:04 AM
551     *
552     */
553    (function($) {
554
555      var self = this,
556        container, running = false,
557        currentY = 0,
558        targetY = 0,
559        oldY = 0,
560        maxScrollTop = 0,
561        minScrollTop, direction, onRenderCallback = null,
562        fricton = 0.7, // higher value for slower deceleration
563        vy = 0,
564        stepAmt = 5,
565        minMovement = 0.1,
566        ts = 0.1;
567
568      var updateScrollTarget = function(amt) {
569        targetY += amt;
570        vy += (targetY - oldY) * stepAmt;
571
572        oldY = targetY;
573      }
574      var render = function() {
575        if (vy < -(minMovement) || vy > minMovement) {
576
577          currentY = (currentY + vy);
578          if (currentY > maxScrollTop) {
579            currentY = vy = 0;
580          } else if (currentY < minScrollTop) {
581            vy = 0;
582            currentY = minScrollTop;
583          }
584
585          container.scrollTop(-currentY);
586
587          vy *= fricton;
588
589          if (onRenderCallback) {
590            onRenderCallback();
591          }
592        }
593      }
594      var animateLoop = function() {
595        if (!running) return;
596        requestAnimFrame(animateLoop);
597        render();
598        //log("45","animateLoop","animateLoop", "",stop);
599      }
600      var onWheel = function(e) {
601        e.preventDefault();
602        var evt = e.originalEvent;
603
604        var delta = evt.detail ? evt.detail * -1 : evt.wheelDelta / 40;
605        var dir = delta < 0 ? -1 : 1;
606        if (dir != direction) {
607          vy = 0;
608          direction = dir;
609        }
610
611        //reset currentY in case non-wheel scroll has occurred (scrollbar drag, etc.)
612        currentY = -container.scrollTop();
613        updateScrollTarget(delta);
614      }
615
616      /*
617       * http://paulirish.com/2011/requestanimationframe-for-smart-animating/
618       */
619      window.requestAnimFrame = (function() {
620        return window.requestAnimationFrame ||
621          window.webkitRequestAnimationFrame ||
622          window.mozRequestAnimationFrame ||
623          window.oRequestAnimationFrame ||
624          window.msRequestAnimationFrame ||
625          function(callback) {
626            window.setTimeout(callback, 1000 / 60);
627          };
628      })();
629
630      /*
631       * http://jsbin.com/iqafek/2/edit
632       */
633      var normalizeWheelDelta = function() {
634        // Keep a distribution of observed values, and scale by the
635        // 33rd percentile.
636        var distribution = [],
637          done = null,
638          scale = 30;
639        return function(n) {
640          // Zeroes don't count.
641          if (n == 0) return n;
642          // After 500 samples, we stop sampling and keep current factor.
643          if (done != null) return n * done;
644          var abs = Math.abs(n);
645          // Insert value (sorted in ascending order).
646          outer: do { // Just used for break goto
647            for (var i = 0; i < distribution.length; ++i) {
648              if (abs <= distribution[i]) {
649                distribution.splice(i, 0, abs);
650                break outer;
651              }
652            }
653            distribution.push(abs);
654          } while (false);
655          // Factor is scale divided by 33rd percentile.
656          var factor = scale / distribution[Math.floor(distribution.length / 3)];
657          if (distribution.length == 500) done = factor;
658          return n * factor;
659        };
660      }();
661
662
663      $.fn.smoothWheel = function() {
664        //  var args = [].splice.call(arguments, 0);
665        var options = jQuery.extend({}, arguments[0]);
666        return this.each(function(index, elm) {
667
668          if (!('ontouchstart' in window)) {
669            container = $(this);
670            container.bind("mousewheel", onWheel);
671            container.bind("DOMMouseScroll", onWheel);
672
673            //set target/old/current Y to match current scroll position to prevent jump to top of container
674            targetY = oldY = container.scrollTop();
675            currentY = -targetY;
676
677            minScrollTop = container.get(0).clientHeight - container.get(0).scrollHeight;
678            if (options.onRender) {
679              onRenderCallback = options.onRender;
680            }
681            if (options.remove) {
682              log("122", "smoothWheel", "remove", "");
683              running = false;
684              container.unbind("mousewheel", onWheel);
685              container.unbind("DOMMouseScroll", onWheel);
686            } else if (!running) {
687              running = true;
688              animateLoop();
689            }
690
691          }
692        });
693      };
694
695    })(jQuery);
696
697
698    (function($, window) {
699        $(window).load(function(){
700            $(window).smoothWheel()
701        });
702    })(jQuery, window);
703    
704}

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.