How to use the delegate function in delegate

To help you get started, we’ve selected a few delegate 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 swup / swup / src / index.js View on Github external
enable() {
		// check for Promise support
		if (typeof Promise === 'undefined') {
			console.warn('Promise is not supported');
			return;
		}

		// add event listeners
		this.delegatedListeners.click = delegate(
			document,
			this.options.linkSelector,
			'click',
			this.linkClickHandler.bind(this)
		);
		window.addEventListener('popstate', this.popStateHandler.bind(this));

		// initial save to cache
		let page = getDataFromHtml(document.documentElement.outerHTML, this.options.containers);
		page.url = page.responseURL = getCurrentUrl();
		if (this.options.cache) {
			this.cache.cacheUrl(page);
		}

		// mark swup blocks in html
		markSwupElements(document.documentElement, this.options.containers);
github sindresorhus / refined-github / source / features / add-confirmation-to-comment-cancellation.js View on Github external
export default function () {
	delegate('.js-hide-inline-comment-form', 'click', event => {
		// Do not prompt if textarea is empty
		const textarea = event.target.closest('.js-inline-comment-form').querySelector('.js-comment-field');
		if (textarea.value === '') {
			return;
		}

		if (window.confirm('Are you sure you want to discard your unsaved changes?') === false) { // eslint-disable-line no-alert
			event.stopPropagation();
			event.stopImmediatePropagation();
		}
	});
}
github bigcommerce / bigcommerce-for-wordpress / assets / js / src / public / page / address.js View on Github external
const handleDeleteConfirmation = (card, form) => {
	const template = tools.getNodes('.bc-account-address__delete-confirmation', false, card, true)[0];
	tools.addClass(template, 'bc-confirmation-active');

	delegate(card, '[data-js="bc-confirm-address-deletion"]', 'click', () => {
		form.submit();
	});

	delegate(card, '[data-js="bc-confirm-address-cancel"]', 'click', () => {
		tools.removeClass(template, 'bc-confirmation-active');
	});
};
github bigcommerce / bigcommerce-for-wordpress / assets / js / src / public / page / address.js View on Github external
const handleDeleteConfirmation = (card, form) => {
	const template = tools.getNodes('.bc-account-address__delete-confirmation', false, card, true)[0];
	tools.addClass(template, 'bc-confirmation-active');

	delegate(card, '[data-js="bc-confirm-address-deletion"]', 'click', () => {
		form.submit();
	});

	delegate(card, '[data-js="bc-confirm-address-cancel"]', 'click', () => {
		tools.removeClass(template, 'bc-confirmation-active');
	});
};
github bigcommerce / bigcommerce-for-wordpress / assets / js / src / admin / shortcode-ui / display-settings.js View on Github external
const bindEvents = () => {
	delegate(el.displaySettings, '#bc-shortcode-ui__posts-per-page', 'input', setPostsPerPage);
	delegate(el.displaySettings, '[name="bc-shortcode-ui__product-order"]', 'click', setOrderParam);
	delegate(el.displaySettings, '[name="bc-shortcode-ui__product-orderby"]', 'click', setOrderbyParam);
	delegate(el.displaySettings, '[data-js="bc-shortcode-ui-reset-posts-per-page"]', 'click', resetPostsPerPage);
	delegate(el.settingsSidebar, '[data-js="bc-shortcode-ui-remove-term"]', 'click', removeTermOnClick);
	on(document, 'bigcommerce/set_shortcode_ui_state', handleSavedUIDisplaySettings);
	on(document, 'bigcommerce/shortcode_product_list_event', toggleDisplaySettings);
	on(document, 'bigcommerce/shortcode_query_term_added', handleQueryTermAddition);
	on(document, 'bigcommerce/shortcode_query_term_removed', handleQueryTermRemoval);
};
github vigetlabs / ca11y / src / ca11y / index.js View on Github external
listen() {
    this.subscriptions.push(
      delegate(this.ui.calendar, '.ca11y__nav.-next', 'click', this.incrementMonth.bind(this,  1)),
      delegate(this.ui.calendar, '.ca11y__nav.-prev', 'click', this.incrementMonth.bind(this,  -1)),
      delegate(this.ui.calendarDays, '.ca11y__day', 'click', this.onDayClick.bind(this)),
      delegate(this.ui.calendar, 'button', 'blur', this.close.bind(this), true),
      delegate(this.ui.calendar, 'button', 'focus', this.cancelClose.bind(this), true)
    )
    this.ui.wrapper.addEventListener('keydown', this.onKeydown.bind(this))
    this.ui.toggle.addEventListener('click', this.toggle.bind(this))
    this.ui.toggle.addEventListener('focus', this.cancelClose.bind(this))
    this.ui.input.addEventListener('change', this.onInputChange.bind(this))
  }
github bigcommerce / bigcommerce-for-wordpress / assets / js / src / public / product / variants.js View on Github external
tools.getNodes('product-form-option', true, options).forEach((option) => {
		const fieldType = option.dataset.field;

		if (fieldType === 'product-form-option-radio') {
			delegate(option, 'input[type=radio]', 'click', handleSelections);
		}

		if (fieldType === 'product-form-option-select') {
			delegate(option, 'select', 'change', handleSelections);
		}
	});
};
github bigcommerce / bigcommerce-for-wordpress / assets / js / src / public / cart / ajax-items.js View on Github external
const bindEvents = () => {
	delegate(document, '[data-js="bc-cart-item__quantity"]', 'input', handleQtyUpdate);
	delegate(document, '[data-js="remove-cart-item"]', 'click', handleCartItemRemoval);
	on(document, 'bigcommerce/handle_cart_state', handleCartState);
};
github bigcommerce / bigcommerce-for-wordpress / assets / js / src / admin / shortcode-ui / display-settings.js View on Github external
const bindEvents = () => {
	delegate(el.displaySettings, '#bc-shortcode-ui__posts-per-page', 'input', setPostsPerPage);
	delegate(el.displaySettings, '[name="bc-shortcode-ui__product-order"]', 'click', setOrderParam);
	delegate(el.displaySettings, '[name="bc-shortcode-ui__product-orderby"]', 'click', setOrderbyParam);
	delegate(el.displaySettings, '[data-js="bc-shortcode-ui-reset-posts-per-page"]', 'click', resetPostsPerPage);
	delegate(el.settingsSidebar, '[data-js="bc-shortcode-ui-remove-term"]', 'click', removeTermOnClick);
	on(document, 'bigcommerce/set_shortcode_ui_state', handleSavedUIDisplaySettings);
	on(document, 'bigcommerce/shortcode_product_list_event', toggleDisplaySettings);
	on(document, 'bigcommerce/shortcode_query_term_added', handleQueryTermAddition);
	on(document, 'bigcommerce/shortcode_query_term_removed', handleQueryTermRemoval);
};
github bigcommerce / bigcommerce-for-wordpress / assets / js / src / admin / settings / settings.js View on Github external
const bindEvents = () => {
	delegate(el.container, 'input[name="bigcommerce_enable_cart"]', 'change', toggleCartOption);
	delegate(el.container, 'input[name="bigcommerce_enable_embedded_checkout"]', 'change', toggleCheckoutOption);
	delegate(el.container, 'input[name="bigcommerce_enable_gift_certificates"]', 'change', toggleGiftCertificateOption);
};

delegate

Lightweight event delegation

MIT
Latest version published 6 years ago

Package Health Score

70 / 100
Full package analysis

Popular delegate functions