1 --Do not remove this if you are using--
2 Original Author: Remiz Rahnas
3 Original Author URL: http://www.htmlremix.com
4 Published date: 2008/09/24
6 Changes by Nick Fetchak:
7 - IE8 standards mode compatibility
8 - VML elements now positioned behind original box rather than inside of it - should be less prone to breakage
9 Published date : 2009/11/18
12 <public:attach event="oncontentready" onevent="oncontentready('v08vnSVo78t4JfjH')" />
13 <script type="text/javascript">
15 // findPos() borrowed from http://www.quirksmode.org/js/findpos.html
16 function findPos(obj) {
17 var curleft = curtop = 0;
19 if (obj.offsetParent) {
21 curleft += obj.offsetLeft;
22 curtop += obj.offsetTop;
23 } while (obj = obj.offsetParent);
32 function oncontentready(classID) {
33 if (this.className.match(classID)) { return(false); }
35 if (!document.namespaces.v) { document.namespaces.add("v", "urn:schemas-microsoft-com:vml"); }
37 this.className = this.className.concat(' ', classID);
38 var arcSize = Math.min(parseInt(this.currentStyle['-moz-border-radius'] ||
39 this.currentStyle['-webkit-border-radius'] ||
40 this.currentStyle['border-radius'] ||
41 this.currentStyle['-khtml-border-radius']) /
42 Math.min(this.offsetWidth, this.offsetHeight), 1);
43 var fillColor = this.currentStyle.backgroundColor;
44 var fillSrc = this.currentStyle.backgroundImage.replace(/^url\("(.+)"\)$/, '$1');
45 var strokeColor = this.currentStyle.borderColor;
46 var strokeWeight = parseInt(this.currentStyle.borderWidth);
48 if (isNaN(strokeWeight)) {
50 strokeColor = fillColor;
54 this.style.background = 'transparent';
55 this.style.borderColor = 'transparent';
57 // Find which element provides position:relative for the target element (default to BODY)
59 var limit = 100, i = 0;
60 while ((typeof(el) != 'unknown') && (el.currentStyle.position != 'relative') && (el.tagName != 'BODY')) {
61 el = el.parentElement;
63 if (i >= limit) { return(false); }
65 var el_zindex = parseInt(el.currentStyle.zIndex);
66 if (isNaN(el_zindex)) { el_zindex = 0; }
67 //alert('got tag '+ el.tagName +' with pos '+ el.currentStyle.position);
70 'width': this.offsetWidth - strokeWeight,
71 'height': this.offsetHeight - strokeWeight
73 var el_pos = findPos(el);
74 var this_pos = findPos(this);
75 this_pos.y = this_pos.y + (0.5 * strokeWeight) - el_pos.y;
76 this_pos.x = this_pos.x + (0.5 * strokeWeight) - el_pos.x;
78 var rect = document.createElement('v:roundrect');
79 rect.arcsize = arcSize +'px';
80 rect.strokecolor = strokeColor;
81 rect.strokeWeight = strokeWeight +'px';
82 rect.stroked = stroked;
83 rect.style.display = 'block';
84 rect.style.position = 'absolute';
85 rect.style.top = this_pos.y +'px';
86 rect.style.left = this_pos.x +'px';
87 rect.style.width = rect_size.width +'px';
88 rect.style.height = rect_size.height +'px';
89 rect.style.antialias = true;
90 rect.style.zIndex = el_zindex - 1;
92 var fill = document.createElement('v:fill');
93 fill.color = fillColor;
97 rect.appendChild(fill);
100 var css = el.document.createStyleSheet();
101 css.addRule("v\\:roundrect", "behavior: url(#default#VML)");
102 css.addRule("v\\:fill", "behavior: url(#default#VML)");
104 isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
105 // IE6 doesn't support transparent borders, use padding to offset original element
106 if (isIE6 && (strokeWeight > 0)) {
107 this.style.borderStyle = 'none';
108 this.style.paddingTop = parseInt(this.currentStyle.paddingTop || 0) + strokeWeight;
109 this.style.paddingBottom = parseInt(this.currentStyle.paddingBottom || 0) + strokeWeight;
112 if (typeof(window.rounded_elements) == 'undefined') {
113 window.rounded_elements = new Array();
115 if (typeof(window.onresize) == 'function') { window.previous_onresize = window.onresize; }
116 window.onresize = window_resize;
118 this.element.vml = rect;
119 window.rounded_elements.push(this.element);
122 function window_resize() {
123 if (typeof(window.rounded_elements) == 'undefined') { return(false); }
125 for (var i in window.rounded_elements) {
126 var el = window.rounded_elements[i];
128 var strokeWeight = parseInt(el.currentStyle.borderWidth);
129 if (isNaN(strokeWeight)) { strokeWeight = 0; }
131 var parent_pos = findPos(el.vml.parentNode);
132 var pos = findPos(el);
133 pos.y = pos.y + (0.5 * strokeWeight) - parent_pos.y;
134 pos.x = pos.x + (0.5 * strokeWeight) - parent_pos.x;
136 el.vml.style.top = pos.y +'px';
137 el.vml.style.left = pos.x +'px';
140 if (typeof(window.previous_onresize) == 'function') { window.previous_onresize(); }