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