Skip to content

Instantly share code, notes, and snippets.

@ghabxph
Last active September 29, 2017 08:17
Show Gist options
  • Save ghabxph/ed4c14fe6b2a45737fb7fa2b5c947114 to your computer and use it in GitHub Desktop.
Save ghabxph/ed4c14fe6b2a45737fb7fa2b5c947114 to your computer and use it in GitHub Desktop.
General purpose toggler
/**
* Toggler
* @author Gabriel Lucernas Pascual <me@ghabpxh.info>
* @license MIT
* @link https://gist.github.com/ghabxph/ed4c14fe6b2a45737fb7fa2b5c947114
*/
$(function(){
/**
* Waits for .toggler element to be clicked
*/
$('.toggleable').click(function(){
var sState = (iState === 'toggle-off') ? 'toggle-on' : 'toggle-off';
this.attr('data-state', sState);
this.trigger(sState);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment