How to use delegate-it - 10 common examples

To help you get started, we’ve selected a few delegate-it examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sindresorhus / refined-github / source / features / fit-textareas.tsx View on Github external
function init(): void {
	// Exclude PR review box because it's in a `position:fixed` container; The scroll HAS to appear within the fixed element.
	delegate('textarea:not(#pull_request_review_body)', 'focusin', focusListener);
}
github sindresorhus / refined-github / source / features / toggle-everything-with-alt.tsx View on Github external
function init(): void {
	// Collapsed comments in PR conversations and files
	delegate('.repository-content', '.minimized-comment details summary', 'click', clickAll(minimizedCommentsSelector));

	// "Load diff" buttons in PR files
	delegate('.repository-content', '.js-file .js-diff-load', 'click', clickAll(allDiffsSelector));

	// Review comments in PR
	delegate('.repository-content', '.js-file .js-resolvable-thread-toggler', 'click', clickAll(resolvedCommentsSelector));
}
github sindresorhus / refined-github / source / features / comment-fields-keyboard-shortcuts.tsx View on Github external
export function listenToCommentFields(callback: DelegateEventHandler): void {
	delegate('.js-comment-field, #commit-description-textarea', 'keydown', event => {
		const field = event.delegateTarget;

		// Don't do anything if the autocomplete helper is shown or if non-Roman input is being used
		if (select.exists('.suggester', field.form!) || event.isComposing) {
			return;
		}

		callback(event);
	}, {
		// Adds support for `esc` key; GitHub seems to use `stopPropagation` on it
		capture: true
	});
}
github sindresorhus / refined-github / source / features / submit-review-as-single-comment.tsx View on Github external
function init(): void {
	delegate('#files', '[action$="/review_comment/create"]', 'submit', handleReviewSubmission);
	delegate('#files', '.rgh-submit-single', 'click', handleSubmitSingle);
	updateUI();
}
github sindresorhus / refined-github / source / features / revert-file.tsx View on Github external
function init(): void {
	delegate('#files', '.js-file-header-dropdown > summary', 'click', handleMenuOpening);
}
github sindresorhus / refined-github / source / features / mark-files-as-viewed.tsx View on Github external
function init(): void {
	delegate('.form-actions button[value="approve"]', 'click', () => markAllFilesAsViewed());
}
github sindresorhus / refined-github / source / features / mark-unread.tsx View on Github external
async function init(): Promise {
	destroy();
	await onDomReady;

	if (pageDetect.isNotifications()) {
		const notifications = await getNotifications();
		if (notifications.length > 0) {
			await renderNotifications(notifications);
			addCustomAllReadButton();
			updateLocalNotificationsCount(notifications);
			updateLocalParticipatingCount(notifications);
			document.dispatchEvent(new CustomEvent('refined-github:mark-unread:notifications-added'));
		}

		listeners.push(
			delegate('.btn-link.delete-note', 'click', markNotificationRead),
			delegate('.js-mark-all-read', 'click', markAllNotificationsRead),
			delegate('.js-delete-notification button', 'click', updateUnreadIndicator),
			delegate('.js-mark-visible-as-read', 'submit', markVisibleNotificationsRead)
		);
	} else if (pageDetect.isPR() || pageDetect.isIssue()) {
		await markRead(location.href);

		if (pageDetect.isPRConversation() || pageDetect.isIssue()) {
			addMarkUnreadButton();
			onUpdatableContentUpdate(select('#partial-discussion-sidebar')!, addMarkUnreadButton);
		}
	} else if (pageDetect.isDiscussionList()) {
		for (const discussion of await getNotifications()) {
			const {pathname} = new URL(discussion.url);
			const listItem = select(`.read [href='${pathname}']`);
			if (listItem) {
github sindresorhus / refined-github / source / features / upload-button.tsx View on Github external
function init(): void {
	addButtons();
	delegate('.rgh-upload-btn', 'click', triggerUploadUI);
}
github sindresorhus / refined-github / source / features / sync-pr-commit-title.tsx View on Github external
function init(): void {
	listeners = [
		...delegate('#discussion_bucket', '#merge_title_field', 'input', maybeShowNote),
		...delegate('#discussion_bucket', 'form.js-merge-pull-request', 'submit', submitPRTitleUpdate),
		...onPrMergePanelOpen(onMergePanelOpen)
	];
}
github sindresorhus / refined-github / source / features / mark-unread.tsx View on Github external
<div>
					<button data-close-dialog="" aria-label="Close dialog" type="button">
						{xIcon()}
					</button>
					<h3>Are you sure?</h3>
				</div>

				<div>
					<p>Are you sure you want to mark all unread notifications as read?</p>
					<button id="clear-local-notification" type="button">Mark all notifications as read</button>
				</div>
			
		
	);

	delegate('#clear-local-notification', 'click', async () =&gt; {
		await setNotifications([]);
		location.reload();
	});
}

delegate-it

Lightweight and modern event delegation in the browser

MIT
Latest version published 5 days ago

Package Health Score

73 / 100
Full package analysis

Popular delegate-it functions