This repository has been archived by the owner on May 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Classily.min.js
1 lines (1 loc) · 1.69 KB
/
Classily.min.js
1
"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t};!function(t,e){var r="Classily";"function"==typeof define&&define.amd?define([],e(r)):"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?module.exports=e(r):window[r]=e(r)}(0,function(t){function e(t){this.options=o(r,t),this.init()}var r={selector:".js-classily"},o=function(t,e){var o={};return Object.keys(r).forEach(function(t){Object.prototype.hasOwnProperty.call(r,t)&&(o[t]=r[t])}),Object.keys(e).forEach(function(t){Object.prototype.hasOwnProperty.call(e,t)&&(o[t]=e[t])}),o},n=function(t,e,r){var o=Array.prototype.slice.call(document.querySelectorAll(e));if(-1!==e.indexOf("this")&&o.push(t),o)for(var n=r.split(" "),i=0;i<o.length;i+=1)for(var c=0;c<n.length;c+=1)o[i].classList.toggle(n[c].trim())},i=function(t){"default"===t.currentTarget.getAttribute("data-prevent")&&t.preventDefault();var e=t.currentTarget.getAttribute("data-target").split(","),r=t.currentTarget.getAttribute("data-class").split(",");if(e.length===r.length)e.forEach(function(e,o){n(t.currentTarget,e.trim(),r[o].trim())});else{var o=e.map(function(t){return t.trim()}).join(","),i=r.map(function(t){return t.trim()}).join(" ");n(t.currentTarget,o,i)}};return e.prototype={init:function(){this.selectors=document.querySelectorAll(this.options.selector);for(var t=0;t<this.selectors.length;t+=1){this.selectors[t].addEventListener("click",i)}},destroy:function(){this.selectors=document.querySelectorAll(this.options.selector);for(var t=0;t<this.selectors.length;t+=1){this.selectors[t].removeEventListener("click",i)}}},e});