-
5 Feb 2012 9:16 AM #1
Event 'load' with images not fire (ST2 Beta)
Event 'load' with images not fire (ST2 Beta)
Need help. Event onLoad for images not fires. Look thru code please, is it wrong code or I have found a error?
Only 'load' event not fires, but 'tap', 'doubletap', 'swipe' works fine...
Code:Ext.Loader.setConfig({enabled: true}); Ext.application({ name: 'Test', launch: function(){ var viewport = Ext.create('Ext.Container', { fullscreen: true, layout: 'fit' }); var image = Ext.create('Ext.Img', { src: 'http://.......yourUrl.....png' }); image.element.on({ scope: this, load: function() {console.log('onLoad works!');},//Not fires! tap: function() {console.log('onTap works!');}, doubletap: function() {console.log('doubletap works!');}, swipe: function() {console.log('swipe works!');} }); viewport.add(image);} });
-
5 Feb 2012 11:11 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,684
- Vote Rating
- 435
There isn't any load event that fires on the Ext.Img component, that much I think you have discovered. Ext.Img has two modes, 'background' and other with 'background' being the default. By default, 'background' mode will apply the CSS background-image on the <div> which you won't be able to list for the image loading. But if you change the mode config on Ext.Img to anything else it will create the <img> tag:
However this still won't fire a load event even if you drill down to the <img> tag. So time to play with the actual Ext.Img source. First, this is something that we want correct?Code:new Ext.Container({ fullscreen : true, items : [ { xtype : 'image', mode : 'tag', src : 'https://www.google.com/intl/en_com/images/srpr/logo3w.png', width : 275, height : 95 } ] });
We can do this with this little extension:Code:new Ext.Container({ fullscreen : true, items : [ { xtype : 'ux-image', src : 'https://www.google.com/intl/en_com/images/srpr/logo3w.png', width : 275, height : 95, listeners : { load : function() { console.log('Image loaded!'); } } } ] });
Code:Ext.define('Ext.ux.Img', { extend : 'Ext.Img', xtype : 'ux-image', config : { mode : 'tag' }, updateSrc : function() { var me = this, img = me.imageElement; img.dom.onload = Ext.Function.bind(me.onLoad, me, [img], 0); me.callParent(arguments); }, onLoad : function(el, e) { this.fireEvent('load', this, el, e); } });Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
5 Feb 2012 11:14 AM #3Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,684
- Vote Rating
- 435
Ok... so a quick thought... how to handle errors. Here is the new Ext.ux.Img:
And of course to produce the load error:Code:Ext.define('Ext.ux.Img', { extend : 'Ext.Img', xtype : 'ux-image', config : { mode : 'tag' }, updateSrc : function() { var me = this, img = me.imageElement, dom = img.dom; dom.onload = Ext.Function.bind(me.onLoad, me, [img], 0); dom.onerror = Ext.Function.bind(me.onError, me, [img], 0); me.callParent(arguments); }, onLoad : function(el, e) { this.fireEvent('load', this, el, e); }, onError : function(el, e) { this.fireEvent('exception', this, el, e); } });
Code:new Ext.Container({ fullscreen : true, items : [ { xtype : 'ux-image', src : 'https://www.google.com/intl/en_com/images/srpr/logo3wabc.png', //url is invalid width : 275, height : 95, listeners : { load : function() { console.log('Image loaded!'); }, exception : function() { console.warn('Image Failed!'); } } } ] });Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
5 Feb 2012 2:15 PM #4
Thank you very much! Thank you very much! I think this feature must be part of ST2, very useful feature
-
5 Feb 2012 2:29 PM #5Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,684
- Vote Rating
- 435
Next release you will find something
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
8 May 2012 11:10 PM #6
Image size
Image size
Hi,
I have a carousel with pictures. The carousel is part of a panel. I can change the width and height of the picture using the mode tag.
I want the size of the pictures the same size as their placeholder. I think I must use an onload event and make use of getwidth and getheight.
Thanks for help
John
-
27 Mar 2013 5:43 AM #7
Hi, I exact the have the same issue here. The thing i want to do is to show some default image in Ext.Img if image load have failed. I dynamically change image using image.setSrc() method.
Solutions that you have mentioned above seems does not work with ExtJS version 4.1.2. Because there is no any "dom" and "imageElement" property of Ext.Img. And there is no any clues how to solve this in ext docs.
Please help, and thanks in advance.
-
27 Mar 2013 5:45 AM #8Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,684
- Vote Rating
- 435
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
27 Mar 2013 5:55 AM #9
Sorry, I did not know this was Sencha Touch thread. Got here by google search link.


Reply With Quote