app.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * @example Image
  3. *
  4. * A Component subclass that adds a value to an image
  5. */
  6. Ext.require('Ext.panel.Panel');
  7. Ext.define('Ext.ux.Image', {
  8. extend: 'Ext.Component', // subclass Ext.Component
  9. alias: 'widget.managedimage', // this component will have an xtype of 'managedimage'
  10. autoEl: {
  11. tag: 'img',
  12. src: Ext.BLANK_IMAGE_URL,
  13. cls: 'my-managed-image'
  14. },
  15. // Add custom processing to the onRender phase.
  16. // Add a ‘load’ listener to the element.
  17. onRender: function() {
  18. this.autoEl = Ext.apply({}, this.initialConfig, this.autoEl);
  19. this.callParent(arguments);
  20. this.el.on('load', this.onLoad, this);
  21. },
  22. onLoad: function() {
  23. this.fireEvent('load', this);
  24. },
  25. setSrc: function(src) {
  26. if (this.rendered) {
  27. this.el.dom.src = src;
  28. } else {
  29. this.src = src;
  30. }
  31. },
  32. getSrc: function(src) {
  33. return this.el.dom.src || this.src;
  34. }
  35. });
  36. Ext.onReady(function() {
  37. var image = Ext.create('Ext.ux.Image');
  38. Ext.create('Ext.panel.Panel', {
  39. title: 'Image Panel',
  40. height: 200,
  41. renderTo: Ext.getBody(),
  42. items: [ image ]
  43. })
  44. image.on('load', function() {
  45. console.log('image loaded: ', image.getSrc());
  46. });
  47. image.setSrc('http://www.sencha.com/img/sencha-large.png');
  48. });