10 * @class Roo.bootstrap.Img
11 * @extends Roo.bootstrap.Component
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
26 * @param {Object} config The config object
29 Roo.bootstrap.Img = function(config){
30 Roo.bootstrap.Img.superclass.constructor.call(this, config);
36 * The img click event for the img.
37 * @param {Roo.EventObject} e
42 * The when any image loads
43 * @param {Roo.EventObject} e
49 Roo.extend(Roo.bootstrap.Img, Roo.bootstrap.Component, {
61 getAutoCreate : function()
63 if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
64 return this.createSingleImg();
69 cls: 'roo-image-responsive-group',
74 Roo.each(['xs', 'sm', 'md', 'lg'], function(size){
76 if(!_this[size + 'Url']){
82 cls: (_this.imgResponsive) ? 'img-responsive' : '',
83 html: _this.html || cfg.html,
84 src: _this[size + 'Url']
87 img.cls += ' roo-image-responsive-' + size;
89 var s = ['xs', 'sm', 'md', 'lg'];
91 s.splice(s.indexOf(size), 1);
93 Roo.each(s, function(ss){
94 img.cls += ' hidden-' + ss;
97 if (['rounded','circle','thumbnail'].indexOf(_this.border)>-1) {
98 cfg.cls += ' img-' + _this.border;
115 a.target = _this.target;
119 cfg.cn.push((_this.href) ? a : img);
126 createSingleImg : function()
130 cls: (this.imgResponsive) ? 'img-responsive' : '',
132 src : 'about:blank' // just incase src get's set to undefined?!?
135 cfg.html = this.html || cfg.html;
137 cfg.src = this.src || cfg.src;
139 if (['rounded','circle','thumbnail'].indexOf(this.border)>-1) {
140 cfg.cls += ' img-' + this.border;
157 a.target = this.target;
162 return (this.href) ? a : cfg;
165 initEvents: function()
168 this.el.on('click', this.onClick, this);
170 this.el.select('img', true).on('load', this.onImageLoad, this);
173 onClick : function(e)
175 Roo.log('img onclick');
176 this.fireEvent('click', this, e);
178 onImageLoad: function(e)
181 this.fireEvent('load', this, e);
185 * Sets the url of the image - used to update it
186 * @param {String} url the url of the image
189 setSrc : function(url)
193 if(this.src || (!this.xsUrl && !this.smUrl && !this.mdUrl && !this.lgUrl)){
194 this.el.dom.src = url;
198 this.el.select('img', true).first().dom.src = url;