Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
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();
}
});
}
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');
});
};
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');
});
};
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);
};
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))
}
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);
}
});
};
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);
};
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);
};
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);
};