Customize components in extjs and expose events to callers

Source: Internet
Author: User
/* *
* @ Example Image
*
* A component subclass that adds a value to an image
  */
Ext. Require ('ext. Panel. Panel ');

Ext. Define ('ext. UX. image ',{
Extend: 'ext. Component ',//Subclass Ext. Component
Alias: 'widget. managedimage ',//This component will have an xtype of 'managedimage'
Autoel :{
Tag: 'img ',
SRC: Ext. blank_image_url,
CLS: 'My-managed-image'
},

// Add custom processing to the onrender phase.
// Add a 'load' listener to the element.
Onrender: Function (){
This . Autoel = ext. Apply ({}, This . Initialconfig, This . Autoel );
This . Callparent (arguments );
This . El. On ('load ', This . Onload, This ), // Load is not an IMG event
This . El. On ('click ', This . Onclick,This );
},

Onload:Function(){
This. Fireevent ('load ',This);
},

Onclick:Function(){
This. Fireevent ('click ',This);
},

Setsrc: Function (SRC ){
If ( This . Rendered ){
This . El. Dom. src = SRC; // El is an instance of the Ext. Element class and should point to the root node of the extjs component.
} Else {
This . Src = SRC;
}
},

Getsrc:Function(SRC ){
Return This. El. Dom. SRC |This. SRC;
}
});

Ext. onready (Function(){

VaRImage = ext. Create ('ext. UX. image ');

Ext. Create ('ext. Panel. Panel ',{
Title: 'image panel ',
Height: 200,
Renderto: Ext. getbody (),
Items: [Image]
})

Image. On ('load ',Function(){
Console. Log ('image loaded: ', image. getsrc ());
});

Image. On ('click ',Function(){
Alert ('click ');
});

Image. setsrc ('HTTP: // www.sencha.com/img/sencha-large.png ');

});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.