<commit_before>/// <reference path="../../elements.d.ts" />

namespace AnimatedButtonElement {
	export const animatedButtonProperties: {
		cooldown: boolean;
		content: string;
		tap: string;
		raised: boolean;
	} = {
		cooldown: {
			type: Boolean,
			notify: false,
			value: false
		},
		content: {
			type: String,
			notify: true,
			value: ''
		},
		tap: {
			type: String,
			notify: false
		},
		raised: {
			type: Boolean,
			notify: true,
			value: false
		}
	} as any;

	export class AB {
		static is: string = 'animated-button';

		static properties = animatedButtonProperties;

		private static _animationIndex: number = 0;
		private static _isAnimating: boolean = false;

		//Inline this for portability
		private static _wait(this: AnimatedButton, time: number) {
			return new Promise((resolve) => {
				window.setTimeout(() => {
					resolve(null);
				}, time);
			});
		}

		static async doAnimation(this: AnimatedButton) {
			this._isAnimating = true;
			const currentAnimation = ++this._animationIndex;

			this.$.button.classList.add('clicked');
			this.$.contentContainer.classList.add('animate');
			await this._wait(100);
			this.$.contentContainer.classList.add('showcheckmark');

			await this._wait(3000);

			if (this._animationIndex === currentAnimation) {
				this.$.button.classList.remove('clicked');
				this.$.contentContainer.classList.remove('showcheckmark');
				await this._wait(100);
				this.$.contentContainer.classList.remove('animate');

				this._isAnimating = false;
				this._animationIndex = 0;
			}
		}

		static onclick(this: AnimatedButton, e: MouseEvent) {
			if (!this.cooldown || !this._isAnimating) {
				this.doAnimation();

				//Try to find the listener that was added
				if (!this.tap) {
					return;
				}
				const host = this.getRootNode().host as Polymer.RootElement;
				if (this.tap in host) {
					(host[this.tap as keyof typeof host] as (e: MouseEvent) => void)(e);
				} else {
					console.warn.apply(console, host._logf(`_createEventHandler`, 
						`listener method ${this.tap} not defined`));
				}
			}
		}

		static ready(this: AnimatedButton) {
			this.addEventListener('click', (e) => {
				this.onclick(e as MouseEvent)
			});
		};
	}

	if (window.objectify) {
		window.register(AB);
	} else {
		window.addEventListener('RegisterReady', () => {
			window.register(AB);<commit_msg>listen for tap events instead of click events<commit_after>/// <reference path="../../elements.d.ts" />

namespace AnimatedButtonElement {
	export const animatedButtonProperties: {
		cooldown: boolean;
		content: string;
		tap: string;
		raised: boolean;
	} = {
		cooldown: {
			type: Boolean,
			notify: false,
			value: false
		},
		content: {
			type: String,
			notify: true,
			value: ''
		},
		tap: {
			type: String,
			notify: false
		},
		raised: {
			type: Boolean,
			notify: true,
			value: false
		}
	} as any;

	export class AB {
		static is: string = 'animated-button';

		static properties = animatedButtonProperties;

		private static _animationIndex: number = 0;
		private static _isAnimating: boolean = false;

		//Inline this for portability
		private static _wait(this: AnimatedButton, time: number) {
			return new Promise((resolve) => {
				window.setTimeout(() => {
					resolve(null);
				}, time);
			});
		}

		static async doAnimation(this: AnimatedButton) {
			this._isAnimating = true;
			const currentAnimation = ++this._animationIndex;

			this.$.button.classList.add('clicked');
			this.$.contentContainer.classList.add('animate');
			await this._wait(100);
			this.$.contentContainer.classList.add('showcheckmark');

			await this._wait(3000);

			if (this._animationIndex === currentAnimation) {
				this.$.button.classList.remove('clicked');
				this.$.contentContainer.classList.remove('showcheckmark');
				await this._wait(100);
				this.$.contentContainer.classList.remove('animate');

				this._isAnimating = false;
				this._animationIndex = 0;
			}
		}

		static onclick(this: AnimatedButton, e: MouseEvent) {
			if (!this.cooldown || !this._isAnimating) {
				this.doAnimation();

				//Try to find the listener that was added
				if (!this.tap) {
					return;
				}
				const host = this.getRootNode().host as Polymer.RootElement;
				if (this.tap in host) {
					(host[this.tap as keyof typeof host] as (e: MouseEvent) => void)(e);
				} else {
					console.warn.apply(console, host._logf(`_createEventHandler`, 
						`listener method ${this.tap} not defined`));
				}
			}
		}

		static ready(this: AnimatedButton) {
			this.addEventListener('tap', (e) => {
				this.onclick(e as MouseEvent)
			});
		};
	}

	if (window.objectify) {
		window.register(AB);
	} else {
		window.addEventListener('RegisterReady', () => {
			window.register(AB);
{'fraction_non_alphanumeric': 0.14285714285714285, 'fraction_numerical': 0.0050568900126422255, 'mean_word_length': 3.2920433996383363, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6738229', 'n_tokens_mistral': 1851, 'n_tokens_neox': 1499, 'n_words': 340}