-
Notifications
You must be signed in to change notification settings - Fork 0
/
simplewf.min.js
3 lines (3 loc) · 2.39 KB
/
simplewf.min.js
1
2
3
/* @author Xakiru */
/* @tool simpleWaterfall-1.0 */
(function(b){var a=function(c,d){this.element=b(c);this._init(d)};b.extend(a.prototype,{options:{colMinWidth:100,},reflow:function(){var d=this,e=d.options;var c=~~((b(window).width())/e.colMinWidth)||1;if(c==d.container.children().length){return}d.items.detach();d._ensureColumns(c)._refill();return d},add:function(d){var c=this,f=c.options,e=c.container.children();d.each(function(h,j){var g=b(j);c._getMinCol(e).append(g)});c.items=c.items.add(d);return c},addAjax:function(d){var c=this;b.ajax({url:d.url,beforeSend:d.before,success:function(e){e=e.replace(/ /g," ");e=e.replace(/'|"/g,"'");e=e.replace(/\r|\n/g,"");e=e.replace(/^\s+|\s+$/g,"");c.add(b(e));d.after()}})},_init:function(d){var c=this,e=c.options=b.extend({},c.options,d);c.container=c.element;c.items=c.container.children();c.items.each(function(){if(!b(this).has("simplewf-item")){b(this).addClass("simplewf-item")}});c.items.detach();e.colMinWidth=parseInt(c.items.css("min-width"))||e.colMinWidth;c.reflow()},_ensureColumns:function(d){var c=this,f=c.options;d=d||1,columns=c.container.children();if(columns.length<d){for(var e=0;e<d-columns.length;e++){c.container.append(c._columnTpl())}}else{if(columns.length>d){columns.slice(-columns.length+d).remove()}}columns=c.container.children();columns.css({width:~~(100/columns.length)+"%",display:"inline-block","vertical-align":"top"});return c},_columnTpl:function(){return'<div class="simplewf-column"></div>'},_refill:function(){var c=this,d=c.options;c.items.each(function(f,g){var e=g.getAttribute("data-column");if(e){switch(e){case"left":case"first":c.container.children().first().append(b(g));break;case"right":case"last":c.container.children().last().append(b(g));break;default:c.container.children().eq(Math.min(e,c.container.children().length)).append(b(g))}}else{c._getMinCol(c.container.children()).append(b(g))}});return c},_getMinCol:function(e){var d=Infinity,c=e.first(),f=0;e.each(function(g,i){var k=b(i);var j=k.height();if(j<d){d=j;f=g}});return e.eq(f)},});b.fn.simplewf=function(c){return b(this).each(function(d,e){if(!b(e).data("simplewf")){b(e).data("simplewf",new a(e,c))}})};b(function(){b(".simplewf-item").each(function(f,g){var d=b(g),c={};if(d.data("colMinWidth")!=undefined){c.colMinWidth=d.data("colMinWidth")}if(d.data("defaultContainerWidth")!=undefined){c.defaultContainerWidth=d.data("defaultContainerWidth")}d.simplewf(c)})})})(jQuery);