1/* Nifty Corners Cube - rounded corners with CSS and Javascript 2Copyright 2006 Alessandro Fulciniti ([email protected]) 3 4This program is free software; you can redistribute it and/or modify 5it under the terms of the GNU General Public License as published by 6the Free Software Foundation; either version 2 of the License, or 7(at your option) any later version. 8 9This program is distributed in the hope that it will be useful, 10but WITHOUT ANY WARRANTY; without even the implied warranty of 11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12GNU General Public License for more details. 13 14You should have received a copy of the GNU General Public License 15along with this program; if not, write to the Free Software 16Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 19var niftyOk = (document.getElementById && document.createElement && Array.prototype.push); 20var niftyCss = false; 21 22String.prototype.find = function(what) { 23 return (this.indexOf(what) >= 0 ? true : false); 24}; 25 26var oldonload = window.onload; 27if (typeof (NiftyLoad) != 'function') 28 NiftyLoad = function() { 29 }; 30if (typeof (oldonload) == 'function') { 31 window.onload = function() { 32 oldonload(); 33 AddCss(); 34 NiftyLoad() 35 }; 36} else { 37 window.onload = function() { 38 AddCss(); 39 NiftyLoad() 40 }; 41}; 42 43function AddCss() { 44 niftyCss = true; 45 var l = CreateEl("link"); 46 l.setAttribute("type", "text/css"); 47 l.setAttribute("rel", "stylesheet"); 48 var url = new String( 49 ((window.WAROOT_URL != null) ? window.WAROOT_URL : '') 50 + ((window.CONF_ON_WEBASYST != null && window.CONF_ON_WEBASYST) ? '' 51 : 'published/') 52 + "common/html/cssbased/geometry/rounded/niftyCorners.css"); 53 l.setAttribute("href", url); 54 l.setAttribute("media", "screen"); 55 document.getElementsByTagName("head")[0].appendChild(l); 56}; 57 58function Nifty(selector, options) { 59 if (niftyOk == false) 60 return; 61 if (niftyCss == false) 62 AddCss(); 63 var i, v = selector.split(","), h = 0; 64 if (options == null) 65 options = ""; 66 if (options.find("fixed-height")) 67 try { 68 h = getElementsBySelector(v[0])[0].offsetHeight; 69 } catch (e) { 70 h = 0; 71 } 72 for (i = 0; i < v.length; i++) 73 Rounded(v[i], options); 74 if (options.find("height")) 75 SameHeight(selector, h); 76}; 77 78function Rounded(selector, options) { 79 var i, top = "", bottom = "", v = new Array(); 80 if (options != "") { 81 options = options.replace("left", "tl bl"); 82 options = options.replace("right", "tr br"); 83 options = options.replace("top", "tr tl"); 84 options = options.replace("bottom", "br bl"); 85 options = options.replace("transparent", "alias"); 86 if (options.find("tl")) { 87 top = "both"; 88 if (!options.find("tr")) 89 top = "left"; 90 } else if (options.find("tr")) 91 top = "right"; 92 if (options.find("bl")) { 93 bottom = "both"; 94 if (!options.find("br")) 95 bottom = "left"; 96 } else if (options.find("br")) 97 bottom = "right"; 98 } 99 if (top == "" && bottom == "" && !options.find("none")) { 100 top = "both"; 101 bottom = "both"; 102 } 103 v = getElementsBySelector(selector); 104 for (i = 0; i < v.length; i++) { 105 FixIE(v[i]); 106 if (top != "") 107 AddTop(v[i], top, options); 108 if (bottom != "") 109 AddBottom(v[i], bottom, options); 110 } 111}; 112 113function AddTop(el, side, options) { 114 var d = CreateEl("b"), lim = 4, border = "", p, i, btype = "r", bk, color; 115 d.style.marginLeft = "-" + getPadding(el, "Left") + "px"; 116 d.style.marginRight = "-" + getPadding(el, "Right") + "px"; 117 if (options.find("alias") || (color = getBk(el)) == "transparent") { 118 color = "transparent"; 119 bk = "transparent"; 120 border = getParentBk(el); 121 btype = "t"; 122 } else { 123 bk = getParentBk(el); 124 border = Mix(color, bk); 125 } 126 d.style.background = bk; 127 d.className = "niftycorners"; 128 p = getPadding(el, "Top"); 129 if (options.find("small")) { 130 d.style.marginBottom = (p - 2) + "px"; 131 btype += "s"; 132 lim = 2; 133 } else if (options.find("big")) { 134 d.style.marginBottom = (p - 10) + "px"; 135 btype += "b"; 136 lim = 8; 137 } else 138 d.style.marginBottom = (p - 5) + "px"; 139 for (i = 1; i <= lim; i++) 140 d.appendChild(CreateStrip(i, side, color, border, btype)); 141 el.style.paddingTop = "0"; 142 el.insertBefore(d, el.firstChild); 143}; 144 145function AddBottom(el, side, options) { 146 var d = CreateEl("b"), lim = 4, border = "", p, i, btype = "r", bk, color; 147 d.style.marginLeft = "-" + getPadding(el, "Left") + "px"; 148 d.style.marginRight = "-" + getPadding(el, "Right") + "px";
149 if (options.find("alias") || (color = getBk(el)) == "transparent") { 150 color = "transparent"; 151 bk = "transparent"; 152 border = getParentBk(el); 153 btype = "t"; 154 } else { 155 bk = getParentBk(el); 156 border = Mix(color, bk); 157 } 158 d.style.background = bk; 159 d.className = "niftycorners"; 160 p = getPadding(el, "Bottom"); 161 if (options.find("small")) { 162 d.style.marginTop = (p - 2) + "px"; 163 btype += "s"; 164 lim = 2; 165 } else if (options.find("big")) { 166 d.style.marginTop = (p - 10) + "px"; 167 btype += "b"; 168 lim = 8; 169 } else 170 d.style.marginTop = (p - 5) + "px"; 171 for (i = lim; i > 0; i--) 172 d.appendChild(CreateStrip(i, side, color, border, btype)); 173 el.style.paddingBottom = 0; 174 el.appendChild(d); 175}; 176 177function CreateStrip(index, side, color, border, btype) { 178 var x = CreateEl("b"); 179 x.className = btype + index; 180 x.style.backgroundColor = color; 181 x.style.borderColor = border; 182 if (side == "left") { 183 x.style.borderRightWidth = "0"; 184 x.style.marginRight = "0"; 185 } else if (side == "right") { 186 x.style.borderLeftWidth = "0"; 187 x.style.marginLeft = "0"; 188 } 189 return (x); 190}; 191 192function CreateEl(x) { 193 return (document.createElement(x)); 194}; 195 196function FixIE(el) { 197 if (el.currentStyle != null && el.currentStyle.hasLayout != null 198 && el.currentStyle.hasLayout == false) 199 el.style.display = "inline-block"; 200}; 201 202function SameHeight(selector, maxh) { 203 var i, v = selector.split(","), t, j, els = [], gap; 204 for (i = 0; i < v.length; i++) { 205 t = getElementsBySelector(v[i]); 206 els = els.concat(t); 207 } 208 for (i = 0; i < els.length; i++) { 209 if (els[i].offsetHeight > maxh) 210 maxh = els[i].offsetHeight; 211 els[i].style.height = "auto"; 212 } 213 for (i = 0; i < els.length; i++) { 214 gap = maxh - els[i].offsetHeight; 215 if (gap > 0) { 216 t = CreateEl("b"); 217 t.className = "niftyfill"; 218 t.style.height = gap + "px"; 219 nc = els[i].lastChild; 220 if (nc.className == "niftycorners") 221 els[i].insertBefore(t, nc); 222 else 223 els[i].appendChild(t); 224 } 225 } 226}; 227 228function getElementsBySelector(selector) { 229 var i, j, selid = "", selclass = "", tag = selector, tag2 = "", v2, k, f, a, s = [], objlist = [], c; 230 if (selector.find("#")) { // id selector like "tag#id" 231 if (selector.find(" ")) { // descendant selector like "tag#id tag" 232 s = selector.split(" "); 233 var fs = s[0].split("#"); 234 if (fs.length == 1) 235 return (objlist); 236 f = document.getElementById(fs[1]); 237 if (f) { 238 v = f.getElementsByTagName(s[1]); 239 for (i = 0; i < v.length; i++) 240 objlist.push(v[i]); 241 } 242 return (objlist); 243 } else { 244 s = selector.split("#"); 245 tag = s[0]; 246 selid = s[1]; 247 if (selid != "") { 248 f = document.getElementById(selid); 249 if (f) 250 objlist.push(f); 251 return (objlist); 252 } 253 } 254 } 255 if (selector.find(".")) { // class selector like "tag.class" 256 s = selector.split("."); 257 tag = s[0]; 258 selclass = s[1]; 259 if (selclass.find(" ")) { // descendant selector like tag1.classname 260 // tag2 261 s = selclass.split(" "); 262 selclass = s[0]; 263 tag2 = s[1]; 264 } 265 } 266 var v = document.getElementsByTagName(tag); // tag selector like "tag" 267 if (selclass == "") { 268 for (i = 0; i < v.length; i++) 269 objlist.push(v[i]); 270 return (objlist); 271 } 272 for (i = 0; i < v.length; i++) { 273 c = v[i].className.split(" "); 274 for (j = 0; j < c.length; j++) { 275 if (c[j] == selclass) { 276 if (tag2 == "") 277 objlist.push(v[i]); 278 else { 279 v2 = v[i].getElementsByTagName(tag2); 280 for (k = 0; k < v2.length; k++) 281 objlist.push(v2[k]); 282 } 283 } 284 } 285 } 286 return (objlist); 287}; 288 289function getParentBk(x) { 290 var el = x.parentNode, c; 291 while (el.tagName.toUpperCase() != "HTML" 292 && (c = getBk(el)) == "transparent") 293 el = el.parentNode; 294 if (c == "transparent") 295 c = "#FFFFFF"; 296 if (c == "white") 297 c = "#FFFFFF"; 298 return (c); 299}; 300 301function getBk(x) { 302 var c = getStyleProp(x, "backgroundColor"); 303 if (c == null || c == "transparent" || c.find("rgba(0, 0, 0, 0)")) 304 return ("transparent"); 305 if (c.find("rgb")) 306 c = rgb2hex(c); 307 return (c); 308}; 309 310function getPadding(x, side) { 311 var p = getStyleProp(x, "padding" + side); 312 if (p == null || !p.find("px")) 313 return (0);
314 return (parseInt(p)); 315}; 316 317function getStyleProp(x, prop) { 318 if (x.currentStyle) 319 return (x.currentStyle[prop]); 320 if (document.defaultView.getComputedStyle) 321 return (document.defaultView.getComputedStyle(x, '')[prop]); 322 return (null); 323}; 324 325function rgb2hex(value) { 326 var hex = "", v, h, i; 327 var regexp = /([0-9]+)[, ]+([0-9]+)[, ]+([0-9]+)/; 328 var h = regexp.exec(value); 329 for (i = 1; i < 4; i++) { 330 v = parseInt(h[i]).toString(16); 331 if (v.length == 1) 332 hex += "0" + v; 333 else 334 hex += v; 335 } 336 return ("#" + hex); 337}; 338 339function Mix(c1, c2) { 340 341 var i, step1, step2, x, y, r = new Array(3); 342 if (c1.length == 4) 343 step1 = 1; 344 else 345 step1 = 2; 346 if (c2.length == 4) 347 step2 = 1; 348 else 349 step2 = 2; 350 for (i = 0; i < 3; i++) { 351 x = parseInt(c1.substr(1 + step1 * i, step1), 16); 352 if (step1 == 1) 353 x = 16 * x + x; 354 y = parseInt(c2.substr(1 + step2 * i, step2), 16); 355 if (step2 == 1) 356 y = 16 * y + y; 357 r[i] = Math.floor((x * 50 + y * 50) / 100); 358 r[i] = r[i].toString(16); 359 if (r[i].length == 1) 360 r[i] = "0" + r[i]; 361 } 362 if (r[0] == 'NaN') { 363 // alert(c1+','+c2); 364 } 365 return ("#" + r[0] + r[1] + r[2]); 366};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.