Roo/bootstrap/Brick.js
[roojs1] / Roo / bootstrap / Brick.js
1 /*
2  * - LGPL
3  *
4  * element
5  * 
6  */
7
8 /**
9  * @class Roo.bootstrap.Brick
10  * @extends Roo.bootstrap.Component
11  * Bootstrap Brick class
12  * 
13  * @constructor
14  * Create a new Brick
15  * @param {Object} config The config object
16  */
17
18 Roo.bootstrap.Brick = function(config){
19     Roo.bootstrap.Brick.superclass.constructor.call(this, config);
20     
21     this.addEvents({
22         // raw events
23         /**
24          * @event click
25          * When a Brick is click
26          * @param {Roo.bootstrap.Brick} this
27          * @param {Roo.EventObject} e
28          */
29         "click" : true
30     });
31 };
32
33 Roo.extend(Roo.bootstrap.MasonryBrick, Roo.bootstrap.Component,  {
34     
35     /**
36      * @cfg {String} title
37      */   
38     title : '',
39     /**
40      * @cfg {String} html
41      */   
42     html : '',
43     /**
44      * @cfg {String} bgimage
45      */   
46     bgimage : '',
47     /**
48      * @cfg {String} cls
49      */   
50     cls : '',
51     /**
52      * @cfg {String} href
53      */   
54     href : '',
55     /**
56      * @cfg {String} video
57      */   
58     video : '',
59     /**
60      * @cfg {Boolean} square
61      */   
62     square : true,
63     
64     getAutoCreate : function()
65     {
66         var cls = 'roo-brick';
67         
68         if(this.href.length){
69             cls += ' roo-brick-link';
70         }
71         
72         if(this.bgimage.length){
73             cls += ' roo-brick-image';
74         }
75         
76         if(this.cls){
77             cls += ' ' + this.cls;
78         }
79         
80         var cfg = {
81             tag: (this.href.length) ? 'a' : 'div',
82             cls: cls,
83             cn: [
84                 {
85                     tag: 'div',
86                     cls: 'roo-brick-paragraph',
87                     cn: []
88                 }
89             ]
90         };
91         
92         if(this.href.length){
93             cfg.href = this.href;
94         }
95         
96         var cn = cfg.cn[0].cn;
97         
98         if(this.title.length){
99             cn.push({
100                 tag: 'h4',
101                 cls: 'masonry-brick-title',
102                 html: this.title
103             });
104         }
105         
106         if(this.html.length){
107             cn.push({
108                 tag: 'p',
109                 cls: 'masonry-brick-text',
110                 html: this.html
111             });
112         }
113         
114         if(this.bgimage.length){
115             cfg.cn.push({
116                 tag: 'img',
117                 cls: 'masonry-brick-image-view',
118                 src: this.bgimage
119             });
120         }
121         
122         return cfg;
123     },
124     
125     initEvents: function() 
126     {
127         this.intSize = 1;
128         
129         switch (this.size) {
130             case 'xs' :
131                 this.intSize = 1;
132                 break;
133             case 'sm' :
134                 this.intSize = 2;
135                 break;
136             case 'md' :
137                 this.intSize = 3;
138                 break;
139             default :
140                 break;
141         }
142         
143         this.el.on('mouseenter'  ,this.enter, this);
144         this.el.on('mouseleave', this.leave, this);
145         
146         this.parent().bricks.push(this);
147         
148     },
149     
150     resize : function()
151     {
152         var paragraph = this.el.select('.masonry-brick-paragraph', true).first();
153         paragraph.setHeight(paragraph.getWidth() + paragraph.getPadding('tb'));
154     },
155     
156     enter: function(e, el)
157     {
158         e.preventDefault();
159         
160         if(this.bgimage.length){
161             this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0.9, true);
162         }
163     },
164     
165     leave: function(e, el)
166     {
167         e.preventDefault();
168         
169         if(this.bgimage.length){
170             this.el.select('.masonry-brick-paragraph', true).first().setOpacity(0, true);
171         }
172     }
173     
174 });
175
176  
177
178