Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / src / Img.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * @class Ext.Img
17  * @extends Ext.Component
18  *
19  * Simple helper class for easily creating image components. This simply renders an image tag to the DOM
20  * with the configured src.
21  *
22  * {@img Ext.Img/Ext.Img.png Ext.Img component}
23  *
24  * ## Example usage: 
25  *
26  *     var changingImage = Ext.create('Ext.Img', {
27  *         src: 'http://www.sencha.com/img/20110215-feat-html5.png',
28  *         renderTo: Ext.getBody()
29  *     });
30  *      
31  *     // change the src of the image programmatically
32  *     changingImage.setSrc('http://www.sencha.com/img/20110215-feat-perf.png');
33 */
34 Ext.define('Ext.Img', {
35     extend: 'Ext.Component',
36     alias: ['widget.image', 'widget.imagecomponent'],
37     /** @cfg {String} src The image src */
38     src: '',
39
40     getElConfig: function() {
41         return {
42             tag: 'img',
43             src: this.src
44         };
45     },
46     
47     // null out this function, we can't set any html inside the image
48     initRenderTpl: Ext.emptyFn,
49     
50     /**
51      * Updates the {@link #src} of the image
52      */
53     setSrc: function(src) {
54         var me = this,
55             img = me.el;
56         me.src = src;
57         if (img) {
58             img.dom.src = src;
59         }
60     }
61 });
62