Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

jsarnowski / jsarnowski/blocksy-companion-pro   php

Repository URL to install this package:

Version: 1.8.76 

/ premium / static / js / hooks / hooksSwitch.js

export const mountHooksSwitch = () => {
	const allSwitches = Array.from(
		document.querySelectorAll('.ct-content-block-switch')
	)

	allSwitches.map((toggle) => {
		const postId = toggle.dataset.postId

		toggle.addEventListener('click', (e) => {
			e.preventDefault()

			let enabled = toggle.classList.contains('ct-active') ? 'no' : 'yes'

			toggle.classList.toggle('ct-active')

			fetch(
				`${ct_localizations.ajax_url}?action=blocksy_content_blocksy_toggle&post_id=${postId}&enabled=${enabled}`
			)
				.then((r) => r.json())
				.then(({ data }) => {
					console.log('here', { data })
				})
		})
	})
}