1 line
1.3 KiB
JavaScript
1 line
1.3 KiB
JavaScript
!function(a,b){"function"==typeof define&&define.amd?define("waterfall",(function(){return b})):"object"==typeof module&&module.exports?module.exports=b:a.waterfall=b}(this,(function(a){function b(a){return window.getComputedStyle(a)}function c(a,c){return parseFloat(b(c)["margin"+a])||0}function d(a){return parseFloat(a)+"px"}function f(a){return parseFloat(a.style.left)}function g(a){return parseFloat(b(a).width)}function i(a){return function(a){return parseFloat(a.style.top)}(a)+function(a){return parseFloat(b(a).height)}(a)+c("Bottom",a)}function j(a){return f(a)+g(a)+c("Right",a)}function k(a){a=a.sort((function(a,b){return i(b)-i(a)||f(b)-f(a)}))}function m(a,b,c){a.style.position="absolute",a.style.top=d(b),a.style.left=d(c)}function o(a,b){m(b,a.style.top,j(a)+c("Left",b))}function p(a,b){m(b,i(a)+c("Top",b),f(a))}function r(b,c){return j(b[c-1])+g(b[c])<=g(a)}if("string"==typeof a&&(a=document.querySelector(a)),null!=a){var s=a.children;s.length&&function(a){m(a,0,c("Left",a))}(s[0]);for(var t=1;t<s.length&&r(s,t);t++)o(s[t-1],s[t]);for(var v=new function(a){var b=a;k(b),this.add=function(a){b.push(a),k(b),b.pop()},this.min=function(){return b[b.length-1]},this.max=function(){return b[0]}}([].slice.call(s,0,t));t<s.length;t++)p(v.min(),s[t]),v.add(s[t]);!function(a,b){a.style.position="relative",a.style.height=d(i(b)+c("Bottom",b))}(a,v.max())}})); |