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