forked from huangtianle/201712
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutils.min.js
1 lines (1 loc) · 2.22 KB
/
utils.min.js
1
var utils=function(){function children(a,b){var d,e,c=[];for(c=isCompatible?toArray(a.children):toArray(a.childNodes),d=0;d<c.length;d++)e=c[d],1===e.nodeType?b&&b.toLowerCase()!==e.tagName.toLowerCase()&&(c.splice(d,1),d--):(c.splice(d,1),d--);return c}function getElementsByClassName(a,b){var c,d,e,f,g,h;if(0===arguments.length)return[];if(b=b||document,isCompatible)return toArray(b.getElementsByClassName(a));for(c=toArray(b.getElementsByTagName("*")),d=a.replace(/^ +| +$/g,"").split(/ +/),e=0;e<d.length;e++)for(f=d[e],g=new RegExp("(^| +)"+f+"( +|$)"),h=0;h<c.length;h++)g.test(c[h].className)||(c.splice(h,1),h--);return c}function getCss(a,b){var c=null,d=null;if(isCompatible)c=window.getComputedStyle(a,null)[b];else{if("opacity"===b)return c=a.currentStyle["filter"],d=/^alpha\(opacity=(.+)\)$/i,d.test(c)?d.exec(c)[1]/100:1;c=a.currentStyle[b]}return d=/^-?\d+(.\d+)?(pt|px|rem|em)?$/i,d.test(c)?parseFloat(c):c}function setCss(a,b,c){return"opacity"===b?(a.style.opacity=c,a.style.filter="alpha(opacity="+100*c+")",void 0):(isNaN(c)||/(fontWeight|lineHeight|zoom|zIndex)/i.test(b)?null:c+="px",a.style[b]=c,void 0)}function setGroupCss(a,b){if("[object Object]"===Object.prototype.toString.call(b))for(var c in b)b.hasOwnProperty(c)&&setCss(a,c,b[c])}function css(){var a=arguments.length,b=Object.prototype.toString.call(arguments[1]),c=getCss;return a>=3?c=setCss:2===a&&"[object Object]"===b?c=setGroupCss:null,c.apply(this,arguments)}var isCompatible="getElementsByClassName"in document,isSupportJSON="JSON"in window,toArray=function(a){var c,b=[];if(isCompatible)b=Array.prototype.slice.call(a);else for(c=0;c<a.length;c++)b[b.length]=a[c];return b},toJSON=function(str){return isSupportJSON?JSON.parse(str):eval("("+str+")")},offset=function(a){for(var b=a.offsetLeft,c=a.offsetTop,d=a.offsetParent;"BODY"!==d.tagName;)isCompatible===!1&&isSupportJSON===!0&&(b+=d.clientLeft,c+=d.clientTop),b+=d.offsetLeft,c+=d.offsetTop,d=d.offsetParent;return{left:b,top:c}},winBox=function(a,b){return"undefined"!=typeof b?(document.documentElement[a]=b,document.body[a]=b,void 0):document.documentElement[a]||document.body[a]};return{toArray:toArray,toJSON:toJSON,offset:offset,winBox:winBox,children:children,getElementsByClassName:getElementsByClassName,css:css}}();