-
1 Mar 2012 7:49 AM #1
Image load
Image load
Any chance that 4.1's Image component might have a load event that fires when the image is loaded on the page?
The images layout awkwardly when the size of the image isn't set in the component's config. Below is how I'm acting on the load event currently which works, but wondered if we might see a load or elementload or some such event in Image.
Code:Ext.define('myimage', { extend: 'Ext.Img' , alias: ['widget.myimage'] , initComponent: function () { this.callParent(); this.addEvents('imageload'); } , afterRender: function () { var me = this; this.callParent(arguments); this.mon(this.el, { 'load' : me.onImgLoad, scope : me }); } , onImgLoad: function () { var me = this , ct = me.ownerCt; me.fireEvent('imageload', me); if (ct) { ct.doLayout(); } } });
-
1 Mar 2012 11:57 AM #2
Yes, it's surprising that it does not have an Observable loaded event.
However, to add listeners to elements of a Component, use the element option of the listeners config:
Code:new Ext.Img({ src: 'http://www.btinternet.com/~the_bagbournes/images/puymorens.jpg', listeners: { load: { fn: function() { alert('Loaded!'); }, element: 'el' } }, renderTo: document.body });Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
1 Mar 2012 12:00 PM #3
Thx for the reply.
Would it be best if I open a feature request for the loaded event on the Image Component?
Also, for my own edification, if I add the listener via 'el' is it now managed so that it's destroyed when the component is destroyed?
Thx again.
-
1 Mar 2012 12:11 PM #4
Element listeners are removed when an element is removed from the DOM
Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
1 Mar 2012 12:13 PM #5
Splendid. Thx for the tip.
-
1 Mar 2012 3:36 PM #6
For what it's worth, my own experience of load events on images is that they didn't used to be reliably supported across all browsers, especially when accessing a file over the file system. I recall having to simulate it by detecting the img tag's dimensions (for an HTML img tag with no width or height set it would be 0x0 until the image was loaded, then it would auto-size). May not be relevant to your use case but it's something that might have to be considered were this to be added to the framework.


Reply With Quote