jQuery.fn.waterfall=function(t){function a(t){var a=i.hGap,e=i.vGap,n=t.find(i.itemSelector);return n.length&&null===a&&(a=parseInt(t.data("h-gap")),a||(a=parseInt(n.eq(0).css("margin-left"))+parseInt(n.eq(0).css("margin-right")))),n.length&&null===e&&(e=parseInt(t.data("v-gap")),e||(e=parseInt(n.eq(0).css("margin-top"))+parseInt(n.eq(0).css("margin-bottom")))),{horizontalGap:a,verticalGap:e}}function e(t){if(!t.length)return;var e=t.find(i.itemSelector);if(!e.length)return;const n=t.width(),r=e.eq(0).outerWidth(),o=Math.floor(n/r),{horizontalGap:l,verticalGap:s}=a(t),c=e.eq(0).offset().top-t.offset().top-parseInt(e.eq(0).css("margin-top"));let f=new Array(o).fill(c);e.each(function(){const t=jQuery(this),a=Math.min(...f),e=f.indexOf(a),n=e*r+l*e,i=a+(a>0?s:0);t.css({position:"absolute",left:"0",top:"0",transform:"translate3d("+n+"px,"+i+"px,0)"}).addClass("waterfall-item"),f[e]+=t.height()+s}),t.css("height",Math.max(...f)+s+"px")}var n={hGap:null,vGap:null,itemSelector:".waterfall-item",containerSelector:".waterfall-container"},i=jQuery.extend(n,t);this.each(function(){var t=jQuery(this);e(t),t.data("waterfall-init")||(t.data("waterfall-init",!0),jQuery(window).on("resize",debounce(function(){e(t)},100)),t.on("lazyloaded","img",debounce(function(){e(t)},50)),t.on("post_ajax.ed",function(){e(t)}))})};