-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetcssfilter.min.js
More file actions
8 lines (8 loc) · 2.35 KB
/
Copy pathsetcssfilter.min.js
File metadata and controls
8 lines (8 loc) · 2.35 KB
1
2
3
4
5
6
7
8
/*!
* VERSION: 0.1.1
* DATE: 2015-09-27
*
* Copyright 2015, Jean Paze (@jpaze)
* Released under MIT license
*/
!function(a,b){var c=b();"object"==typeof exports?module.exports=c:"function"==typeof define&&define.amd?define([],function(){return a.returnExportsGlobal=c}):a.setCSSFilter=c}(this,function(){function b(a){for(var b=c(a.target,a.prop).split(" "),d="drop-shadow"==a.remove,e="",f=0;f<b.length;f++){var g="-"==b[f].substr(0,1)||!isNaN(b[f].substr(0,1)),h=f<b.length-1?" ":"",i=new RegExp(a.remove);i.test(b[f])?(!d&&g&&(b[f-1]+=" "+b[f],b.splice(f,1),f--),e+="[REPLACE]"+h):d&&g?(b.splice(f,1),f--):e+=b[f]+h}return"none"==e?"":e}function c(a,b){return a.currentStyle?a.currentStyle[b]:document.defaultView&&document.defaultView.getComputedStyle?document.defaultView.getComputedStyle(a,"")[b]:a.style[b]}var a=function(c,d){if(c.length)for(var e=0;e<c.length;e++)a(c[e],d);else{var n,f=window.getComputedStyle(document.documentElement,""),g=(Array.prototype.slice.call(f).join("").match(/-(moz|webkit|ms)-/)||""===f.OLink&&["","o"])[1],h="webkit"===g?"-webkit-filter":"filter",i=100*d.progress>>0,j="drop-shadow"!=d.filter,k=j?Math.abs(d.start-d.end)/100*i:0,l=j?d.start<d.end?d.start+k:d.start-k:0,m=b({target:c,remove:d.filter,prop:h}),o="blur"==d.filter?"px":"";if(o="hue-rotate"==d.filter?"deg":o,o="hue-rotate"!=d.filter&&"blur"!=d.filter?"%":o,j)n=d.filter+"("+l+o+")";else{var p=d.start[0],q=d.start[1],r=d.start[2],s=d.start[3]||"#000000",t=d.start[4]||0,u=d.end[0],v=d.end[1],w=d.end[2],x=d.end[3]||"#000000",y=d.end[4]||0,z=p+Math.abs(p-u)/100*i;z=p>u?p-Math.abs(p-u)/100*i:z;var A=q+Math.abs(q-v)/100*i;A=q>v?q-Math.abs(q-v)/100*i:A;var B=r+Math.abs(r-w)/100*i;B=r>w?r-Math.abs(r-w)/100*i:B;var C=t+Math.abs(t-y)/100*i;C=t>y?t-Math.abs(t-y)/100*i:C;var D=parseInt(s.substring(1,3),16),E=parseInt(s.substring(3,5),16),F=parseInt(s.substring(5,7),16),G=parseInt(x.substring(1,3),16),H=parseInt(x.substring(3,5),16),I=parseInt(x.substring(5,7),16),J=parseInt(D+Math.abs(D-G)/100*i);J=D>G?parseInt(D-Math.abs(D-G)/100*i):J,J=255>J?J:255;var K=parseInt(E+Math.abs(E-H)/100*i);K=E>H?parseInt(E-Math.abs(E-H)/100*i):K,K=255>K?K:255;var L=parseInt(F+Math.abs(F-I)/100*i);L=F>I?parseInt(F-Math.abs(F-I)/100*i):L,L=255>L?L:255,n="drop-shadow("+z+"px "+A+"px "+B+"px rgba("+J+","+K+","+L+","+C+") )"}var M=-1!=m.indexOf("[REPLACE]")?m.replace("[REPLACE]",n):n+" "+m;c.style[h]=M}};return a});