Skip to content

Instantly share code, notes, and snippets.

@doriansmiley
Last active January 14, 2020 00:58
Show Gist options
  • Select an option

  • Save doriansmiley/b8e648887f367e256820faba7f336c8b to your computer and use it in GitHub Desktop.

Select an option

Save doriansmiley/b8e648887f367e256820faba7f336c8b to your computer and use it in GitHub Desktop.
import {AbstractComponent} from './AbstractComponent';
import {SkinPart} from './SkinPart';
import {ComponentEvent} from '../control/events/ComponentEvent';
/**
* Created by dsmiley on 7/26/17.
*/
export class Button extends AbstractComponent {
public buttonSkinPart: HTMLElement;
constructor () {
super();
}
public onClick (event: Event): void {
console.log(`Lotus.Button.prototype.onClick: event is ${event}`);
console.log(`Lotus.Button.prototype.onClick: my id is ${this.id}`);
console.log(`Lotus.Button.prototype.onClick: this ${this}`);
this.dispatch(new ComponentEvent(ComponentEvent.CLICK, {target: this.buttonSkinPart, originalEvent: event}));
}
public onSkinPartAdded (part: string, element: HTMLElement): void {
super.onSkinPartAdded(part, element);
switch (part) {
case 'button':
// add button event listener or whatever else yo want to do when this skin part is added
// you could hold until all skin parts are added and then call addEventListeners
console.log(`Lotus.Button.prototype.onSkinPartAdded: part: ${part}`);
console.log(`Lotus.Button.prototype.onSkinPartAdded: skinPart: ${part}`);
this.buttonSkinPart.addEventListener('click', this.onClick.bind(this));
break;
}
}
public removeEventListeners (): void {
super.removeEventListeners();
this.buttonSkinPart.removeEventListener('click', this.onClick);
}
public destroy (): void {
super.destroy();
this.buttonSkinPart.clear();
this.buttonSkinPart = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment