From b1e4f6c60f072f581de33835c13fcd7f34b812a1 Mon Sep 17 00:00:00 2001 From: fearenales Date: Mon, 28 Jul 2014 12:25:06 -0300 Subject: [PATCH] Upgrading Wookmark to v1.4.8 --- vendor/assets/javascripts/jquery.wookmark.js | 160 ++++++++++++------ .../assets/javascripts/jquery.wookmark.min.js | 8 +- 2 files changed, 111 insertions(+), 57 deletions(-) diff --git a/vendor/assets/javascripts/jquery.wookmark.js b/vendor/assets/javascripts/jquery.wookmark.js index 656cec5..e373257 100644 --- a/vendor/assets/javascripts/jquery.wookmark.js +++ b/vendor/assets/javascripts/jquery.wookmark.js @@ -3,10 +3,10 @@ @name jquery.wookmark.js @author Christoph Ono (chri@sto.ph or @gbks) @author Sebastian Helzle (sebastian@helzle.net or @sebobo) - @version 1.4.3 - @date 8/25/2013 + @version 1.4.8 + @date 07/08/2013 @category jQuery plugin - @copyright (c) 2009-2013 Christoph Ono (www.wookmark.com) + @copyright (c) 2009-2014 Christoph Ono (www.wookmark.com) @license Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license. */ (function (factory) { @@ -15,7 +15,6 @@ else factory(jQuery); }(function ($) { - var Wookmark, defaultOptions, __bind; __bind = function(fn, me) { @@ -30,17 +29,38 @@ autoResize: false, comparator: null, container: $('body'), + direction: undefined, ignoreInactiveItems: true, itemWidth: 0, fillEmptySpace: false, flexibleWidth: 0, - direction: undefined, offset: 2, - onLayoutChanged: undefined, outerOffset: 0, - resizeDelay: 50 + onLayoutChanged: undefined, + possibleFilters: [], + resizeDelay: 50, + verticalOffset: undefined }; + // Function for executing css writes to dom on the next animation frame if supported + var executeNextFrame = window.requestAnimationFrame || function(callback) {callback();}, + $window = $(window); + + function bulkUpdateCSS(data) { + executeNextFrame(function() { + var i, item; + for (i = 0; i < data.length; i++) { + item = data[i]; + item.obj.css(item.css); + } + }); + } + + function cleanFilterName(filterName) { + return $.trim(filterName).toLowerCase(); + } + + // Main wookmark plugin class Wookmark = (function() { function Wookmark(handler, options) { @@ -53,6 +73,8 @@ $.extend(true, this, defaultOptions, options); + this.verticalOffset = this.verticalOffset || this.offset; + // Bind instance methods this.update = __bind(this.update, this); this.onResize = __bind(this.onResize, this); @@ -66,36 +88,49 @@ this.getActiveItems = __bind(this.getActiveItems, this); this.refreshPlaceholders = __bind(this.refreshPlaceholders, this); this.sortElements = __bind(this.sortElements, this); + this.updateFilterClasses = __bind(this.updateFilterClasses, this); + + // Initial update of the filter classes + this.updateFilterClasses(); + + // Listen to resize event if requested. + if (this.autoResize) + $window.bind('resize.wookmark', this.onResize); + this.container.bind('refreshWookmark', this.onRefresh); + } + + Wookmark.prototype.updateFilterClasses = function() { // Collect filter data - var i = 0, j = 0, filterClasses = {}, itemFilterClasses, $item, filterClass; + var i = 0, j = 0, k = 0, filterClasses = {}, itemFilterClasses, + $item, filterClass, possibleFilters = this.possibleFilters, possibleFilter; - for (; i < handler.length; i++) { - $item = handler.eq(i); + for (; i < this.handler.length; i++) { + $item = this.handler.eq(i); - // Read filter classes + // Read filter classes and globally store each filter class as object and the fitting items in the array itemFilterClasses = $item.data('filterClass'); - - // Globally store each filter class as object and the fitting items in the array if (typeof itemFilterClasses == 'object' && itemFilterClasses.length > 0) { for (j = 0; j < itemFilterClasses.length; j++) { - filterClass = $.trim(itemFilterClasses[j]).toLowerCase(); + filterClass = cleanFilterName(itemFilterClasses[j]); - if (!(filterClass in filterClasses)) { + if (typeof(filterClasses[filterClass]) === 'undefined') { filterClasses[filterClass] = []; } filterClasses[filterClass].push($item[0]); } } } - this.filterClasses = filterClasses; - // Listen to resize event if requested. - if (this.autoResize) - $(window).bind('resize.wookmark', this.onResize); + for (; k < possibleFilters.length; k++) { + possibleFilter = cleanFilterName(possibleFilters[k]); + if (!(possibleFilter in filterClasses)) { + filterClasses[possibleFilter] = []; + } + } - this.container.bind('refreshWookmark', this.onRefresh); - } + this.filterClasses = filterClasses; + }; // Method for updating the plugins options Wookmark.prototype.update = function(options) { @@ -121,17 +156,18 @@ * @param filters array of string * @param mode 'or' or 'and' */ - Wookmark.prototype.filter = function(filters, mode) { + Wookmark.prototype.filter = function(filters, mode, dryRun) { var activeFilters = [], activeFiltersLength, activeItems = $(), i, j, k, filter; filters = filters || []; mode = mode || 'or'; + dryRun = dryRun || false; if (filters.length) { // Collect active filters for (i = 0; i < filters.length; i++) { - filter = $.trim(filters[i].toLowerCase()); + filter = cleanFilterName(filters[i]); if (filter in this.filterClasses) { activeFilters.push(this.filterClasses[filter]); } @@ -157,6 +193,7 @@ } // Iterate over shortest filter and find elements in other filter classes + shortestFilter = shortestFilter || []; for (i = 0; i < shortestFilter.length; i++) { currentItem = shortestFilter[i]; itemValid = true; @@ -176,18 +213,21 @@ } } // Hide inactive items - this.handler.not(activeItems).addClass('inactive'); + if (!dryRun) + this.handler.not(activeItems).addClass('inactive'); } else { // Show all items if no filter is selected activeItems = this.handler; } // Show active items - activeItems.removeClass('inactive'); - - // Unset columns and refresh grid for a full layout - this.columns = null; - this.layout(); + if (!dryRun) { + activeItems.removeClass('inactive'); + // Unset columns and refresh grid for a full layout + this.columns = null; + this.layout(); + } + return activeItems; }; /** @@ -205,7 +245,7 @@ this.placeholders.push($placeholder); } - innerOffset = this.offset + parseInt(this.placeholders[0].css('borderWidth'), 10) * 2; + innerOffset = this.offset + parseInt(this.placeholders[0].css('borderLeftWidth'), 10) * 2; for (i = 0; i < this.placeholders.length; i++) { $placeholder = this.placeholders[i]; @@ -216,7 +256,7 @@ } else { $lastColumnItem = column[column.length - 1]; if (!$lastColumnItem) continue; - top = $lastColumnItem.data('wookmark-top') + $lastColumnItem.data('wookmark-height') + this.offset; + top = $lastColumnItem.data('wookmark-top') + $lastColumnItem.data('wookmark-height') + this.verticalOffset; height = containerHeight - top - innerOffset; $placeholder.css({ @@ -256,7 +296,11 @@ flexibleWidth = parseFloat(flexibleWidth) / 100 * innerWidth; } - var columns = ~~(0.5 + (innerWidth + this.offset) / (flexibleWidth + this.offset)), + // Find highest column count + var paddedInnerWidth = (innerWidth + this.offset), + flexibleColumns = ~~(0.5 + paddedInnerWidth / (flexibleWidth + this.offset)), + fixedColumns = ~~(paddedInnerWidth / (itemWidth + this.offset)), + columns = Math.max(flexibleColumns, fixedColumns), columnWidth = Math.min(flexibleWidth, ~~((innerWidth - (columns - 1) * this.offset) / columns)); itemWidth = Math.max(itemWidth, columnWidth); @@ -284,12 +328,13 @@ $item; // Cache item height - if (this.itemHeightsDirty) { + if (this.itemHeightsDirty || !this.container.data('itemHeightsInitialized')) { for (; i < activeItemsLength; i++) { $item = activeItems.eq(i); $item.data('wookmark-height', $item.outerHeight()); } this.itemHeightsDirty = false; + this.container.data('itemHeightsInitialized', true); } // Use less columns if there are to few items @@ -340,8 +385,7 @@ activeItems = $.makeArray(this.getActiveItems()), length = activeItems.length, shortest = null, shortestIndex = null, - itemCSS = {position: 'absolute'}, - sideOffset, heights = [], + sideOffset, heights = [], itemBulkCSS = [], leftAligned = this.align == 'left' ? true : false; this.columns = []; @@ -368,6 +412,7 @@ shortestIndex = k; } } + $item.data('wookmark-top', shortest); // stick to left side if alignment is left and this is the first column sideOffset = offset; @@ -375,15 +420,21 @@ sideOffset += shortestIndex * columnWidth; // Position the item. - itemCSS[this.direction] = sideOffset; - itemCSS.top = shortest; - $item.css(itemCSS).data('wookmark-top', shortest); + (itemBulkCSS[i] = { + obj: $item, + css: { + position: 'absolute', + top: shortest + } + }).css[this.direction] = sideOffset; // Update column height and store item in shortest column - heights[shortestIndex] += $item.data('wookmark-height') + this.offset; + heights[shortestIndex] += $item.data('wookmark-height') + this.verticalOffset; this.columns[shortestIndex].push($item); } + bulkUpdateCSS(itemBulkCSS); + // Return longest column return Math.max.apply(Math, heights); }; @@ -393,9 +444,9 @@ * existing column assignments. */ Wookmark.prototype.layoutColumns = function(columnWidth, offset) { - var heights = [], - i = 0, k = 0, currentHeight, - column, $item, itemCSS, sideOffset; + var heights = [], itemBulkCSS = [], + i = 0, k = 0, j = 0, currentHeight, + column, $item, itemData, sideOffset; for (; i < this.columns.length; i++) { heights.push(this.outerOffset); @@ -403,31 +454,34 @@ sideOffset = i * columnWidth + offset; currentHeight = heights[i]; - for (k = 0; k < column.length; k++) { - $item = column[k]; - itemCSS = { - top: currentHeight - }; - itemCSS[this.direction] = sideOffset; - - $item.css(itemCSS).data('wookmark-top', currentHeight); + for (k = 0; k < column.length; k++, j++) { + $item = column[k].data('wookmark-top', currentHeight); + (itemBulkCSS[j] = { + obj: $item, + css: { + top: currentHeight + } + }).css[this.direction] = sideOffset; - currentHeight += $item.data('wookmark-height') + this.offset; + currentHeight += $item.data('wookmark-height') + this.verticalOffset; } heights[i] = currentHeight; } + bulkUpdateCSS(itemBulkCSS); + // Return longest column return Math.max.apply(Math, heights); }; /** - * Clear event listeners and time outs. + * Clear event listeners and time outs and the instance itself */ Wookmark.prototype.clear = function() { clearTimeout(this.resizeTimer); - $(window).unbind('resize.wookmark', this.onResize); + $window.unbind('resize.wookmark', this.onResize); this.container.unbind('refreshWookmark', this.onRefresh); + this.handler.wookmarkInstance = null; }; return Wookmark; diff --git a/vendor/assets/javascripts/jquery.wookmark.min.js b/vendor/assets/javascripts/jquery.wookmark.min.js index cab6882..e4f8512 100644 --- a/vendor/assets/javascripts/jquery.wookmark.min.js +++ b/vendor/assets/javascripts/jquery.wookmark.min.js @@ -3,10 +3,10 @@ jQuery wookmark plugin @name jquery.wookmark.js @author Christoph Ono (chri@sto.ph or @gbks) @author Sebastian Helzle (sebastian@helzle.net or @sebobo) -@version 1.4.3 -@date 08/25/2013 +@version 1.4.8 +@date 07/08/2014 @category jQuery plugin -@copyright (c) 2009-2013 Christoph Ono (www.wookmark.com) +@copyright (c) 2009-2014 Christoph Ono (www.wookmark.com) @license Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license. */ -(function(t){"function"==typeof define&&define.amd?define(["jquery"],t):t(jQuery)})(function(t){var i,e,s;s=function(t,i){return function(){return t.apply(i,arguments)}},e={align:"center",autoResize:!1,comparator:null,container:t("body"),ignoreInactiveItems:!0,itemWidth:0,fillEmptySpace:!1,flexibleWidth:0,direction:void 0,offset:2,onLayoutChanged:void 0,outerOffset:0,resizeDelay:50},i=function(){function i(i,h){this.handler=i,this.columns=this.containerWidth=this.resizeTimer=null,this.activeItemCount=0,this.itemHeightsDirty=!0,this.placeholders=[],t.extend(!0,this,e,h),this.update=s(this.update,this),this.onResize=s(this.onResize,this),this.onRefresh=s(this.onRefresh,this),this.getItemWidth=s(this.getItemWidth,this),this.layout=s(this.layout,this),this.layoutFull=s(this.layoutFull,this),this.layoutColumns=s(this.layoutColumns,this),this.filter=s(this.filter,this),this.clear=s(this.clear,this),this.getActiveItems=s(this.getActiveItems,this),this.refreshPlaceholders=s(this.refreshPlaceholders,this),this.sortElements=s(this.sortElements,this);for(var o,n,r,a=0,l=0,f={};i.length>a;a++)if(n=i.eq(a),o=n.data("filterClass"),"object"==typeof o&&o.length>0)for(l=0;o.length>l;l++)r=t.trim(o[l]).toLowerCase(),r in f||(f[r]=[]),f[r].push(n[0]);this.filterClasses=f,this.autoResize&&t(window).bind("resize.wookmark",this.onResize),this.container.bind("refreshWookmark",this.onRefresh)}return i.prototype.update=function(i){this.itemHeightsDirty=!0,t.extend(!0,this,i)},i.prototype.onResize=function(){clearTimeout(this.resizeTimer),this.itemHeightsDirty=0!==this.flexibleWidth,this.resizeTimer=setTimeout(this.layout,this.resizeDelay)},i.prototype.onRefresh=function(){this.itemHeightsDirty=!0,this.layout()},i.prototype.filter=function(i,e){var s,h,o,n,r,a=[],l=t();if(i=i||[],e=e||"or",i.length){for(h=0;i.length>h;h++)r=t.trim(i[h].toLowerCase()),r in this.filterClasses&&a.push(this.filterClasses[r]);if(s=a.length,"or"==e||1==s)for(h=0;s>h;h++)l=l.add(a[h]);else if("and"==e){var f,u,c,d=a[0],m=!0;for(h=1;s>h;h++)a[h].lengthh;h++){for(u=d[h],m=!0,o=0;a.length>o&&m;o++)if(c=a[o],d!=c){for(n=0,f=!1;c.length>n&&!f;n++)f=c[n]==u;m&=f}m&&l.push(d[h])}}this.handler.not(l).addClass("inactive")}else l=this.handler;l.removeClass("inactive"),this.columns=null,this.layout()},i.prototype.refreshPlaceholders=function(i,e){for(var s,h,o,n,r,a,l=this.placeholders.length,f=this.columns.length,u=this.container.innerHeight();f>l;l++)s=t('
').appendTo(this.container),this.placeholders.push(s);for(a=this.offset+2*parseInt(this.placeholders[0].css("borderWidth"),10),l=0;this.placeholders.length>l;l++)if(s=this.placeholders[l],o=this.columns[l],l>=f||!o[o.length-1])s.css("display","none");else{if(h=o[o.length-1],!h)continue;r=h.data("wookmark-top")+h.data("wookmark-height")+this.offset,n=u-r-a,s.css({position:"absolute",display:n>0?"block":"none",left:l*i+e,top:r,width:i-a,height:n})}},i.prototype.getActiveItems=function(){return this.ignoreInactiveItems?this.handler.not(".inactive"):this.handler},i.prototype.getItemWidth=function(){var t=this.itemWidth,i=this.container.width()-2*this.outerOffset,e=this.handler.eq(0),s=this.flexibleWidth;if(void 0===this.itemWidth||0===this.itemWidth&&!this.flexibleWidth?t=e.outerWidth():"string"==typeof this.itemWidth&&this.itemWidth.indexOf("%")>=0&&(t=parseFloat(this.itemWidth)/100*i),s){"string"==typeof s&&s.indexOf("%")>=0&&(s=parseFloat(s)/100*i);var h=~~(.5+(i+this.offset)/(s+this.offset)),o=Math.min(s,~~((i-(h-1)*this.offset)/h));t=Math.max(t,o),this.handler.css("width",t)}return t},i.prototype.layout=function(t){if(this.container.is(":visible")){var i,e=this.getItemWidth()+this.offset,s=this.container.width(),h=s-2*this.outerOffset,o=~~((h+this.offset)/e),n=0,r=0,a=0,l=this.getActiveItems(),f=l.length;if(this.itemHeightsDirty){for(;f>a;a++)i=l.eq(a),i.data("wookmark-height",i.outerHeight());this.itemHeightsDirty=!1}o=Math.max(1,Math.min(o,f)),n=this.outerOffset,"center"==this.align&&(n+=~~(.5+(h-(o*e-this.offset))>>1)),this.direction=this.direction||("right"==this.align?"right":"left"),r=t||null===this.columns||this.columns.length!=o||this.activeItemCount!=f?this.layoutFull(e,o,n):this.layoutColumns(e,n),this.activeItemCount=f,this.container.css("height",r),this.fillEmptySpace&&this.refreshPlaceholders(e,n),void 0!==this.onLayoutChanged&&"function"==typeof this.onLayoutChanged&&this.onLayoutChanged()}},i.prototype.sortElements=function(t){return"function"==typeof this.comparator?t.sort(this.comparator):t},i.prototype.layoutFull=function(i,e,s){var h,o,n=0,r=0,a=t.makeArray(this.getActiveItems()),l=a.length,f=null,u=null,c={position:"absolute"},d=[],m="left"==this.align?!0:!1;for(this.columns=[],a=this.sortElements(a);e>d.length;)d.push(this.outerOffset),this.columns.push([]);for(;l>n;n++){for(h=t(a[n]),f=d[0],u=0,r=0;e>r;r++)f>d[r]&&(f=d[r],u=r);o=s,(u>0||!m)&&(o+=u*i),c[this.direction]=o,c.top=f,h.css(c).data("wookmark-top",f),d[u]+=h.data("wookmark-height")+this.offset,this.columns[u].push(h)}return Math.max.apply(Math,d)},i.prototype.layoutColumns=function(t,i){for(var e,s,h,o,n,r=[],a=0,l=0;this.columns.length>a;a++){for(r.push(this.outerOffset),s=this.columns[a],n=a*t+i,e=r[a],l=0;s.length>l;l++)h=s[l],o={top:e},o[this.direction]=n,h.css(o).data("wookmark-top",e),e+=h.data("wookmark-height")+this.offset;r[a]=e}return Math.max.apply(Math,r)},i.prototype.clear=function(){clearTimeout(this.resizeTimer),t(window).unbind("resize.wookmark",this.onResize),this.container.unbind("refreshWookmark",this.onRefresh)},i}(),t.fn.wookmark=function(t){return this.wookmarkInstance?this.wookmarkInstance.update(t||{}):this.wookmarkInstance=new i(this,t||{}),this.wookmarkInstance.layout(!0),this.show()}}); \ No newline at end of file +(function(t){"function"==typeof define&&define.amd?define(["jquery"],t):t(jQuery)})(function(t){function i(t){n(function(){var i,e;for(i=0;t.length>i;i++)e=t[i],e.obj.css(e.css)})}function e(i){return t.trim(i).toLowerCase()}var s,h,o;o=function(t,i){return function(){return t.apply(i,arguments)}},h={align:"center",autoResize:!1,comparator:null,container:t("body"),direction:void 0,ignoreInactiveItems:!0,itemWidth:0,fillEmptySpace:!1,flexibleWidth:0,offset:2,outerOffset:0,onLayoutChanged:void 0,possibleFilters:[],resizeDelay:50,verticalOffset:void 0};var n=window.requestAnimationFrame||function(t){t()},r=t(window);s=function(){function s(i,e){this.handler=i,this.columns=this.containerWidth=this.resizeTimer=null,this.activeItemCount=0,this.itemHeightsDirty=!0,this.placeholders=[],t.extend(!0,this,h,e),this.verticalOffset=this.verticalOffset||this.offset,this.update=o(this.update,this),this.onResize=o(this.onResize,this),this.onRefresh=o(this.onRefresh,this),this.getItemWidth=o(this.getItemWidth,this),this.layout=o(this.layout,this),this.layoutFull=o(this.layoutFull,this),this.layoutColumns=o(this.layoutColumns,this),this.filter=o(this.filter,this),this.clear=o(this.clear,this),this.getActiveItems=o(this.getActiveItems,this),this.refreshPlaceholders=o(this.refreshPlaceholders,this),this.sortElements=o(this.sortElements,this),this.updateFilterClasses=o(this.updateFilterClasses,this),this.updateFilterClasses(),this.autoResize&&r.bind("resize.wookmark",this.onResize),this.container.bind("refreshWookmark",this.onRefresh)}return s.prototype.updateFilterClasses=function(){for(var t,i,s,h,o=0,n=0,r=0,a={},l=this.possibleFilters;this.handler.length>o;o++)if(i=this.handler.eq(o),t=i.data("filterClass"),"object"==typeof t&&t.length>0)for(n=0;t.length>n;n++)s=e(t[n]),a[s]===void 0&&(a[s]=[]),a[s].push(i[0]);for(;l.length>r;r++)h=e(l[r]),h in a||(a[h]=[]);this.filterClasses=a},s.prototype.update=function(i){this.itemHeightsDirty=!0,t.extend(!0,this,i)},s.prototype.onResize=function(){clearTimeout(this.resizeTimer),this.itemHeightsDirty=0!==this.flexibleWidth,this.resizeTimer=setTimeout(this.layout,this.resizeDelay)},s.prototype.onRefresh=function(){this.itemHeightsDirty=!0,this.layout()},s.prototype.filter=function(i,s,h){var o,n,r,a,l,f=[],u=t();if(i=i||[],s=s||"or",h=h||!1,i.length){for(n=0;i.length>n;n++)l=e(i[n]),l in this.filterClasses&&f.push(this.filterClasses[l]);if(o=f.length,"or"==s||1==o)for(n=0;o>n;n++)u=u.add(f[n]);else if("and"==s){var c,d,m,p=f[0],g=!0;for(n=1;o>n;n++)f[n].lengthn;n++){for(d=p[n],g=!0,r=0;f.length>r&&g;r++)if(m=f[r],p!=m){for(a=0,c=!1;m.length>a&&!c;a++)c=m[a]==d;g&=c}g&&u.push(p[n])}}h||this.handler.not(u).addClass("inactive")}else u=this.handler;return h||(u.removeClass("inactive"),this.columns=null,this.layout()),u},s.prototype.refreshPlaceholders=function(i,e){for(var s,h,o,n,r,a,l=this.placeholders.length,f=this.columns.length,u=this.container.innerHeight();f>l;l++)s=t('
').appendTo(this.container),this.placeholders.push(s);for(a=this.offset+2*parseInt(this.placeholders[0].css("borderLeftWidth"),10),l=0;this.placeholders.length>l;l++)if(s=this.placeholders[l],o=this.columns[l],l>=f||!o[o.length-1])s.css("display","none");else{if(h=o[o.length-1],!h)continue;r=h.data("wookmark-top")+h.data("wookmark-height")+this.verticalOffset,n=u-r-a,s.css({position:"absolute",display:n>0?"block":"none",left:l*i+e,top:r,width:i-a,height:n})}},s.prototype.getActiveItems=function(){return this.ignoreInactiveItems?this.handler.not(".inactive"):this.handler},s.prototype.getItemWidth=function(){var t=this.itemWidth,i=this.container.width()-2*this.outerOffset,e=this.handler.eq(0),s=this.flexibleWidth;if(void 0===this.itemWidth||0===this.itemWidth&&!this.flexibleWidth?t=e.outerWidth():"string"==typeof this.itemWidth&&this.itemWidth.indexOf("%")>=0&&(t=parseFloat(this.itemWidth)/100*i),s){"string"==typeof s&&s.indexOf("%")>=0&&(s=parseFloat(s)/100*i);var h=i+this.offset,o=~~(.5+h/(s+this.offset)),n=~~(h/(t+this.offset)),r=Math.max(o,n),a=Math.min(s,~~((i-(r-1)*this.offset)/r));t=Math.max(t,a),this.handler.css("width",t)}return t},s.prototype.layout=function(t){if(this.container.is(":visible")){var i,e=this.getItemWidth()+this.offset,s=this.container.width(),h=s-2*this.outerOffset,o=~~((h+this.offset)/e),n=0,r=0,a=0,l=this.getActiveItems(),f=l.length;if(this.itemHeightsDirty||!this.container.data("itemHeightsInitialized")){for(;f>a;a++)i=l.eq(a),i.data("wookmark-height",i.outerHeight());this.itemHeightsDirty=!1,this.container.data("itemHeightsInitialized",!0)}o=Math.max(1,Math.min(o,f)),n=this.outerOffset,"center"==this.align&&(n+=~~(.5+(h-(o*e-this.offset))>>1)),this.direction=this.direction||("right"==this.align?"right":"left"),r=t||null===this.columns||this.columns.length!=o||this.activeItemCount!=f?this.layoutFull(e,o,n):this.layoutColumns(e,n),this.activeItemCount=f,this.container.css("height",r),this.fillEmptySpace&&this.refreshPlaceholders(e,n),void 0!==this.onLayoutChanged&&"function"==typeof this.onLayoutChanged&&this.onLayoutChanged()}},s.prototype.sortElements=function(t){return"function"==typeof this.comparator?t.sort(this.comparator):t},s.prototype.layoutFull=function(e,s,h){var o,n,r=0,a=0,l=t.makeArray(this.getActiveItems()),f=l.length,u=null,c=null,d=[],m=[],p="left"==this.align?!0:!1;for(this.columns=[],l=this.sortElements(l);s>d.length;)d.push(this.outerOffset),this.columns.push([]);for(;f>r;r++){for(o=t(l[r]),u=d[0],c=0,a=0;s>a;a++)u>d[a]&&(u=d[a],c=a);o.data("wookmark-top",u),n=h,(c>0||!p)&&(n+=c*e),(m[r]={obj:o,css:{position:"absolute",top:u}}).css[this.direction]=n,d[c]+=o.data("wookmark-height")+this.verticalOffset,this.columns[c].push(o)}return i(m),Math.max.apply(Math,d)},s.prototype.layoutColumns=function(t,e){for(var s,h,o,n,r=[],a=[],l=0,f=0,u=0;this.columns.length>l;l++){for(r.push(this.outerOffset),h=this.columns[l],n=l*t+e,s=r[l],f=0;h.length>f;f++,u++)o=h[f].data("wookmark-top",s),(a[u]={obj:o,css:{top:s}}).css[this.direction]=n,s+=o.data("wookmark-height")+this.verticalOffset;r[l]=s}return i(a),Math.max.apply(Math,r)},s.prototype.clear=function(){clearTimeout(this.resizeTimer),r.unbind("resize.wookmark",this.onResize),this.container.unbind("refreshWookmark",this.onRefresh),this.handler.wookmarkInstance=null},s}(),t.fn.wookmark=function(t){return this.wookmarkInstance?this.wookmarkInstance.update(t||{}):this.wookmarkInstance=new s(this,t||{}),this.wookmarkInstance.layout(!0),this.show()}}); \ No newline at end of file