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* Minified by jsDelivr using Terser v5.39.0.\n * Original file: /gh/kayleegao/personal-website@master/js/img-comparsion.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","jQuery(document).ready(function($){\n    var dragging = false,\n        scrolling = false,\n        resizing = false;\n    //cache jQuery objects\n    var imageComparisonContainers = $('.cd-image-container');\n    //check if the .cd-image-container is in the viewport \n    //if yes, animate it\n    checkPosition(imageComparisonContainers);\n    $(window).on('scroll', function(){\n        if( !scrolling) {\n            scrolling =  true;\n            ( !window.requestAnimationFrame )\n                ? setTimeout(function(){checkPosition(imageComparisonContainers);}, 100)\n                : requestAnimationFrame(function(){checkPosition(imageComparisonContainers);});\n        }\n    });\n    \n    //make the .cd-handle element draggable and modify .cd-resize-img width according to its position\n    imageComparisonContainers.each(function(){\n        var actual = $(this);\n        drags(actual.find('.cd-handle'), actual.find('.cd-resize-img'), actual, actual.find('.cd-image-label[data-type=\"original\"]'), actual.find('.cd-image-label[data-type=\"modified\"]'));\n    });\n\n    //upadate images label visibility\n    $(window).on('resize', function(){\n        if( !resizing) {\n            resizing =  true;\n            ( !window.requestAnimationFrame )\n                ? setTimeout(function(){checkLabel(imageComparisonContainers);}, 100)\n                : requestAnimationFrame(function(){checkLabel(imageComparisonContainers);});\n        }\n    });\n\n    function checkPosition(container) {\n        container.each(function(){\n            var actualContainer = $(this);\n            if( $(window).scrollTop() + $(window).height()*0.5 > actualContainer.offset().top) {\n                actualContainer.addClass('is-visible');\n            }\n        });\n\n        scrolling = false;\n    }\n\n    function checkLabel(container) {\n        container.each(function(){\n            var actual = $(this);\n            updateLabel(actual.find('.cd-image-label[data-type=\"modified\"]'), actual.find('.cd-resize-img'), 'left');\n            updateLabel(actual.find('.cd-image-label[data-type=\"original\"]'), actual.find('.cd-resize-img'), 'right');\n        });\n\n        resizing = false;\n    }\n\n    //draggable funtionality - credits to http://css-tricks.com/snippets/jquery/draggable-without-jquery-ui/\n    function drags(dragElement, resizeElement, container, labelContainer, labelResizeElement) {\n        dragElement.on(\"mousedown vmousedown\", function(e) {\n            dragElement.addClass('draggable');\n            resizeElement.addClass('resizable');\n\n            var dragWidth = dragElement.outerWidth(),\n                xPosition = dragElement.offset().left + dragWidth - e.pageX,\n                containerOffset = container.offset().left,\n                containerWidth = container.outerWidth(),\n                minLeft = containerOffset + 10,\n                maxLeft = containerOffset + containerWidth - dragWidth - 10;\n            \n            dragElement.parents().on(\"mousemove vmousemove\", function(e) {\n                if( !dragging) {\n                    dragging =  true;\n                    ( !window.requestAnimationFrame )\n                        ? setTimeout(function(){animateDraggedHandle(e, xPosition, dragWidth, minLeft, maxLeft, containerOffset, containerWidth, resizeElement, labelContainer, labelResizeElement);}, 100)\n                        : requestAnimationFrame(function(){animateDraggedHandle(e, xPosition, dragWidth, minLeft, maxLeft, containerOffset, containerWidth, resizeElement, labelContainer, labelResizeElement);});\n                }\n            }).on(\"mouseup vmouseup\", function(e){\n                dragElement.removeClass('draggable');\n                resizeElement.removeClass('resizable');\n            });\n            e.preventDefault();\n        }).on(\"mouseup vmouseup\", function(e) {\n            dragElement.removeClass('draggable');\n            resizeElement.removeClass('resizable');\n        });\n    }\n\n    function animateDraggedHandle(e, xPosition, dragWidth, minLeft, maxLeft, containerOffset, containerWidth, resizeElement, labelContainer, labelResizeElement) {\n        var leftValue = e.pageX + xPosition - dragWidth;   \n        //constrain the draggable element to move inside his container\n        if(leftValue < minLeft ) {\n            leftValue = minLeft;\n        } else if ( leftValue > maxLeft) {\n            leftValue = maxLeft;\n        }\n\n        var widthValue = (leftValue + dragWidth/2 - containerOffset)*100/containerWidth+'%';\n        \n        $('.draggable').css('left', widthValue).on(\"mouseup vmouseup\", function() {\n            $(this).removeClass('draggable');\n            resizeElement.removeClass('resizable');\n        });\n\n        $('.resizable').css('width', widthValue); \n\n        updateLabel(labelResizeElement, resizeElement, 'left');\n        updateLabel(labelContainer, resizeElement, 'right');\n        dragging =  false;\n    }\n\n    function updateLabel(label, resizeElement, position) {\n        if(position == 'left') {\n            ( label.offset().left + label.outerWidth() < resizeElement.offset().left + resizeElement.outerWidth() ) ? label.removeClass('is-hidden') : label.addClass('is-hidden') ;\n        } else {\n            ( label.offset().left > resizeElement.offset().left + resizeElement.outerWidth() ) ? label.removeClass('is-hidden') : label.addClass('is-hidden') ;\n        }\n    }\n});"]}