-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathmultiple.min.js
5 lines (4 loc) · 2.97 KB
/
multiple.min.js
1
2
3
4
5
/*! Multiple.js - v0.0.1 - 2016-04-09
* http://NeXTs.github.com/Multiple.js/
* Copyright (c) 2015 Denis Lukov; Licensed MIT */
!function(a,b){"undefined"!=typeof module?module.exports=b():"function"==typeof define&&"object"==typeof define.amd?define(b):a.Multiple=b()}(this,function(){"use strict";var a="ontouchstart"in window||navigator.maxTouchPoints,b="WebkitAppearance"in document.documentElement.style;b&&window.addEventListener("resize",function(a){document.body.style.visibility="hidden",a=document.body.offsetHeight,document.body.style.visibility=""});var c=function(b){return this instanceof c?(["selector","background","affectText","opacity"].forEach(function(a){this[a]=b[a]}.bind(this)),this.className="multiple-"+(a?"mobile":"desktop")+(this.affectText?"-text":""),void this.update(this.background)):new c(b)};return c.prototype={constructor:c,each:function(a,b,c){Array.prototype.slice.call(c?a:document.querySelectorAll(a)).forEach(b.bind(this))},setOpacity:function(a){return a.replace(/#\b([a-f\d]{3}|[a-f\d]{6})\b/gi,function(a,b){var c=b.match(new RegExp("(.{"+b.length/3+"})","g")).map(function(a){return parseInt(b.length%2?a+a:a,16)});return"rgb("+c.join(",")+")"}).replace(/rgb\((.[^\)]*)\)/gi,function(a,b){var c,d=(255-(c=Math.min.apply(Math,b=b.split(","))))/255,e=this.opacity===!0?b.map(function(a){return 0|(a-c)/d}).concat((0|1e3*d)/1e3):b.concat(this.opacity);return"rgba("+e.join(",")+")"}.bind(this))},setVendors:function(a,b){var c=b?[]:[a];return(/-gradient\(/i.test(a)||b)&&["webkit","moz","ms","o"].forEach(function(d,e){b&&e||c.unshift((b?"-webkit-linear-gradient(transparent,transparent),":"")+a.replace(/([^,\s]*-gradient\()/gi,"-"+d+"-$1"))}),c},setStyles:function(a,b,c){this.opacity&&(b=this.setOpacity(b)),this.styleTag.innerHTML=a+"{background-image:"+this.setVendors(b,c).join(";\nbackground-image:")+"}"},renderTag:function(a){var b=document.createElement("div");return b.className=a,b},update:function(b){this.each(this.selector,function(b){if(!b.getAttribute("data-multiple")){if(!a||this.affectText)return b.classList.add(this.className);var c=this.renderTag(this.className+"-wrapper"),d=this.renderTag(this.className+"-content");this.each(b.childNodes,function(a){d.appendChild(a)},!0),b.appendChild(c),c.appendChild(this.renderTag(this.className)),c.appendChild(d),b.setAttribute("data-multiple",!0)}}),b&&(this.styleTag||document.head.appendChild(this.styleTag=document.createElement("style")),a&&this.affectText||this.setStyles(this.selector+(a?" ":"")+"."+this.className+(a?":before":""),b,this.affectText),this.affectText&&(this.styleTag.innerHTML+=this.selector+"."+this.className+"{color:"+this.affectText+"}"))},destroy:function(){this.styleTag.parentNode&&this.styleTag.parentNode.removeChild(this.styleTag)&&delete this.styleTag,this.each(this.selector,function(b){b.classList.remove(this.className),b.removeAttribute("data-multiple"),a&&!this.affectText&&(this.each(b.children[0].children[1].childNodes,function(a){b.appendChild(a)},!0),b.removeChild(b.children[0]))})}},c});