This repository has been archived by the owner on Dec 31, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
roundrect.min.js
31 lines (31 loc) · 15.3 KB
/
roundrect.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(function(j){function r(a,b){return function(){return b.apply(a||this,arguments)}}function C(a){y?a.call(document):D.push(a)}function E(a,b){var c=a.style.left,d=a.runtimeStyle.left,e=a.currentStyle[b];if(G.test(e))return parseInt(a.currentStyle[b],10);if(H.test(e)){a.runtimeStyle.left=a.currentStyle.left;a.style.left=e;e=a.style.pixelLeft;a.style.left=c;a.runtimeStyle.left=d;return e}return 0}function A(a){var b;if(!a||!a.nodeName||!a.type)return false;b=a.nodeName.toUpperCase();a=a.type.toLowerCase();
return b==="BUTTON"||b==="INPUT"&&(a==="image"||a==="button"||a==="submit"||a==="reset")}function F(a){var b;if(!a||!a.nodeName)return false;b=a.nodeName.toUpperCase();b==="INPUT"&&a.type.toLowerCase();return b==="INPUT"&&(a.type==="text"||a.type==="password")||b==="TEXTAREA"}function w(){var a;if(y)document.detachEvent("onreadystatechange",w);else if(document.readyState==="complete"){document.detachEvent("onreadystatechange",w);if(document.body)for(y=true;a=D.shift();)a.call(document);else setTimeout(w,
13)}}function n(a,b){if(a[t]&&p[a[t]])throw Error("Can\u2019t round already rounded rectangles (use RoundRect.create)");p[a[t]=++I]=this;this.element=a;this.onPropertyChangeProxy=r(this,function(){var c=this,d=window.event.propertyName;setTimeout(function(){c.onPropertyChange.call(c,d)})});this.onStateChangeProxy=r(this,function(){var c=this,d=window.event.type;setTimeout(function(){c.onStateChange.call(c,d)})});this.onVmlStateChangeProxy=r(this,function(){this.onVmlStateChange(window.event.type,
window.event.toElement)});this.events={element:{},container:{}};C(r(this,function(){this.render();b&&this.start()}))}if(window.attachEvent){var s="RoundRect",t=s+(new Date).getTime(),I=0,p={},B=document.documentMode===8,y=false,D=[],u={},G=/^-?\d+(?:px)?$/i,H=/^-?\d/,z=s+"-hover";(function a(){var b;try{B?document.namespaces.add("rr","urn:schemas-microsoft-com:vml","#default#VML"):document.namespaces.add("rr","urn:schemas-microsoft-com:vml")}catch(c){setTimeout(a,10);return}try{document.execCommand("BackgroundImageCache",
false,true)}catch(d){}b=document.createElement("style");document.body.appendChild(b);b.styleSheet.addRule("rr\\:shape","behavior:url(#default#VML);display:inline-block");b.styleSheet.addRule("rr\\:group","behavior:url(#default#VML);display:inline-block");b.styleSheet.addRule("rr\\:fill","behavior:url(#default#VML);display:inline-block")})();document.attachEvent("onreadystatechange",w);(function a(){if(!y){try{document.documentElement.doScroll("left")}catch(b){setTimeout(a);return}w()}})();window.attachEvent("onunload",
function(){for(var a in p)if(p.hasOwnProperty(a))try{p[a].destroy()}catch(b){}p=null});n.expando=t;n.disallowed={BODY:true,TABLE:true,TR:true,TD:true,SELECT:!B,OPTION:true};n.create=function(a,b){var c=a[t],d;if(c&&(d=p[c])){if(b!==j&&d.dynamic!==b)d.dynamic?d.start():d.stop();return d}return new n(a,b)};n.gc=function(){for(var a in p)if(p.hasOwnProperty(a))p[a].element.parentNode||p[a].destroy()};n.processStyleSheets=function(){function a(l){var k,i;for(k=l.rules.length-1;k>=0;--k){i=l.rules[k];
if(i.selectorText.indexOf("."+s+"-hover")!==-1)l.removeRule(k);else i.selectorText.indexOf(":hover")!==-1&&l.addRule(i.selectorText.replace(/:hover/g,"."+s+"-hover"),i.style.cssText,k+1)}}var b,c,d,e,f;b=0;for(c=document.styleSheets.length;b<c;++b)try{f=document.styleSheets[b];if(f.imports){d=0;for(e=f.imports.length;d<e;++d)try{a(f.imports[d])}catch(g){}}a(f)}catch(h){}};n.run=function(a,b){if(a===j)a=true;a&&n.processStyleSheets();C(function(){var c=document.getElementsByTagName("*"),d,e,f,g,h=
s.toUpperCase();for(d=0;d<c.length;++d){e=c[d];f=e.currentStyle;g=e.nodeName.toUpperCase();if(!(e.nodeType!==1||g===h||n.disallowed[g]||e.scopeName==="rr"))if((f["border-radius"]||f["border-top-left-radius"]||f["border-top-right-radius"]||f["border-bottom-right-radius"]||f["border-bottom-left-radius"])!==j||a&&b)n.create(e,a)}})};n.prototype={element:j,container:j,dimensions:j,radii:null,borderWidths:j,vml:j,dynamic:false,backgroundImage:null,originalStyles:j,events:j,addEvent:function(a,b,c){if(this.events[a][b])this.events[a][b].push(c);
else this.events[a][b]=[c];this[a].attachEvent("on"+b,c)},removeEvent:function(a,b,c){var d,e,f,g,h,l;if(a!==j){d={};d[a]=1}else d=this.events;for(f in d)if(d.hasOwnProperty(f)){if(b!==j){a={};a[b]=1}else a=this.events[f];for(g in a)if(a.hasOwnProperty(g)){e=this.events[f][g];h=0;for(l=e.length;h<l;++h)if(e[h]===c){this[f].detachEvent("on"+g,e.splice(h,1)[0]);return}else c===j&&this[f].detachEvent("on"+g,e[h]);c===j&&delete this.events[f][g]}}},destroy:function(a){var b=this.element[t],c;this.removeEvent();
this.element.removeAttribute(t);if(this.vml)for(c in this.vml)if(this.vml.hasOwnProperty(c)){this.vml[c].filler=null;this.vml[c]=null}this.container&&this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container);if(a&&this.originalStyles){for(c in this.originalStyles)if(this.originalStyles.hasOwnProperty(c))this.element.style[c]=this.originalStyles[c];this.element.parentNode.style.width=""}this.element=this.container=null;delete p[b]},start:function(){if(!this.dynamic){this.modifyEvents(true);
this.dynamic=true}},stop:function(){if(this.dynamic){this.modifyEvents(false);this.dynamic=false}},modifyEvents:function(a){var b=this.onStateChangeProxy,c=this.onVmlStateChangeProxy;a=a?"addEvent":"removeEvent";this[a]("element","propertychange",this.onPropertyChangeProxy);this[a]("element","mouseenter",b);this[a]("element","mouseleave",b);this[a]("element","focus",b);this[a]("element","blur",b);this[a]("element","resize",b);this[a]("element","move",b);this[a]("container","mouseover",c);this[a]("container",
"mouseout",c);this[a]("container","click",c)},addClass:function(a){if((" "+this.element.className+" ").indexOf(" "+a+" ")===-1)this.element.className+=" "+a},removeClass:function(a){var b=" "+this.element.className+" ";if(b.indexOf(" "+a+" ")!==-1)this.element.className=b.replace(" "+s+"-hover "," ").replace(/^\s+|\s+$/g,"")},onVmlStateChangeProxy:j,onVmlStateChange:function(a){if(a==="click"&&F(this.element)){a=this.element.createTextRange();a.moveStart("textedit");a.select()}else if(a==="click"&&
A(this.element))this.element.click();else if(a==="click"&&document.activeElement!==this.element&&document.activeElement!==document.body)document.activeElement.blur();else if(a==="mouseover")this.addClass(z);else a==="mouseout"&&this.removeClass(z)},onPropertyChangeProxy:j,onPropertyChange:function(a){var b=this.element.style,c=this.container.style;switch(a){case "style.display":c.display=b.display==="none"?"none":"block";case "style":case "className":case "style.cssText":this.dimensions=this.calculateDimensions();
case "style.border":case "style.borderTop":case "style.borderRight":case "style.borderBottom":case "style.borderLeft":case "style.borderTopWidth":case "style.borderRightWidth":case "style.borderBottomWidth":case "style.borderLeftWidth":case "style.borderWidth":this.borderWidths=this.calculateBorderWidths();case "style.border-radius":case "style.border-top-left-radius":case "style.border-top-right-radius":case "style.border-bottom-right-radius":case "style.border-bottom-left-radius":this.radii=this.calculateRadii();
case "style.padding":case "style.background":case "style.backgroundImage":case "style.backgroundColor":case "style.backgroundPosition":case "style.backgroundRepeat":this.applyVML();break;case "style.borderColor":this.vmlStrokeColor();break;case "style.visibility":c.visibility=b.visibility;break;case "style.filter":this.vmlOpacity();break;case "style.zIndex":c.zIndex=b.zIndex;break}},onStateChangeProxy:j,onStateChange:function(a){if(a==="resize"||a==="move"){a=this.dimensions;this.dimensions=this.calculateDimensions();
if(this.dimensions.width!==a.width||this.dimensions.height!==a.height||this.dimensions.top!==a.top||this.dimensions.left!==a.left){this.vmlOffsets();this.vmlPath()}}else{if(A(this.element))if(a==="mouseenter")this.addClass(z);else a==="mouseleave"&&this.removeClass(z);this.element.runtimeStyle.cssText="";this.dimensions=this.calculateDimensions();this.borderWidths=this.calculateBorderWidths();this.radii=this.calculateRadii();this.applyVML()}},calculateRadii:function(){var a=this.element.currentStyle,
b;if((a["border-radius"]||a["border-top-left-radius"]||a["border-top-right-radius"]||a["border-bottom-right-radius"]||a["border-bottom-left-radius"])===j)return null;b=(a["border-radius"]||"0 0 0 0").split(/\s+\//)[0].replace(/[^0-9\s]/g,"").split(/\s+/);b[0]=(a["border-top-left-radius"]||"").replace(/[^0-9]/g,"")||b[0];b[1]=(a["border-top-right-radius"]||"").replace(/[^0-9]/g,"")||b[1];b[2]=(a["border-bottom-right-radius"]||"").replace(/[^0-9]/g,"")||b[2];b[3]=(a["border-bottom-left-radius"]||"").replace(/[^0-9]/g,
"")||b[3];for(a=0;a<4;++a)b[a]=b[a]===j?+b[Math.max(a-2,0)]:+b[a];if(b[0]+b[1]+b[2]+b[3]===0)return null;return b},calculateDimensions:function(){return{width:this.element.offsetWidth,height:this.element.offsetHeight,left:this.element.offsetLeft,top:this.element.offsetTop}},calculateBorderWidths:function(){var a=this.element.currentStyle;return{top:parseInt(a.borderTopWidth,10)||0,right:parseInt(a.borderRightWidth,10)||0,bottom:parseInt(a.borderBottomWidth,10)||0,left:parseInt(a.borderLeftWidth,10)||
0}},render:function(){var a=this.element,b=a.currentStyle,c=a.nodeName.toUpperCase(),d;if(!(!b||n.disallowed[c]||(this.radii=this.calculateRadii())===null)){a.style.behavior="none";this.originalStyles={zoom:a.style.zoom,position:a.style.position,top:a.style.top,right:a.style.right,bottom:a.style.bottom,left:a.style.left};this.container=document.createElement(s);this.container.runtimeStyle.cssText="behavior:none;position:absolute;margin:0;padding:0;border:0;background:none;";this.container.style.zIndex=
b.zIndex;this.vml={color:null,image:null,stroke:null};for(d in this.vml)if(this.vml.hasOwnProperty(d)){this.vml[d]=document.createElement("rr:shape");this.vml[d].filler=document.createElement("rr:fill");this.vml[d].appendChild(this.vml[d].filler);this.vml[d].stroked=false;this.vml[d].style.position="absolute";this.vml[d].style.zIndex=b.zIndex;this.vml[d].coordorigin="1,1";this.container.appendChild(this.vml[d])}this.vml.image.fillcolor="none";this.vml.image.filler.type="tile";a.parentNode.insertBefore(this.container,
a);(function(){for(var e,f=0,g=arguments.length;f<g;++f){e=arguments[f];e.style.zoom=1;if(e.currentStyle.position==="static"){e.style.position="relative";e.style.top="auto";e.style.right="auto";e.style.bottom="auto";e.style.left="auto"}}})(a.offsetParent,a,this.container);if(c==="IMG")a.style.visibility="hidden";else if(F(a))this.container.style.cursor=b.cursor==="auto"?"text":b.cursor;else if(A(a))this.container.style.cursor=b.cursor==="auto"?"pointer":b.cursor;setTimeout(r(this,function(){this.addEvent("container",
"mouseenter",r(this,function(){var e=document.createEventObject(window.event);e.toElement=e.srcElement=this.element;this.element.fireEvent("on"+window.event.type,e)}));this.addEvent("container","mouseleave",r(this,function(){var e=document.createEventObject(window.event);e.fromElement=e.srcElement=this.element;this.element.fireEvent("on"+window.event.type,e)}));this.dimensions=this.calculateDimensions();this.borderWidths=this.calculateBorderWidths();this.applyVML()}))}},applyVML:function(){if(this.dimensions.width===
0||this.dimensions.height===0)this.dimensions=this.calculateDimensions();if(!(this.dimensions.width===0||this.dimensions.height===0)){this.element.runtimeStyle.cssText="";this.vmlFill();this.vmlStrokeColor();this.vmlOffsets();this.vmlPath();this.padBorder();this.vmlOpacity()}},vmlOpacity:function(){var a,b=this.vml;if(a=/Opacity=([0-9]+)/i.exec(this.element.currentStyle.filter)){a=+a[1]*0.01;for(var c in b)if(b.hasOwnProperty(c))b[c].filler.opacity=a}},vmlStrokeColor:function(){this.vml.stroke.fillcolor=
this.element.currentStyle.borderColor},vmlOffsets:function(){function a(g,h){g.style.left=(h?0:b.left)+"px";g.style.top=(h?0:b.top)+"px";g.style.width=b.width+"px";g.style.height=b.height+"px"}var b=this.dimensions,c,d=this.vml,e,f=this.element.parentNode;for(c in d)if(d.hasOwnProperty(c)){e=c==="image"?1:2;d[c].coordsize=b.width*e+","+b.height*e;a(d[c],true)}a(this.container,false);if(!B&&(f.nodeName.toUpperCase()==="TD"||f.nodeName.toUpperCase()==="TH")){f.style.width="";if(f.currentStyle.width===
"auto")f.style.width=b.width+"px"}},vmlPath:function(){function a(h,l,k,i,o,m,x){var q=h?["m","qy","l","qx","l","qy","l","qx","l"]:["qx","l","qy","l","qx","l","qy","l","m"];i=i.slice();var v;o*=x;m*=x;l*=x;k*=x;for(v=0;v<4;++v){i[v]*=x;i[v]=Math.min(l*0.5,k*0.5,i[v])}l=[q[0]+Math.floor(0+o)+","+Math.floor(i[0]+m),q[1]+Math.floor(i[0]+o)+","+Math.floor(0+m),q[2]+Math.ceil(l-i[1]+o)+","+Math.floor(0+m),q[3]+Math.ceil(l+o)+","+Math.floor(i[1]+m),q[4]+Math.ceil(l+o)+","+Math.ceil(k-i[2]+m),q[5]+Math.ceil(l-
i[2]+o)+","+Math.ceil(k+m),q[6]+Math.floor(i[3]+o)+","+Math.ceil(k+m),q[7]+Math.floor(0+o)+","+Math.ceil(k-i[3]+m),q[8]+Math.floor(0+o)+","+Math.floor(i[0]+m)];h||l.reverse();return l.join("")}var b=this.borderWidths,c=this.dimensions,d=this.radii.slice(),e=this.vml,f;if(b===j)b=this.calculateBorderWidths();var g=a(true,c.width,c.height,d,0,0,2);d[0]-=Math.max(b.left,b.top);d[1]-=Math.max(b.top,b.right);d[2]-=Math.max(b.right,b.bottom);d[3]-=Math.max(b.bottom,b.left);for(f=0;f<4;++f)d[f]=Math.max(d[f],
0);f=a(false,c.width-b.left-b.right,c.height-b.top-b.bottom,d,b.left,b.top,2);b=a(true,c.width-b.left-b.right+1,c.height-b.top-b.bottom+1,d,b.left,b.top,1);e.color.path=f;e.image.path=b;e.stroke.path=g+f;this.clipImage()},padBorder:function(){var a=this.element,b=["Top","Right","Bottom","Left"],c;for(c=0;c<4;++c)a.runtimeStyle["padding"+b[c]]=E(a,"padding"+b[c])+E(a,"border"+b[c]+"Width")+"px";a.runtimeStyle.border="none"},vmlFill:function(){var a=this.element,b=a.currentStyle,c=this.element.tagName.toUpperCase()===
"IMG",d=this.vml,e;a.runtimeStyle.backgroundColor="";a.runtimeStyle.backgroundImage="";if(c||b.backgroundImage!=="none"){this.backgroundImage=e=c?a.src:/^url\(["']?\s*(.+?)\s*["']?\)$/.exec(b.backgroundImage)[1];if(u[e]===j){c=new Image;c.attachEvent("onload",r(this,function(){u[e]={width:this.width,height:this.height};this.vmlOffsets()}));c.src=e;u[e]=c}d.image.filler.src=e;c=true}d.image.filled=c;d.image.fillcolor="none";d.color.filled=b.backgroundColor!=="transparent";d.color.fillcolor=b.backgroundColor;
a.runtimeStyle.backgroundImage="none";a.runtimeStyle.backgroundColor="transparent"},clipImage:function(){function a(k,i){var o=true;switch(i){case "left":case "top":g[k]=0;break;case "center":g[k]=0.5;break;case "right":case "bottom":g[k]=1;break;default:if(i.indexOf("%")!==-1)g[k]=parseInt(i,10)*0.01;else o=false;break}var m=k==="X";g[k]=Math.ceil(o?(d[m?"width":"height"]-(e[m?"left":"top"]+e[m?"right":"bottom"]))*g[k]-u[c][m?"width":"height"]*g[k]:parseInt(i,10));g[k]+=1}var b=this.element.currentStyle,
c=this.backgroundImage,d=this.calculateDimensions(),e=this.calculateBorderWidths(),f=this.vml;if(!(c===j||u[c]===j)){var g={X:0,Y:0};for(var h in g)g.hasOwnProperty(h)&&a(h,b["backgroundPosition"+h]);f.image.filler.position=g.X/(d.width-e.left-e.right+1)+","+g.Y/(d.height-e.top-e.bottom+1);h={T:1,R:d.width+1,B:d.height+1,L:1};var l={X:{b1:"L",b2:"R",d:"Width"},Y:{b1:"T",b2:"B",d:"Height"}};if(b.backgroundRepeat!=="repeat"){h={T:g.Y,R:g.X+u[c].width,B:g.Y+u[c].height,L:g.X};if(b.backgroundRepeat.indexOf("repeat-")!==
-1){b=b.backgroundRepeat.split("repeat-")[1].toUpperCase();h[l[b].b1]=1;h[l[b].b2]=d[l[b].d.toLowerCase()]+1}}f.image.style.clip="rect("+h.T+"px "+h.R+"px "+h.B+"px "+h.L+"px)"}}};window[s]=n}})();