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