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         cfg.html = this.html || cfg.html;
53         
54         cfg.src = this.src || cfg.src;
55         
56         if (['rounded','circle','thumbnail'].indexOf(this.border)>-1) {
57             cfg.cls += ' img-' + this.border;
58         }
59         
60         if(this.alt){
61             cfg.alt = this.alt;
62         }
63         
64         if(this.href){
65             var a = {
66                 tag: 'a',
67                 href: this.href,
68                 cn: [
69                     cfg
70                 ]
71             }
72         }
73         
74         
75         return (this.href) ? a : cfg;
76     },
77     
78     initEvents: function() {
79         
80         if(!this.href){
81             this.el.on('click', this.onClick, this);
82         }
83     },
84     
85     onClick : function(e)
86     {
87         Roo.log('img onclick');
88         this.fireEvent('click', this, e);
89     }
90    
91 });
92
93