/
overflow-color.umd.min.js
executable file
·1 lines (1 loc) · 2.62 KB
/
overflow-color.umd.min.js
1
(function(e,t){typeof exports==="object"&&typeof module!=="undefined"?module.exports=t():typeof define==="function"&&define.amd?define(t):e.overflowColor=t()})(this,function(){"use strict";var a="data-oc";var u=void 0;var l=void 0;var d=void 0;var r=void 0;var o=void 0;var n=false;var t=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(e){window.setTimeout(e,1e3/60)}}();var i=function e(t){if(d!==t){d=t;var o="html { background: "+d+"; }";if(!r){r=document.createElement("style");var n=document.head||document.getElementsByTagName("head")[0];n.appendChild(r)}if(r.styleSheet){r.styleSheet.cssText=o}else{r.innerHTML=o}}};var c=function e(){o=window.scrollY;if(!n&&(u||l)){t(function(){var e=document.body.scrollHeight;var t=window.innerHeight;if(e===t){i(l)}else{i(t-e+2*o<0?u:l)}n=false});n=true}};var s=function e(){u=null;l=null;var t=document.querySelector("["+a+"]");if(t){var o=t.getAttribute(a).split(",");if(o.length>1){u=o[0];l=o[1]}else if(o.length===1){u=l=o[0]}}else{var n=document.querySelector("["+a+"-top]");var d=document.querySelector("["+a+"-bottom]");if(n){u=n.getAttribute(a+"-top")}if(d){l=d.getAttribute(a+"-bottom")}}if(!u&&l){u=l}else if(u&&!l){l=u}var r=window.getComputedStyle(document.body,null);var i=r.getPropertyValue("background");if(i===""||r.getPropertyValue("background-color")==="rgba(0, 0, 0, 0)"&&i.substring(21,17)==="none"){i="white"}document.body.style.background="transparent";c()};var e=function e(){var t=window.getComputedStyle(document.body,null);var o=t.getPropertyValue("background");if(o===""||t.getPropertyValue("background-color")==="rgba(0, 0, 0, 0)"&&o.substring(21,17)==="none"){o="white"}document.body.style.background="transparent";var n=document.createElement("div");n.setAttribute(a+"-wrap","");n.style.background=o;for(var d=document.body.childNodes.length-1;d>0;d--){var r=document.body.childNodes[d];if(typeof r.getAttribute!=="function"||r.getAttribute(a+"-outside")===null){n.insertBefore(r,n.childNodes[0])}}if(document.body.childNodes.length){document.body.insertBefore(n,document.body.childNodes[0])}else{document.body.appendChild(n)}s();if(typeof window.addEventListener!=="undefined"){window.addEventListener("scroll",c,{passive:true});window.addEventListener("resize",c,{passive:true})}else{window.attachEvent("scroll",c);window.attachEvent("resize",c)}};if(["interactive","complete","loaded"].indexOf(document.readyState)!==-1){e()}else if(typeof document.addEventListener!=="undefined"){document.addEventListener("DOMContentLoaded",e,false)}else{document.attachEvent("onreadystatechange",e)}window.updateOverflowColor=s;return s});