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.Brick, 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         Roo.log(this.title);
99         
100         if(this.title.length){
101             cn.push({
102                 tag: 'h4',
103                 cls: 'roo-brick-title',
104                 html: this.title
105             });
106         }
107         
108         if(this.html.length){
109             cn.push({
110                 tag: 'p',
111                 cls: 'roo-brick-text',
112                 html: this.html
113             });
114         }
115         
116         if(this.bgimage.length){
117             cfg.cn.push({
118                 tag: 'img',
119                 cls: 'roo-brick-image-view',
120                 src: this.bgimage
121             });
122         }
123         
124         return cfg;
125     },
126     
127     initEvents: function() 
128     {
129         if(this.title.length || this.html.length){
130             this.el.on('mouseenter'  ,this.enter, this);
131             this.el.on('mouseleave', this.leave, this);
132         }
133         
134         
135         Roo.EventManager.onWindowResize(this.resize, this); 
136         
137         this.resize();
138     },
139     
140     resize : function()
141     {
142         var paragraph = this.el.select('.roo-brick-paragraph', true).first();
143 //        paragraph.setHeight(paragraph.getWidth() + paragraph.getPadding('tb'));
144         paragraph.setHeight(paragraph.getWidth());
145         
146         if(this.bgimage.length){
147             var image = this.el.select('.roo-brick-image-view', true).first();
148             image.setWidth(paragraph.getWidth());
149             image.setHeight(paragraph.getHeight());
150         }
151         
152     },
153     
154     enter: function(e, el)
155     {
156         e.preventDefault();
157         
158         if(this.bgimage.length){
159             this.el.select('.roo-brick-paragraph', true).first().setOpacity(0.9, true);
160             this.el.select('.roo-brick-image-view', true).first().setOpacity(0.1, true);
161         }
162     },
163     
164     leave: function(e, el)
165     {
166         e.preventDefault();
167         
168         if(this.bgimage.length){
169             this.el.select('.roo-brick-paragraph', true).first().setOpacity(0, true);
170             this.el.select('.roo-brick-image-view', true).first().setOpacity(1, true);
171         }
172     }
173     
174 });
175
176  
177
178