Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added comment + minimized version

  • Loading branch information...
commit d834cc3e5f5ebb82123a93cb14c26f93d53dc34e 1 parent ec1f38c
@archiloque authored
Showing with 21 additions and 2 deletions.
  1. +3 −0  compact.sh
  2. +10 −2 jquery.compactWall.js
  3. +8 −0 jquery.compactWall.min.js
View
3  compact.sh
@@ -0,0 +1,3 @@
+# uglify jquery.compactWall.js to jquery.compactWall.min.js
+# requires UglifyJS from https://github.com/mishoo/UglifyJS
+uglifyjs jquery.compactWall.js > jquery.compactWall.min.js
View
12 jquery.compactWall.js
@@ -1,5 +1,5 @@
/**
- * jQuery CompactWall v2.1.04
+ * jQuery CompactWall v0.0.1
* A jQuery plugin to organizes blocks in a compact way.
* http://github.com/archiloque/compact-wall
*
@@ -176,7 +176,9 @@
return bestFitInternal(blocksList, position, Number.POSITIVE_INFINITY);
};
-
+ /**
+ * Internal version of bestFit.
+ */
var bestFitInternal = function (remainingBlocks, position, maxHeight) {
if (remainingBlocks.length == 1) {
return bestFitLastBlock(remainingBlocks[0], position, maxHeight);
@@ -194,6 +196,9 @@
}
};
+ /**
+ * Find the best fitting position when adding the last block.
+ */
var bestFitLastBlock = function (remainingBlock, position, maxHeight) {
var bestPosition = null;
var minHeight = maxHeight;
@@ -206,6 +211,9 @@
return bestPosition;
};
+ /**
+ * Find the best fitting position when adding a block to a position
+ */
var nextFitNextBlock = function (remainingBlocks, block, index, position, maxHeight) {
var bestPosition = null;
var minHeight = maxHeight;
View
8 jquery.compactWall.min.js
@@ -0,0 +1,8 @@
+/**
+ * jQuery CompactWall v0.0.1
+ * A jQuery plugin to organizes blocks in a compact way.
+ * http://github.com/archiloque/compact-wall
+ *
+ * Licensed under the MIT license.
+ * Copyright 2012 Julien Kirch
+ */(function(a){a.fn.compactWall=function(b){var c=function(b,d,e,f){this.positionedBlocks=b,this.height=e,this.slots=d,this.addBlock=function(g,h,i){e<h&&a.each(d,function(a,j){if(j.top+g.height<h&&j.availableWidth>=g.width&&j.availableHeight>=g.height){var k={top:j.top,left:j.left,block:g},l=[];j.availableHeight==g.height?j.availableWidth==g.width?l=d.slice(0,a).concat(d.slice(a+1)):d.length>a+1&&d[a+1].left==j.left+g.width&&d[a+1].availableWidth==j.availableWidth-g.width?l=d.slice(0,a).concat([{top:d[a+1].top,left:d[a+1].left,availableWidth:d[a+1].availableWidth,availableHeight:d[a+1].availableHeight+g.height}]).concat(d.slice(a+2)):l=d.slice(0,a).concat([{top:j.top,left:j.left+g.width,availableWidth:j.availableWidth-g.width,availableHeight:g.height}]).concat(d.slice(a+1)):g.width==j.availableWidth?l=d.slice(0,a).concat([{top:j.top+g.height,left:j.left,availableWidth:j.availableWidth,availableHeight:j.availableHeight-g.height}]).concat(d.slice(a+1)):d.length>a+1&&d[a+1].left==j.left+g.width&&d[a+1].availableWidth==j.availableWidth-g.width?a==0?l=[{top:j.top+g.height,left:0,availableWidth:j.availableWidth,availableHeight:Number.Infinity},{top:d[a+1].top,left:d[a+1].left,availableWidth:d[a+1].availableWidth,availableHeight:d[a+1].availableHeight+g.height}].concat(d.slice(a+2)):l=d.slice(0,a).concat([{top:d[a+1].top,left:d[a+1].left,availableWidth:d[a+1].availableWidth,availableHeight:d[a+1].availableHeight+g.height}]).concat(d.slice(a+2)):l=d.slice(0,a).concat([{top:j.top+g.height,left:j.left,availableWidth:j.availableWidth,availableHeight:j.availableHeight-g.height},{top:j.top,left:j.left+g.width,availableWidth:j.availableWidth-g.width,availableHeight:g.height}]).concat(d.slice(a+1)),i(new c(b.concat([k]),l,Math.max(e,j.top+g.height),f))}})}},d=function(a,b){var d={top:0,left:0,availableWidth:b,availableHeight:Number.POSITIVE_INFINITY},f=new c([],[d],0,b);return e(a,f,Number.POSITIVE_INFINITY)},e=function(b,c,d){if(b.length==1)return f(b[0],c,d);var e=null,h=d;return a.each(b,function(a,f){var i=g(b,f,a,c,d);i&&i.height<h&&(h=i.height,e=i)}),e},f=function(a,b,c){var d=null,e=c;return b.addBlock(a,e,function(a){a.height<e&&(e=a.height,d=a)}),d},g=function(a,b,c,d,f){var g=null,h=f;return d.addBlock(b,h,function(b){var d=e(a.slice(0,c).concat(a.slice(c+1)),b,h);d&&d.height<h&&(h=d.height,g=d)}),g};return this.each(function(c,e){var f=a.map(b,function(b){var c=a(b);return{width:c.outerWidth(!0),height:c.outerHeight(!0),block:b}}),g=d(f,a(e).innerWidth());g&&(a.each(g.positionedBlocks,function(b,c){a(c.block.block).css("position","absolute").css("top",c.top).css("left",c.left)}),a(e).css("position","relative").css("height",g.height))})}})(jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.