Roo/bootstrap/Img.js
[roojs1] / Roo / bootstrap / Img.js
1 /*
2  * - LGPL
3  *
4  * image
5  * 
6  */
7
8
9 /**
10  * @class Roo.bootstrap.Img
11  * @extends Roo.bootstrap.Component
12  * Bootstrap Img class
13  * @cfg {Boolean} imgResponsive false | true
14  * @cfg {String} border rounded | circle | thumbnail
15  * @cfg {String} src image source
16  * @cfg {String} alt image alternative text
17  * 
18  * @constructor
19  * Create a new Input
20  * @param {Object} config The config object
21  */
22
23 Roo.bootstrap.Img = function(config){
24     Roo.bootstrap.Img.superclass.constructor.call(this, config);
25     
26     this.addEvents({
27         // img events
28         /**
29          * @event click
30          * The img click event for the img.
31          * @param {Roo.EventObject} e
32          */
33         "click" : true
34     });
35 };
36
37 Roo.extend(Roo.bootstrap.Img, Roo.bootstrap.Component,  {
38     
39     imgResponsive: true,
40     border: '',
41     src: '',
42     href: false,
43
44     getAutoCreate : function(){
45         
46         var cfg = {
47             tag: 'img',
48             cls: 'img-responsive',
49             html : null
50         }
51         
52         if(this.href){
53             cfg = {
54                 tag: 'a',
55                 href: this.href,
56                 cn: [
57                     {
58                         tag: 'img',
59                         cls: 'img-responsive',
60                         html : null
61                     }
62                 ]
63             }
64             
65         }
66         
67         cfg.html = this.html || cfg.html;
68         
69         cfg.src = this.src || cfg.src;
70         
71         if (['rounded','circle','thumbnail'].indexOf(this.border)>-1) {
72             cfg.cls += ' img-' + this.border;
73         }
74         
75         if(this.alt){
76             cfg.alt = this.alt;
77         }
78         
79         return cfg;
80     },
81     
82     initEvents: function() {
83         
84         this.el.on('click', this.onClick, this);
85        
86     },
87     
88     onClick : function(e)
89     {
90         this.fireEvent('click', this, e);
91     }
92    
93 });
94
95