Roo/bootstrap/Link.js
[roojs1] / Roo / bootstrap / Link.js
1 /*
2  * - LGPL
3  *
4  * image
5  * 
6  */
7
8
9 /**
10  * @class Roo.bootstrap.Link
11  * @extends Roo.bootstrap.Component
12  * Bootstrap Link Class
13  * @cfg {String} alt image alternative text
14  * @cfg {String} href a tag href
15  * @cfg {String} target (_self|_blank|_parent|_top) target for a href.
16  * @cfg {String} html the content of the link.
17
18  * 
19  * @constructor
20  * Create a new Input
21  * @param {Object} config The config object
22  */
23
24 Roo.bootstrap.Link = function(config){
25     Roo.bootstrap.Link.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.Link, 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: (this.imgResponsive) ? '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             if(this.target){
76                 a.target = this.target;
77             }
78             
79         }
80         
81         
82         return (this.href) ? a : cfg;
83     },
84     
85     initEvents: function() {
86         
87         if(!this.href){
88             this.el.on('click', this.onClick, this);
89         }
90     },
91     
92     onClick : function(e)
93     {
94         Roo.log('img onclick');
95         this.fireEvent('click', this, e);
96     }
97    
98 });
99
100