Chloroplast (Talk | contribs) |
Chloroplast (Talk | contribs) |
||
Line 1: | Line 1: | ||
<html> | <html> | ||
+ | <!--lunar.js--> | ||
+ | <script> | ||
+ | (function (root, factory) { | ||
+ | if (typeof define === 'function' && define.amd) { | ||
+ | define(factory); | ||
+ | } else if (typeof exports === 'object') { | ||
+ | module.exports = factory; | ||
+ | } else { | ||
+ | root.lunar = factory(); | ||
+ | } | ||
+ | })(this, function () { | ||
+ | |||
+ | 'use strict'; | ||
+ | |||
+ | var lunar = {}; | ||
+ | |||
+ | lunar.hasClass = function (elem, name) { | ||
+ | return new RegExp('(\\s|^)' + name + '(\\s|$)').test(elem.getAttribute('class')); | ||
+ | }; | ||
+ | |||
+ | lunar.addClass = function (elem, name) { | ||
+ | if(!lunar.hasClass(elem, name)){ | ||
+ | if(elem.setAttribute('class', (!!elem.getAttribute('class') ? elem.getAttribute('class') + ' ' : '') + name)){ | ||
+ | true; | ||
+ | }else{ | ||
+ | false; | ||
+ | } | ||
+ | }else{ | ||
+ | false; | ||
+ | } | ||
+ | }; | ||
+ | |||
+ | lunar.removeClass = function (elem, name) { | ||
+ | var remove = elem.getAttribute('class').replace(new RegExp('(\\s|^)' + name + '(\\s|$)', 'g'), '$2'); | ||
+ | if(lunar.hasClass(elem, name)){ | ||
+ | if(elem.setAttribute('class', remove)){ | ||
+ | true; | ||
+ | }else{ | ||
+ | false; | ||
+ | } | ||
+ | }else{ | ||
+ | false; | ||
+ | } | ||
+ | }; | ||
+ | |||
+ | lunar.toggleClass = function (elem, name) { | ||
+ | lunar[lunar.hasClass(elem, name) ? 'removeClass' : 'addClass'](elem, name); | ||
+ | }; | ||
+ | |||
+ | return lunar; | ||
+ | |||
+ | }); | ||
+ | |||
+ | </script> | ||
<!--imagesloaded.pkgd.min.js--> | <!--imagesloaded.pkgd.min.js--> |
Revision as of 03:53, 4 October 2016