Upgrade to ExtJS 4.0.1 - Released 05/18/2011
[extjs.git] / src / Img.js
1 /**
2  * @class Ext.Img
3  * @extends Ext.Component
4  *
5  * Simple helper class for easily creating image components. This simply renders an image tag to the DOM
6  * with the configured src.
7  *
8  * {@img Ext.Img/Ext.Img.png Ext.Img component}
9  *
10  * ## Example usage: 
11  *
12  *     var changingImage = Ext.create('Ext.Img', {
13  *         src: 'http://www.sencha.com/img/20110215-feat-html5.png',
14  *         renderTo: Ext.getBody()
15  *     });
16  *      
17  *     // change the src of the image programmatically
18  *     changingImage.setSrc('http://www.sencha.com/img/20110215-feat-perf.png');
19 */
20 Ext.define('Ext.Img', {
21     extend: 'Ext.Component',
22     alias: ['widget.image', 'widget.imagecomponent'],
23     /** @cfg {String} src The image src */
24     src: '',
25
26     getElConfig: function() {
27         return {
28             tag: 'img',
29             src: this.src
30         };
31     },
32     
33     // null out this function, we can't set any html inside the image
34     initRenderTpl: Ext.emptyFn,
35     
36     /**
37      * Updates the {@link #src} of the image
38      */
39     setSrc: function(src) {
40         var me = this,
41             img = me.el;
42         me.src = src;
43         if (img) {
44             img.dom.src = src;
45         }
46     }
47 });