HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/komma.pro/resources/assets/js/site/viewport/viewportHandler.js
/* ==========================================================================
 Handles elements that need animation when entering the viewport
 ========================================================================== */

var ViewportHandler = {

    init : function()
    {
        // Fire once on init
        this.handle();
        // Handle on scroll
        $(window).on('scroll', this.handle);
    },

    handle : function()
    {
        // For every element with data-in-viewport with haven't got a class show
        $('*[data-in-viewport]:not(.show)').each(function()
        {
            if(ViewportHandler.isInViewport($(this),1))
            {
                // Execute the function written in 'data-in-viewport'
                executeFunctionByName($(this).data('in-viewport'), window, $(this));
            }
        })
    },

    /**
     * Return if the element is in the viewport
     *
     * @param el
     * @param partial
     * @returns {boolean}
     */
    isInViewport : function(el, partial) {

        // For jQuery we need to get the first key
        el = el[0];

        // Get bounding rectangle
        var rect = el.getBoundingClientRect();
        var parentRect = {top: 0, left: 0, bottom: $(window).height(), right: $(window).width()};

        // Partially in viewport
        if (partial) {
            return (
                rect.left >= parentRect.left &&
                rect.right <= parentRect.right &&
                (
                    (rect.top >= parentRect.top && rect.top <= parentRect.bottom) ||
                    (rect.bottom >= parentRect.top && rect.bottom <= parentRect.bottom)
                )
            );
        }
        // Fully in viewport
        else {
            return (
                rect.top >= parentRect.top &&
                rect.left >= parentRect.left &&
                rect.bottom <= parentRect.bottom &&
                rect.right <= parentRect.right
            );
        }
    }
};