6b6ad3021b0dcb855bc7728e7e3ce51883e6e204
[roojs1] / Roo / bootstrap / LayoutMasonry.js
1 /**
2  *
3  * This is based on 
4  * http://masonry.desandro.com
5  *
6  * The idea is to render all the bricks based on vertical width...
7  *
8  * The original code extends 'outlayer' - we might need to use that....
9  * 
10  */
11
12
13 /**
14  * @class Roo.bootstrap.LayoutMasonry
15  * @extends Roo.bootstrap.Component
16  * Bootstrap Layout Masonry class
17  * 
18  * @constructor
19  * Create a new Element
20  * @param {Object} config The config object
21  */
22
23 Roo.bootstrap.LayoutMasonry = function(config){
24     
25     Roo.bootstrap.LayoutMasonry.superclass.constructor.call(this, config);
26     
27     this.bricks = [];
28     
29     Roo.bootstrap.LayoutMasonry.register(this);
30     
31     this.addEvents({
32         // raw events
33         /**
34          * @event layout
35          * Fire after layout the items
36          * @param {Roo.bootstrap.LayoutMasonry} this
37          * @param {Roo.EventObject} e
38          */
39         "layout" : true
40     });
41     
42 };
43
44 Roo.extend(Roo.bootstrap.LayoutMasonry, Roo.bootstrap.Component,  {
45     
46     /**
47      * @cfg {Boolean} isLayoutInstant = no animation?
48      */   
49     isLayoutInstant : false, // needed?
50    
51     /**
52      * @cfg {Number} boxWidth  width of the columns
53      */   
54     boxWidth : 450,
55     
56       /**
57      * @cfg {Number} boxHeight  - 0 for square, or fix it at a certian height
58      */   
59     boxHeight : 0,
60     
61     /**
62      * @cfg {Number} padWidth padding below box..
63      */   
64     padWidth : 10, 
65     
66     /**
67      * @cfg {Number} gutter gutter width..
68      */   
69     gutter : 10,
70     
71      /**
72      * @cfg {Number} maxCols maximum number of columns
73      */   
74     
75     maxCols: 0,
76     
77     /**
78      * @cfg {Boolean} isAutoInitial defalut true
79      */   
80     isAutoInitial : true, 
81     
82     containerWidth: 0,
83     
84     /**
85      * @cfg {Boolean} isHorizontal defalut false
86      */   
87     isHorizontal : false, 
88
89     currentSize : null,
90     
91     tag: 'div',
92     
93     cls: '',
94     
95     bricks: null, //CompositeElement
96     
97     cols : 1,
98     
99     _isLayoutInited : false,
100     
101 //    isAlternative : false, // only use for vertical layout...
102     
103     /**
104      * @cfg {Number} alternativePadWidth padding below box..
105      */   
106     alternativePadWidth : 50,
107     
108     selectedBrick : [],
109     
110     getAutoCreate : function(){
111         
112         var cfg = Roo.apply({}, Roo.bootstrap.LayoutMasonry.superclass.getAutoCreate.call(this));
113         
114         var cfg = {
115             tag: this.tag,
116             cls: 'blog-masonary-wrapper ' + this.cls,
117             cn : {
118                 cls : 'mas-boxes masonary'
119             }
120         };
121         
122         return cfg;
123     },
124     
125     getChildContainer: function( )
126     {
127         if (this.boxesEl) {
128             return this.boxesEl;
129         }
130         
131         this.boxesEl = this.el.select('.mas-boxes').first();
132         
133         return this.boxesEl;
134     },
135     
136     
137     initEvents : function()
138     {
139         var _this = this;
140         
141         if(this.isAutoInitial){
142             Roo.log('hook children rendered');
143             this.on('childrenrendered', function() {
144                 Roo.log('children rendered');
145                 _this.initial();
146             } ,this);
147         }
148     },
149     
150     initial : function()
151     {
152         this.selectedBrick = [];
153         
154         this.currentSize = this.el.getBox(true);
155         
156         Roo.EventManager.onWindowResize(this.resize, this); 
157
158         if(!this.isAutoInitial){
159             this.layout();
160             return;
161         }
162         
163         this.layout();
164         
165         return;
166         //this.layout.defer(500,this);
167         
168     },
169     
170     resize : function()
171     {
172         var cs = this.el.getBox(true);
173         
174         if (
175                 this.currentSize.width == cs.width && 
176                 this.currentSize.x == cs.x && 
177                 this.currentSize.height == cs.height && 
178                 this.currentSize.y == cs.y 
179         ) {
180             Roo.log("no change in with or X or Y");
181             return;
182         }
183         
184         this.currentSize = cs;
185         
186         this.layout();
187         
188     },
189     
190     layout : function()
191     {   
192         this._resetLayout();
193         
194         var isInstant = this.isLayoutInstant !== undefined ? this.isLayoutInstant : !this._isLayoutInited;
195         
196         this.layoutItems( isInstant );
197       
198         this._isLayoutInited = true;
199         
200         this.fireEvent('layout', this);
201         
202     },
203     
204     _resetLayout : function()
205     {
206         if(this.isHorizontal){
207             this.horizontalMeasureColumns();
208             return;
209         }
210         
211         this.verticalMeasureColumns();
212         
213     },
214     
215     verticalMeasureColumns : function()
216     {
217         this.getContainerWidth();
218         
219 //        if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
220 //            this.colWidth = Math.floor(this.containerWidth * 0.8);
221 //            return;
222 //        }
223         
224         var boxWidth = this.boxWidth + this.padWidth;
225         
226         if(this.containerWidth < this.boxWidth){
227             boxWidth = this.containerWidth
228         }
229         
230         var containerWidth = this.containerWidth;
231         
232         var cols = Math.floor(containerWidth / boxWidth);
233         
234         this.cols = Math.max( cols, 1 );
235         
236         this.cols = this.maxCols > 0 ? Math.min( this.cols, this.maxCols ) : this.cols;
237         
238         var totalBoxWidth = this.cols * boxWidth - this.padWidth;
239         
240         var avail = Math.floor((containerWidth - totalBoxWidth) / this.cols);
241         
242         this.colWidth = boxWidth + avail - this.padWidth;
243         
244         this.unitWidth = Math.round((this.colWidth - (this.gutter * 2)) / 3);
245         this.unitHeight = this.boxHeight > 0 ? this.boxHeight  : this.unitWidth;
246     },
247     
248     horizontalMeasureColumns : function()
249     {
250         this.getContainerWidth();
251         
252         var boxWidth = this.boxWidth;
253         
254         if(this.containerWidth < boxWidth){
255             boxWidth = this.containerWidth;
256         }
257         
258         this.unitWidth = Math.floor((boxWidth - (this.gutter * 2)) / 3);
259         
260         this.el.setHeight(boxWidth);
261         
262     },
263     
264     getContainerWidth : function()
265     {
266         this.containerWidth = this.el.getBox(true).width;  //maybe use getComputedWidth
267     },
268     
269     layoutItems : function( isInstant )
270     {
271         Roo.log(this.bricks);
272         
273         var items = Roo.apply([], this.bricks);
274         
275         if(this.isHorizontal){
276             this._horizontalLayoutItems( items , isInstant );
277             return;
278         }
279         
280 //        if(Roo.lib.Dom.getViewWidth() < 768 && this.isAlternative){
281 //            this._verticalAlternativeLayoutItems( items , isInstant );
282 //            return;
283 //        }
284         
285         this._verticalLayoutItems( items , isInstant );
286         
287     },
288     
289     _verticalLayoutItems : function ( items , isInstant)
290     {
291         if ( !items || !items.length ) {
292             return;
293         }
294         
295         var standard = [
296             ['xs', 'xs', 'xs', 'tall'],
297             ['xs', 'xs', 'tall'],
298             ['xs', 'xs', 'sm'],
299             ['xs', 'xs', 'xs'],
300             ['xs', 'tall'],
301             ['xs', 'sm'],
302             ['xs', 'xs'],
303             ['xs'],
304             
305             ['sm', 'xs', 'xs'],
306             ['sm', 'xs'],
307             ['sm'],
308             
309             ['tall', 'xs', 'xs', 'xs'],
310             ['tall', 'xs', 'xs'],
311             ['tall', 'xs'],
312             ['tall']
313             
314         ];
315         
316         var queue = [];
317         
318         var boxes = [];
319         
320         var box = [];
321         
322         Roo.each(items, function(item, k){
323             
324             switch (item.size) {
325                 // these layouts take up a full box,
326                 case 'md' :
327                 case 'md-left' :
328                 case 'md-right' :
329                 case 'wide' :
330                     
331                     if(box.length){
332                         boxes.push(box);
333                         box = [];
334                     }
335                     
336                     boxes.push([item]);
337                     
338                     break;
339                     
340                 case 'xs' :
341                 case 'sm' :
342                 case 'tall' :
343                     
344                     box.push(item);
345                     
346                     break;
347                 default :
348                     break;
349                     
350             }
351             
352         }, this);
353         
354         if(box.length){
355             boxes.push(box);
356             box = [];
357         }
358         
359         var filterPattern = function(box, length)
360         {
361             if(!box.length){
362                 return;
363             }
364             
365             var match = false;
366             
367             var pattern = box.slice(0, length);
368             
369             var format = [];
370             
371             Roo.each(pattern, function(i){
372                 format.push(i.size);
373             }, this);
374             
375             Roo.each(standard, function(s){
376                 
377                 if(String(s) != String(format)){
378                     return;
379                 }
380                 
381                 match = true;
382                 return false;
383                 
384             }, this);
385             
386             if(!match && length == 1){
387                 return;
388             }
389             
390             if(!match){
391                 filterPattern(box, length - 1);
392                 return;
393             }
394                 
395             queue.push(pattern);
396
397             box = box.slice(length, box.length);
398
399             filterPattern(box, 4);
400
401             return;
402             
403         }
404         
405         Roo.each(boxes, function(box, k){
406             
407             if(!box.length){
408                 return;
409             }
410             
411             if(box.length == 1){
412                 queue.push(box);
413                 return;
414             }
415             
416             filterPattern(box, 4);
417             
418         }, this);
419         
420         this._processVerticalLayoutQueue( queue, isInstant );
421         
422     },
423     
424 //    _verticalAlternativeLayoutItems : function( items , isInstant )
425 //    {
426 //        if ( !items || !items.length ) {
427 //            return;
428 //        }
429 //
430 //        this._processVerticalAlternativeLayoutQueue( items, isInstant );
431 //        
432 //    },
433     
434     _horizontalLayoutItems : function ( items , isInstant)
435     {
436         if ( !items || !items.length || items.length < 3) {
437             return;
438         }
439         
440         items.reverse();
441         
442         var eItems = items.slice(0, 3);
443         
444         items = items.slice(3, items.length);
445         
446         var standard = [
447             ['xs', 'xs', 'xs', 'wide'],
448             ['xs', 'xs', 'wide'],
449             ['xs', 'xs', 'sm'],
450             ['xs', 'xs', 'xs'],
451             ['xs', 'wide'],
452             ['xs', 'sm'],
453             ['xs', 'xs'],
454             ['xs'],
455             
456             ['sm', 'xs', 'xs'],
457             ['sm', 'xs'],
458             ['sm'],
459             
460             ['wide', 'xs', 'xs', 'xs'],
461             ['wide', 'xs', 'xs'],
462             ['wide', 'xs'],
463             ['wide'],
464             
465             ['wide-thin']
466         ];
467         
468         var queue = [];
469         
470         var boxes = [];
471         
472         var box = [];
473         
474         Roo.each(items, function(item, k){
475             
476             switch (item.size) {
477                 case 'md' :
478                 case 'md-left' :
479                 case 'md-right' :
480                 case 'tall' :
481                     
482                     if(box.length){
483                         boxes.push(box);
484                         box = [];
485                     }
486                     
487                     boxes.push([item]);
488                     
489                     break;
490                     
491                 case 'xs' :
492                 case 'sm' :
493                 case 'wide' :
494                 case 'wide-thin' :
495                     
496                     box.push(item);
497                     
498                     break;
499                 default :
500                     break;
501                     
502             }
503             
504         }, this);
505         
506         if(box.length){
507             boxes.push(box);
508             box = [];
509         }
510         
511         var filterPattern = function(box, length)
512         {
513             if(!box.length){
514                 return;
515             }
516             
517             var match = false;
518             
519             var pattern = box.slice(0, length);
520             
521             var format = [];
522             
523             Roo.each(pattern, function(i){
524                 format.push(i.size);
525             }, this);
526             
527             Roo.each(standard, function(s){
528                 
529                 if(String(s) != String(format)){
530                     return;
531                 }
532                 
533                 match = true;
534                 return false;
535                 
536             }, this);
537             
538             if(!match && length == 1){
539                 return;
540             }
541             
542             if(!match){
543                 filterPattern(box, length - 1);
544                 return;
545             }
546                 
547             queue.push(pattern);
548
549             box = box.slice(length, box.length);
550
551             filterPattern(box, 4);
552
553             return;
554             
555         }
556         
557         Roo.each(boxes, function(box, k){
558             
559             if(!box.length){
560                 return;
561             }
562             
563             if(box.length == 1){
564                 queue.push(box);
565                 return;
566             }
567             
568             filterPattern(box, 4);
569             
570         }, this);
571         
572         
573         var prune = [];
574         
575         var pos = this.el.getBox(true);
576         
577         var minX = pos.x;
578         
579         var maxX = pos.right - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
580         
581         var hit_end = false;
582         
583         Roo.each(queue, function(box){
584             
585             if(hit_end){
586                 
587                 Roo.each(box, function(b){
588                 
589                     b.el.setVisibilityMode(Roo.Element.DISPLAY);
590                     b.el.hide();
591
592                 }, this);
593
594                 return;
595             }
596             
597             var mx = 0;
598             
599             Roo.each(box, function(b){
600                 
601                 b.el.setVisibilityMode(Roo.Element.DISPLAY);
602                 b.el.show();
603
604                 mx = Math.max(mx, b.x);
605                 
606             }, this);
607             
608             maxX = maxX - this.unitWidth * mx - this.gutter * (mx - 1) - this.padWidth;
609             
610             if(maxX < minX){
611                 
612                 Roo.each(box, function(b){
613                 
614                     b.el.setVisibilityMode(Roo.Element.DISPLAY);
615                     b.el.hide();
616                     
617                 }, this);
618                 
619                 hit_end = true;
620                 
621                 return;
622             }
623             
624             prune.push(box);
625             
626         }, this);
627         
628         this._processHorizontalLayoutQueue( prune, eItems, isInstant );
629     },
630     
631     /** Sets position of item in DOM
632     * @param {Element} item
633     * @param {Number} x - horizontal position
634     * @param {Number} y - vertical position
635     * @param {Boolean} isInstant - disables transitions
636     */
637     _processVerticalLayoutQueue : function( queue, isInstant )
638     {
639         var pos = this.el.getBox(true);
640         var x = pos.x;
641         var y = pos.y;
642         var maxY = [];
643         
644         for (var i = 0; i < this.cols; i++){
645             maxY[i] = pos.y;
646         }
647         
648         Roo.each(queue, function(box, k){
649             
650             var col = k % this.cols;
651             
652             Roo.each(box, function(b,kk){
653                 
654                 b.el.position('absolute');
655                 
656                 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
657                 var height = Math.floor(this.unitHeight * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
658                 
659                 if(b.size == 'md-left' || b.size == 'md-right'){
660                     width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
661                     height = Math.floor(this.unitHeight * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
662                 }
663                 
664                 b.el.setWidth(width);
665                 b.el.setHeight(height);
666                 // iframe?
667 //                b.el.select('iframe',true).setSize(width,height);
668                 
669             }, this);
670             
671             for (var i = 0; i < this.cols; i++){
672                 
673                 if(maxY[i] < maxY[col]){
674                     col = i;
675                     continue;
676                 }
677                 
678                 col = Math.min(col, i);
679                 
680             }
681             
682             x = pos.x + col * (this.colWidth + this.padWidth);
683             
684             y = maxY[col];
685             
686             var positions = [];
687             
688             switch (box.length){
689                 case 1 :
690                     positions = this.getVerticalOneBoxColPositions(x, y, box);
691                     break;
692                 case 2 :
693                     positions = this.getVerticalTwoBoxColPositions(x, y, box);
694                     break;
695                 case 3 :
696                     positions = this.getVerticalThreeBoxColPositions(x, y, box);
697                     break;
698                 case 4 :
699                     positions = this.getVerticalFourBoxColPositions(x, y, box);
700                     break;
701                 default :
702                     break;
703             }
704             
705             Roo.each(box, function(b,kk){
706                 
707                 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
708                 
709                 var sz = b.el.getSize();
710                 
711                 maxY[col] = Math.max(maxY[col], positions[kk].y + sz.height + this.padWidth);
712                 
713             }, this);
714             
715         }, this);
716         
717         var mY = 0;
718         
719         for (var i = 0; i < this.cols; i++){
720             mY = Math.max(mY, maxY[i]);
721         }
722         
723         this.el.setHeight(mY - pos.y);
724         
725     },
726     
727 //    _processVerticalAlternativeLayoutQueue : function( items, isInstant )
728 //    {
729 //        var pos = this.el.getBox(true);
730 //        var x = pos.x;
731 //        var y = pos.y;
732 //        var maxX = pos.right;
733 //        
734 //        var maxHeight = 0;
735 //        
736 //        Roo.each(items, function(item, k){
737 //            
738 //            var c = k % 2;
739 //            
740 //            item.el.position('absolute');
741 //                
742 //            var width = Math.floor(this.colWidth + item.el.getPadding('lr'));
743 //
744 //            item.el.setWidth(width);
745 //
746 //            var height = Math.floor(this.colWidth * item.y / item.x + item.el.getPadding('tb'));
747 //
748 //            item.el.setHeight(height);
749 //            
750 //            if(c == 0){
751 //                item.el.setXY([x, y], isInstant ? false : true);
752 //            } else {
753 //                item.el.setXY([maxX - width, y], isInstant ? false : true);
754 //            }
755 //            
756 //            y = y + height + this.alternativePadWidth;
757 //            
758 //            maxHeight = maxHeight + height + this.alternativePadWidth;
759 //            
760 //        }, this);
761 //        
762 //        this.el.setHeight(maxHeight);
763 //        
764 //    },
765     
766     _processHorizontalLayoutQueue : function( queue, eItems, isInstant )
767     {
768         var pos = this.el.getBox(true);
769         
770         var minX = pos.x;
771         var minY = pos.y;
772         
773         var maxX = pos.right;
774         
775         this._processHorizontalEndItem(eItems, maxX, minX, minY, isInstant);
776         
777         var maxX = maxX - this.unitWidth * 3 - this.gutter * 2 - this.padWidth;
778         
779         Roo.each(queue, function(box, k){
780             
781             Roo.each(box, function(b, kk){
782                 
783                 b.el.position('absolute');
784                 
785                 var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
786                 var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
787                 
788                 if(b.size == 'md-left' || b.size == 'md-right'){
789                     width = Math.floor(this.unitWidth * (b.x - 1) + (this.gutter * (b.x - 2)) + b.el.getPadding('lr'));
790                     height = Math.floor(this.unitWidth * (b.y - 1) + (this.gutter * (b.y - 2)) + b.el.getPadding('tb'));
791                 }
792                 
793                 b.el.setWidth(width);
794                 b.el.setHeight(height);
795                 
796             }, this);
797             
798             if(!box.length){
799                 return;
800             }
801             
802             var positions = [];
803             
804             switch (box.length){
805                 case 1 :
806                     positions = this.getHorizontalOneBoxColPositions(maxX, minY, box);
807                     break;
808                 case 2 :
809                     positions = this.getHorizontalTwoBoxColPositions(maxX, minY, box);
810                     break;
811                 case 3 :
812                     positions = this.getHorizontalThreeBoxColPositions(maxX, minY, box);
813                     break;
814                 case 4 :
815                     positions = this.getHorizontalFourBoxColPositions(maxX, minY, box);
816                     break;
817                 default :
818                     break;
819             }
820             
821             Roo.each(box, function(b,kk){
822                 
823                 b.el.setXY([positions[kk].x, positions[kk].y], isInstant ? false : true);
824                 
825                 maxX = Math.min(maxX, positions[kk].x - this.padWidth);
826                 
827             }, this);
828             
829         }, this);
830         
831     },
832     
833     _processHorizontalEndItem : function(eItems, maxX, minX, minY, isInstant)
834     {
835         Roo.each(eItems, function(b,k){
836             
837             b.size = (k == 0) ? 'sm' : 'xs';
838             b.x = (k == 0) ? 2 : 1;
839             b.y = (k == 0) ? 2 : 1;
840             
841             b.el.position('absolute');
842             
843             var width = Math.floor(this.unitWidth * b.x + (this.gutter * (b.x - 1)) + b.el.getPadding('lr'));
844                 
845             b.el.setWidth(width);
846             
847             var height = Math.floor(this.unitWidth * b.y + (this.gutter * (b.y - 1)) + b.el.getPadding('tb'));
848             
849             b.el.setHeight(height);
850             
851         }, this);
852
853         var positions = [];
854         
855         positions.push({
856             x : maxX - this.unitWidth * 2 - this.gutter,
857             y : minY
858         });
859         
860         positions.push({
861             x : maxX - this.unitWidth,
862             y : minY + (this.unitWidth + this.gutter) * 2
863         });
864         
865         positions.push({
866             x : maxX - this.unitWidth * 3 - this.gutter * 2,
867             y : minY
868         });
869         
870         Roo.each(eItems, function(b,k){
871             
872             b.el.setXY([positions[k].x, positions[k].y], isInstant ? false : true);
873
874         }, this);
875         
876     },
877     
878     getVerticalOneBoxColPositions : function(x, y, box)
879     {
880         var pos = [];
881         
882         var rand = Math.floor(Math.random() * ((4 - box[0].x)));
883         
884         if(box[0].size == 'md-left'){
885             rand = 0;
886         }
887         
888         if(box[0].size == 'md-right'){
889             rand = 1;
890         }
891         
892         pos.push({
893             x : x + (this.unitWidth + this.gutter) * rand,
894             y : y
895         });
896         
897         return pos;
898     },
899     
900     getVerticalTwoBoxColPositions : function(x, y, box)
901     {
902         var pos = [];
903         
904         if(box[0].size == 'xs'){
905             
906             pos.push({
907                 x : x,
908                 y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[1].y))
909             });
910
911             pos.push({
912                 x : x + (this.unitWidth + this.gutter) * (3 - box[1].x),
913                 y : y
914             });
915             
916             return pos;
917             
918         }
919         
920         pos.push({
921             x : x,
922             y : y
923         });
924
925         pos.push({
926             x : x + (this.unitWidth + this.gutter) * 2,
927             y : y + ((this.unitHeight + this.gutter) * Math.floor(Math.random() * box[0].y))
928         });
929         
930         return pos;
931         
932     },
933     
934     getVerticalThreeBoxColPositions : function(x, y, box)
935     {
936         var pos = [];
937         
938         if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
939             
940             pos.push({
941                 x : x,
942                 y : y
943             });
944
945             pos.push({
946                 x : x + (this.unitWidth + this.gutter) * 1,
947                 y : y
948             });
949             
950             pos.push({
951                 x : x + (this.unitWidth + this.gutter) * 2,
952                 y : y
953             });
954             
955             return pos;
956             
957         }
958         
959         if(box[0].size == 'xs' && box[1].size == 'xs'){
960             
961             pos.push({
962                 x : x,
963                 y : y
964             });
965
966             pos.push({
967                 x : x,
968                 y : y + ((this.unitHeight + this.gutter) * (box[2].y - 1))
969             });
970             
971             pos.push({
972                 x : x + (this.unitWidth + this.gutter) * 1,
973                 y : y
974             });
975             
976             return pos;
977             
978         }
979         
980         pos.push({
981             x : x,
982             y : y
983         });
984
985         pos.push({
986             x : x + (this.unitWidth + this.gutter) * 2,
987             y : y
988         });
989
990         pos.push({
991             x : x + (this.unitWidth + this.gutter) * 2,
992             y : y + (this.unitHeight + this.gutter) * (box[0].y - 1)
993         });
994             
995         return pos;
996         
997     },
998     
999     getVerticalFourBoxColPositions : function(x, y, box)
1000     {
1001         var pos = [];
1002         
1003         if(box[0].size == 'xs'){
1004             
1005             pos.push({
1006                 x : x,
1007                 y : y
1008             });
1009
1010             pos.push({
1011                 x : x,
1012                 y : y + (this.unitHeight + this.gutter) * 1
1013             });
1014             
1015             pos.push({
1016                 x : x,
1017                 y : y + (this.unitHeight + this.gutter) * 2
1018             });
1019             
1020             pos.push({
1021                 x : x + (this.unitWidth + this.gutter) * 1,
1022                 y : y
1023             });
1024             
1025             return pos;
1026             
1027         }
1028         
1029         pos.push({
1030             x : x,
1031             y : y
1032         });
1033
1034         pos.push({
1035             x : x + (this.unitWidth + this.gutter) * 2,
1036             y : y
1037         });
1038
1039         pos.push({
1040             x : x + (this.unitHeightunitWidth + this.gutter) * 2,
1041             y : y + (this.unitHeight + this.gutter) * 1
1042         });
1043
1044         pos.push({
1045             x : x + (this.unitWidth + this.gutter) * 2,
1046             y : y + (this.unitWidth + this.gutter) * 2
1047         });
1048
1049         return pos;
1050         
1051     },
1052     
1053     getHorizontalOneBoxColPositions : function(maxX, minY, box)
1054     {
1055         var pos = [];
1056         
1057         if(box[0].size == 'md-left'){
1058             pos.push({
1059                 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
1060                 y : minY
1061             });
1062             
1063             return pos;
1064         }
1065         
1066         if(box[0].size == 'md-right'){
1067             pos.push({
1068                 x : maxX - this.unitWidth * (box[0].x - 1) - this.gutter * (box[0].x - 2),
1069                 y : minY + (this.unitWidth + this.gutter) * 1
1070             });
1071             
1072             return pos;
1073         }
1074         
1075         var rand = Math.floor(Math.random() * (4 - box[0].y));
1076         
1077         pos.push({
1078             x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
1079             y : minY + (this.unitWidth + this.gutter) * rand
1080         });
1081         
1082         return pos;
1083         
1084     },
1085     
1086     getHorizontalTwoBoxColPositions : function(maxX, minY, box)
1087     {
1088         var pos = [];
1089         
1090         if(box[0].size == 'xs'){
1091             
1092             pos.push({
1093                 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
1094                 y : minY
1095             });
1096
1097             pos.push({
1098                 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
1099                 y : minY + (this.unitWidth + this.gutter) * (3 - box[1].y)
1100             });
1101             
1102             return pos;
1103             
1104         }
1105         
1106         pos.push({
1107             x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
1108             y : minY
1109         });
1110
1111         pos.push({
1112             x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
1113             y : minY + (this.unitWidth + this.gutter) * 2
1114         });
1115         
1116         return pos;
1117         
1118     },
1119     
1120     getHorizontalThreeBoxColPositions : function(maxX, minY, box)
1121     {
1122         var pos = [];
1123         
1124         if(box[0].size == 'xs' && box[1].size == 'xs' && box[2].size == 'xs'){
1125             
1126             pos.push({
1127                 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
1128                 y : minY
1129             });
1130
1131             pos.push({
1132                 x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
1133                 y : minY + (this.unitWidth + this.gutter) * 1
1134             });
1135             
1136             pos.push({
1137                 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
1138                 y : minY + (this.unitWidth + this.gutter) * 2
1139             });
1140             
1141             return pos;
1142             
1143         }
1144         
1145         if(box[0].size == 'xs' && box[1].size == 'xs'){
1146             
1147             pos.push({
1148                 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
1149                 y : minY
1150             });
1151
1152             pos.push({
1153                 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
1154                 y : minY
1155             });
1156             
1157             pos.push({
1158                 x : maxX - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
1159                 y : minY + (this.unitWidth + this.gutter) * 1
1160             });
1161             
1162             return pos;
1163             
1164         }
1165         
1166         pos.push({
1167             x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
1168             y : minY
1169         });
1170
1171         pos.push({
1172             x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
1173             y : minY + (this.unitWidth + this.gutter) * 2
1174         });
1175
1176         pos.push({
1177             x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
1178             y : minY + (this.unitWidth + this.gutter) * 2
1179         });
1180             
1181         return pos;
1182         
1183     },
1184     
1185     getHorizontalFourBoxColPositions : function(maxX, minY, box)
1186     {
1187         var pos = [];
1188         
1189         if(box[0].size == 'xs'){
1190             
1191             pos.push({
1192                 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
1193                 y : minY
1194             });
1195
1196             pos.push({
1197                 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
1198                 y : minY
1199             });
1200             
1201             pos.push({
1202                 x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1) - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
1203                 y : minY
1204             });
1205             
1206             pos.push({
1207                 x : maxX - this.unitWidth * box[3].x - this.gutter * (box[3].x - 1),
1208                 y : minY + (this.unitWidth + this.gutter) * 1
1209             });
1210             
1211             return pos;
1212             
1213         }
1214         
1215         pos.push({
1216             x : maxX - this.unitWidth * box[0].x - this.gutter * (box[0].x - 1),
1217             y : minY
1218         });
1219         
1220         pos.push({
1221             x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1),
1222             y : minY + (this.unitWidth + this.gutter) * 2
1223         });
1224         
1225         pos.push({
1226             x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1),
1227             y : minY + (this.unitWidth + this.gutter) * 2
1228         });
1229         
1230         pos.push({
1231             x : maxX - this.unitWidth * box[1].x - this.gutter * (box[1].x - 1) - this.unitWidth * box[2].x - this.gutter * (box[2].x - 1) - this.unitWidth * box[3].x - this.gutter * (box[3].x - 1),
1232             y : minY + (this.unitWidth + this.gutter) * 2
1233         });
1234
1235         return pos;
1236         
1237     },
1238     
1239     /**
1240     * remove a Masonry Brick
1241     * @param {Roo.bootstrap.MasonryBrick} the masonry brick to remove
1242     */
1243     removeBrick : function(brick_id)
1244     {
1245         if (!brick_id) {
1246             return;
1247         }
1248         
1249         for (var i = 0; i<this.bricks.length; i++) {
1250             if (this.bricks[i].id == brick_id) {
1251                 this.bricks.splice(i,1);
1252                 this.el.dom.removeChild(Roo.get(brick_id).dom);
1253                 this.initial();
1254             }
1255         }
1256     },
1257     
1258     /**
1259     * adds a Masonry Brick
1260     * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
1261     */
1262     addBrick : function(cfg)
1263     {
1264         var cn = new Roo.bootstrap.MasonryBrick(cfg);
1265         //this.register(cn);
1266         cn.parentId = this.id;
1267         cn.render(this.el);
1268         return cn;
1269     },
1270     
1271     /**
1272     * register a Masonry Brick
1273     * @param {Roo.bootstrap.MasonryBrick} the masonry brick to add
1274     */
1275     
1276     register : function(brick)
1277     {
1278         this.bricks.push(brick);
1279         brick.masonryId = this.id;
1280     },
1281     
1282     /**
1283     * clear all the Masonry Brick
1284     */
1285     clearAll : function()
1286     {
1287         this.bricks = [];
1288         //this.getChildContainer().dom.innerHTML = "";
1289         this.el.dom.innerHTML = '';
1290     },
1291     
1292     getSelected : function()
1293     {
1294         if (!this.selectedBrick) {
1295             return false;
1296         }
1297         
1298         return this.selectedBrick;
1299     }
1300 });
1301
1302 Roo.apply(Roo.bootstrap.LayoutMasonry, {
1303     
1304     groups: {},
1305      /**
1306     * register a Masonry Layout
1307     * @param {Roo.bootstrap.LayoutMasonry} the masonry layout to add
1308     */
1309     
1310     register : function(layout)
1311     {
1312         this.groups[layout.id] = layout;
1313     },
1314     /**
1315     * fetch a  Masonry Layout based on the masonry layout ID
1316     * @param {string} the masonry layout to add
1317     * @returns {Roo.bootstrap.LayoutMasonry} the masonry layout
1318     */
1319     
1320     get: function(layout_id) {
1321         if (typeof(this.groups[layout_id]) == 'undefined') {
1322             return false;
1323         }
1324         return this.groups[layout_id] ;
1325     }
1326     
1327     
1328     
1329 });
1330
1331  
1332
1333