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  * @cfg {String} anchor name for the anchor link
18
19  * @cfg {Boolean} preventDefault (true | false) default false
20
21  * 
22  * @constructor
23  * Create a new Input
24  * @param {Object} config The config object
25  */
26
27 Roo.bootstrap.Link = function(config){
28     Roo.bootstrap.Link.superclass.constructor.call(this, config);
29     
30     this.addEvents({
31         // img events
32         /**
33          * @event click
34          * The img click event for the img.
35          * @param {Roo.EventObject} e
36          */
37         "click" : true
38     });
39 };
40
41 Roo.extend(Roo.bootstrap.Link, Roo.bootstrap.Component,  {
42     
43     href: false,
44     target: false,
45     preventDefault: false,
46     anchor : false,
47     alt : false,
48
49     getAutoCreate : function()
50     {
51         
52         var cfg = {
53             tag: 'a',
54         
55         }
56         // anchor's do not require html/href...
57         if (this.anchor === false) {
58             cfg.html = this.html || 'html-missing';
59             cfg.href = this.href || '#';
60         } else {
61             cfg.name = this.anchor;
62             if (this.html !== false) {
63                 cfg.html = this.html;
64             }
65             if (this.href !== false) {
66                 cfg.href = this.href;
67             }
68         }
69         
70         if(this.alt !== false){
71             cfg.alt = this.alt;
72         }
73         
74         
75         if(this.target) !== false) {
76             cfg.target = this.target;
77         }
78         
79         return cfg;
80     },
81     
82     initEvents: function() {
83         
84         if(!this.href || this.preventDefault){
85             this.el.on('click', this.onClick, this);
86         }
87     },
88     
89     onClick : function(e)
90     {
91         if(this.preventDefault){
92             e.preventDefault();
93         }
94         //Roo.log('img onclick');
95         this.fireEvent('click', this, e);
96     }
97    
98 });
99
100