Skip to content

Instantly share code, notes, and snippets.

@gsoldateli
Last active February 25, 2018 11:47
Show Gist options
  • Select an option

  • Save gsoldateli/5fa4f022d732a2edd598349e76439924 to your computer and use it in GitHub Desktop.

Select an option

Save gsoldateli/5fa4f022d732a2edd598349e76439924 to your computer and use it in GitHub Desktop.
toggler.js
console.log('Toggler loaded from GitHub!');
toggler = function(selector) {
return (function() {
var toggles = document.querySelectorAll(selector);
var _toggleContent = function(toggleFunction) {
return function() {
if(toggleFunction) {
return (toggleFunction.bind(this))();
}
throw 'You must set a callback for toggler ['+selector+']';
}
};
return {
init: function() {
for(var x = 0; x < toggles.length; x++) {
toggles[x].addEventListener('click',_toggleContent(toggleFunction));
}
return this;
},
setToggleAction: function(callback) {
toggleFunction = callback;
return this;
}
};
})();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment