(function ( $ ) { $.fn.mpmansory = function ( options ) { var settings = $.extend({ childrenclass: '', breakpoints: { lg: 3, md: 3, sm: 6, xs: 12 }, distributeby: { attr: 'data-order', attrorder: 'asc', order: false, height: false }, onload: function ( items ) { return true; } }, options); array.min = function( array ){ return math.min.apply( math, array ); }; $.emptyarray = function ( array ) { for (var i = 0; i'); wrap.addclass(classstr); $(this).append(wrap); cols.push(wrap); } return cols; } $.fn.distributeitemsbyheight = function ( wrappers, items ) { /* * @params [array] {wrappers} - the array containing the columns elements * @params [array] {items} - the array containing items * @description - distribute the items through the columns - to the columns with lowest height */ var counter = 0; for (var k = 0; k 1200) { return 'lg'; } else if ($(window).width() > 992) { return 'md'; } else if ($(window).width() > 720) { return 'sm'; } else if ($(window).width() > 480) { return 'xs'; } else if ($(window).width() > 320) { return 'xs'; } else { return 'xs'; } } $.fn.distributeitemsbyorder = function ( wrappers, items ) { /* * @params [array] {wrappers} - the array containing the columns elements * @params [array] {items} - the array containing items * @description - distribute the items through the columns - to the columns with lowest height */ var counter = 0; for (var k = 0; k 1) { if (counter2 == items[i].length) counter2 = 0; wrappers[counter].append($(items[i][counter2])); counter2++; } else { wrappers[counter].append($(items[i])); } counter++; } } $.fn.apply = function ( settings, nrofcolumns, wrappers, items ) { var _this = $(this); var currentsize = _this.getcurrentcolumnsize(); var columns = nrofcolumns; //find number of columns //build the bootstrap class string var classstr = "col-lg-" + settings.breakpoints.lg + " col-md-"+settings.breakpoints.md + " col-sm-" + settings.breakpoints.sm + " col-xs-" + settings.breakpoints.xs + " " + settings.columnclasses; wrappers = $(this).initialize( columns, classstr ); //create columns'white if ( settings.distributeby.order ) { _this.distributeitemsbyorder( wrappers, items); //apply mansory } else if ( settings.distributeby.height ) { _this.distributeitemsbyheight( wrappers, items); //apply mansory } else if ( settings.distributeby.attr ) { _this.distributeitemsbyattr( wrappers, _this.orderitemsbyattr(items, settings.distributeby), settings.distributeby); } return { wrappers: wrappers, items: items }; } return this.each(function () { var _this = $(this); var currentsize = _this.getcurrentcolumnsize(); var numberofcolumns = 12 / settings.breakpoints[currentsize]; var items = _this.children( (settings.childrenclass != '' ? '.'+settings.childrenclass : 'div') ); var wrappers = new array(); var returns = _this.apply( settings, numberofcolumns, wrappers, items ); wrappers = returns.wrappers; $(window).on('resize', function ( e ) { if (_this.getcurrentcolumnsize() != currentsize ) { numberofcolumns = 12 / settings.breakpoints[_this.getcurrentcolumnsize()]; wrappers = $.emptyarray(wrappers); returns = _this.apply( settings , numberofcolumns, wrappers, items); wrappers = returns.wrappers; currentsize = _this.getcurrentcolumnsize(); } }); if (settings.hasownproperty('onload')) { //execute on load settings.onload( items ); } }); } })(jquery);