Skip to content

Instantly share code, notes, and snippets.

Last active November 8, 2017 14:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save claudia-romano/1d5299887ef299ef246b392437047a98 to your computer and use it in GitHub Desktop.
(function() {
function ncCreateCustomEvent(eventName) {
//this function is used to create custom events in Javascript
//you can use your own if you already have one
var customEvent;
if (typeof window.Event == 'function') {
customEvent = new Event(eventName, {'bubbles': false, 'cancelable': true});
} else {
//fallback for IE - initEvent is deprecated but this will run only for IE9/IE10
customEvent = document.createEvent('Event');
customEvent.initEvent(eventName, false, true);
return customEvent;
function ncCheckOption(event) {
//an input has been selected/deselected -> we need to trigger the icon animation'svg')[0].dispatchEvent(ncCreateCustomEvent('animate'));
//if the input is a radio input, we need to deselect all the siblings
if( == 'radio') ncResetRadio(this, event);
function ncResetRadio(wrapper, input) {
var radioInput = wrapper.querySelectorAll('input[type=radio]:not(:checked)'),
resetEvent = ncCreateCustomEvent('reset');
for( var i = 0; radioInput.length > i; i++ ) {
var formButtons = document.getElementsByClassName('js-nc-form-buttons');
if( formButtons ) {
for( var i = 0; formButtons.length > i; i++ ) {
formButtons[i].addEventListener('change', ncCheckOption);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment