rivet-switch
Version:
An accessible switch component for Rivet
9 lines (7 loc) • 922 B
JavaScript
/*!
*
* Copyright (C) 2018 The Trustees of Indiana University
* SPDX-License-Identifier: BSD-3-Clause
* rivet-switch - @version 0.3.2
*/
!function(t,e){"function"==typeof define&&define.amd?define([],function(){return e(t)}):"object"==typeof exports?module.exports=e(t):t.Switch=e(t)}("undefined"!=typeof global?global:"undefined"!=typeof window?window:this,function(t){"use strict";var n=function(t,e){var n=new CustomEvent(e,{bubbles:!0,detail:{name:function(){return t.getAttribute("data-switch")}}});t.dispatchEvent(n)},i=function(t,e){t.setAttribute("aria-checked","true"),n(t,"switchOn"),e&&"function"==typeof e&&e()},o=function(t,e){t.setAttribute("aria-checked","false"),n(t,"switchOff"),e&&"function"==typeof e&&e()},e=function(t){var e=t.target.closest("[data-switch]");e&&("false"===e.getAttribute("aria-checked")?i(e):o(e))};return{on:i,off:o,init:function(){document.addEventListener("click",e,!1)}}});