/*! jQuery Wookmark plugin 0.5 @name jquery.wookmark.js @author Christoph Ono (chri@sto.ph or @gbks) @version 0.5 @date 3/19/2012 @category jQuery plugin @copyright (c) 2009-2012 Christoph Ono (www.wookmark.com) @license Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license. */ $.fn.wookmark = function(options) { if(!this.wookmarkOptions) { this.wookmarkOptions = $.extend( { container: $('body'), offset: 2, autoResize: false, itemWidth: $(this[0]).outerWidth(), resizeDelay: 50 }, options); } else if(options) { this.wookmarkOptions = $.extend(this.wookmarkOptions, options); } // Layout variables. if(!this.wookmarkColumns) { this.wookmarkColumns = null; this.wookmarkContainerWidth = null; } // Main layout function. this.wookmarkLayout = function() { // Calculate basic layout parameters. var columnWidth = this.wookmarkOptions.itemWidth + this.wookmarkOptions.offset; var containerWidth = this.wookmarkOptions.container.width(); var columns = Math.floor((containerWidth+this.wookmarkOptions.offset)/columnWidth); var offset = Math.round((containerWidth - (columns*columnWidth-this.wookmarkOptions.offset))/2); // If container and column count hasn't changed, we can only update the columns. var bottom = 0; if(this.wookmarkColumns != null && this.wookmarkColumns.length == columns) { bottom = this.wookmarkLayoutColumns(columnWidth, offset); } else { bottom = this.wookmarkLayoutFull(columnWidth, columns, offset); } // Set container height to height of the grid. this.wookmarkOptions.container.css('height', bottom+'px'); }; /** * Perform a full layout update. */ this.wookmarkLayoutFull = function(columnWidth, columns, offset) { // Prepare Array to store height of columns. var heights = []; while(heights.length < columns) { heights.push(0); } // Store column data. this.wookmarkColumns = []; while(this.wookmarkColumns.length < columns) { this.wookmarkColumns.push([]); } // Loop over items. var item, top, left, i=0, k=0, length=this.length, shortest=null, shortestIndex=null, bottom = 0; for(; i