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