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