Changeset 5015
- Timestamp:
- 10/18/07 19:49:41 (1 year ago)
- Files:
-
- trunk/openlayers/lib/Rico/Color.js (modified) (5 diffs)
- trunk/openlayers/lib/Rico/Corner.js (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/lib/Rico/Color.js
r3767 r5015 92 92 var shortHexCode = hexCode; 93 93 var hexCode = '#'; 94 for(var i=1;i<4;i++) hexCode += (shortHexCode.charAt(i) + 95 shortHexCode.charAt(i)); 94 for(var i=1;i<4;i++) { 95 hexCode += (shortHexCode.charAt(i) + 96 shortHexCode.charAt(i)); 97 } 96 98 } 97 if ( hexCode.indexOf('#') == 0 ) 98 hexCode = hexCode.substring(1); 99 if ( hexCode.indexOf('#') == 0 ) { 100 hexCode = hexCode.substring(1); 101 } 99 102 var red = hexCode.substring(0,2); 100 103 var green = hexCode.substring(2,4); 101 104 var blue = hexCode.substring(4,6); 102 105 return new OpenLayers.Rico.Color( parseInt(red,16), parseInt(green,16), parseInt(blue,16) ); 103 } 106 }; 104 107 105 108 /** … … 114 117 "background-color"); 115 118 116 if ( actualColor == "transparent" && elem.parentNode ) 119 if ( actualColor == "transparent" && elem.parentNode ) { 117 120 return OpenLayers.Rico.Color.createColorFromBackground(elem.parentNode); 118 119 if ( actualColor == null ) 121 } 122 if ( actualColor == null ) { 120 123 return new OpenLayers.Rico.Color(255,255,255); 121 124 } 122 125 if ( actualColor.indexOf("rgb(") == 0 ) { 123 126 var colors = actualColor.substring(4, actualColor.length - 1 ); … … 131 134 return OpenLayers.Rico.Color.createFromHex(actualColor); 132 135 } 133 else 136 else { 134 137 return new OpenLayers.Rico.Color(255,255,255); 135 } 138 } 139 }; 136 140 137 141 OpenLayers.Rico.Color.HSBtoRGB = function(hue, saturation, brightness) { … … 188 192 189 193 return { r : parseInt(red), g : parseInt(green) , b : parseInt(blue) }; 190 } 194 }; 191 195 192 196 OpenLayers.Rico.Color.RGBtoHSB = function(r, g, b) { … … 197 201 198 202 var cmax = (r > g) ? r : g; 199 if (b > cmax) 203 if (b > cmax) { 200 204 cmax = b; 201 205 } 202 206 var cmin = (r < g) ? r : g; 203 if (b < cmin) 207 if (b < cmin) { 204 208 cmin = b; 205 209 } 206 210 brightness = cmax / 255.0; 207 if (cmax != 0) 211 if (cmax != 0) { 208 212 saturation = (cmax - cmin)/cmax; 209 else213 } else { 210 214 saturation = 0; 211 212 if (saturation == 0) 215 } 216 if (saturation == 0) { 213 217 hue = 0; 214 else {218 } else { 215 219 var redc = (cmax - r)/(cmax - cmin); 216 220 var greenc = (cmax - g)/(cmax - cmin); 217 221 var bluec = (cmax - b)/(cmax - cmin); 218 222 219 if (r == cmax) 223 if (r == cmax) { 220 224 hue = bluec - greenc; 221 else if (g == cmax)225 } else if (g == cmax) { 222 226 hue = 2.0 + redc - bluec; 223 else227 } else { 224 228 hue = 4.0 + greenc - redc; 225 229 } 226 230 hue = hue / 6.0; 227 if (hue < 0) 231 if (hue < 0) { 228 232 hue = hue + 1.0; 233 } 229 234 } 230 235 231 236 return { h : hue, s : saturation, b : brightness }; 232 } 233 237 }; 238 trunk/openlayers/lib/Rico/Corner.js
r3829 r5015 18 18 OpenLayers.Rico.Corner = { 19 19 20 round: function(e, options) {21 e = OpenLayers.Util.getElement(e);22 this._setOptions(options);23 24 var color = this.options.color;25 if ( this.options.color == "fromElement" )26 color = this._background(e);27 28 var bgColor = this.options.bgColor;29 if ( this.options.bgColor == "fromParent" )30 bgColor = this._background(e.offsetParent);31 32 this._roundCornersImpl(e, color, bgColor);33 },20 round: function(e, options) { 21 e = OpenLayers.Util.getElement(e); 22 this._setOptions(options); 23 24 var color = this.options.color; 25 if ( this.options.color == "fromElement" ) { 26 color = this._background(e); 27 } 28 var bgColor = this.options.bgColor; 29 if ( this.options.bgColor == "fromParent" ) { 30 bgColor = this._background(e.offsetParent); 31 } 32 this._roundCornersImpl(e, color, bgColor); 33 }, 34 34 35 35 /** This is a helper function to change the background … … 108 108 109 109 _roundCornersImpl: function(e, color, bgColor) { 110 if(this.options.border) 110 if(this.options.border) { 111 111 this._renderBorder(e,bgColor); 112 if(this._isTopRounded()) 112 } 113 if(this._isTopRounded()) { 113 114 this._roundTopCorners(e,color,bgColor); 114 if(this._isBottomRounded()) 115 } 116 if(this._isBottomRounded()) { 115 117 this._roundBottomCorners(e,color,bgColor); 118 } 116 119 }, 117 120 … … 121 124 var borderR = "border-right: " + borderValue; 122 125 var style = "style='" + borderL + ";" + borderR + "'"; 123 el.innerHTML = "<div " + style + ">" + el.innerHTML + "</div>" 126 el.innerHTML = "<div " + style + ">" + el.innerHTML + "</div>"; 124 127 }, 125 128 126 129 _roundTopCorners: function(el, color, bgColor) { 127 130 var corner = this._createCorner(bgColor); 128 for(var i=0 ; i < this.options.numSlices ; i++ ) 131 for(var i=0 ; i < this.options.numSlices ; i++ ) { 129 132 corner.appendChild(this._createCornerSlice(color,bgColor,i,"top")); 133 } 130 134 el.style.paddingTop = 0; 131 135 el.insertBefore(corner,el.firstChild); … … 134 138 _roundBottomCorners: function(el, color, bgColor) { 135 139 var corner = this._createCorner(bgColor); 136 for(var i=(this.options.numSlices-1) ; i >= 0 ; i-- ) 140 for(var i=(this.options.numSlices-1) ; i >= 0 ; i-- ) { 137 141 corner.appendChild(this._createCornerSlice(color,bgColor,i,"bottom")); 142 } 138 143 el.style.paddingBottom = 0; 139 144 el.appendChild(corner); … … 172 177 } 173 178 174 if ( !this.options.compact && (n == (this.options.numSlices-1)) ) 179 if ( !this.options.compact && (n == (this.options.numSlices-1)) ) { 175 180 inStyle.height = "2px"; 176 181 } 177 182 this._setMargin(slice, n, position); 178 183 this._setBorder(slice, n, position); … … 188 193 border : false, 189 194 compact : false 190 } 195 }; 191 196 OpenLayers.Util.extend(this.options, options || {}); 192 197 193 198 this.options.numSlices = this.options.compact ? 2 : 4; 194 if ( this._isTransparent() ) 199 if ( this._isTransparent() ) { 195 200 this.options.blend = false; 201 } 196 202 }, 197 203 198 204 _whichSideTop: function() { 199 if ( this._hasString(this.options.corners, "all", "top") ) 200 return ""; 201 202 if ( this.options.corners.indexOf("tl") >= 0 && this.options.corners.indexOf("tr") >= 0 ) 203 return ""; 204 205 if (this.options.corners.indexOf("tl") >= 0) 205 if ( this._hasString(this.options.corners, "all", "top") ) { 206 return ""; 207 } 208 if ( this.options.corners.indexOf("tl") >= 0 && this.options.corners.indexOf("tr") >= 0 ) { 209 return ""; 210 } 211 if (this.options.corners.indexOf("tl") >= 0) { 206 212 return "left"; 207 else if (this.options.corners.indexOf("tr") >= 0)213 } else if (this.options.corners.indexOf("tr") >= 0) { 208 214 return "right"; 215 } 209 216 return ""; 210 217 }, 211 218 212 219 _whichSideBottom: function() { 213 if ( this._hasString(this.options.corners, "all", "bottom") ) 214 return ""; 215 216 if ( this.options.corners.indexOf("bl")>=0 && this.options.corners.indexOf("br")>=0 ) 217 return ""; 218 219 if(this.options.corners.indexOf("bl") >=0) 220 if ( this._hasString(this.options.corners, "all", "bottom") ) { 221 return ""; 222 } 223 if ( this.options.corners.indexOf("bl")>=0 && this.options.corners.indexOf("br")>=0 ) { 224 return ""; 225 } 226 227 if(this.options.corners.indexOf("bl") >=0) { 220 228 return "left"; 221 else if(this.options.corners.indexOf("br")>=0)229 } else if(this.options.corners.indexOf("br")>=0) { 222 230 return "right"; 231 } 223 232 return ""; 224 233 }, 225 234 226 235 _borderColor : function(color,bgColor) { 227 if ( color == "transparent" ) 236 if ( color == "transparent" ) { 228 237 return bgColor; 229 else if ( this.options.border )238 } else if ( this.options.border ) { 230 239 return this.options.border; 231 else if ( this.options.blend )240 } else if ( this.options.blend ) { 232 241 return this._blend( bgColor, color ); 233 else 234 return ""; 242 } else { 243 return ""; 244 } 235 245 }, 236 246 … … 263 273 el.style.borderLeftWidth = borderSize + "px"; el.style.borderRightWidth = borderSize + "px"; 264 274 } 265 if (this.options.border != false) 275 if (this.options.border != false) { 266 276 el.style.borderLeftWidth = borderSize + "px"; el.style.borderRightWidth = borderSize + "px"; 277 } 267 278 }, 268 279 269 280 _marginSize: function(n) { 270 if ( this._isTransparent() ) 281 if ( this._isTransparent() ) { 271 282 return 0; 272 283 } 273 284 var marginSizes = [ 5, 3, 2, 1 ]; 274 285 var blendedMarginSizes = [ 3, 2, 1, 0 ]; … … 276 287 var smBlendedMarginSizes = [ 1, 0 ]; 277 288 278 if ( this.options.compact && this.options.blend ) 289 if ( this.options.compact && this.options.blend ) { 279 290 return smBlendedMarginSizes[n]; 280 else if ( this.options.compact )291 } else if ( this.options.compact ) { 281 292 return compactMarginSizes[n]; 282 else if ( this.options.blend )293 } else if ( this.options.blend ) { 283 294 return blendedMarginSizes[n]; 284 else295 } else { 285 296 return marginSizes[n]; 297 } 286 298 }, 287 299 … … 292 304 var actualBorderSizes = [ 0, 2, 0, 0 ]; 293 305 294 if ( this.options.compact && (this.options.blend || this._isTransparent()) ) 306 if ( this.options.compact && (this.options.blend || this._isTransparent()) ) { 295 307 return 1; 296 else if ( this.options.compact )308 } else if ( this.options.compact ) { 297 309 return compactBorderSizes[n]; 298 else if ( this.options.blend )310 } else if ( this.options.blend ) { 299 311 return blendedBorderSizes[n]; 300 else if ( this.options.border )312 } else if ( this.options.border ) { 301 313 return actualBorderSizes[n]; 302 else if ( this._isTransparent() )314 } else if ( this._isTransparent() ) { 303 315 return transparentBorderSizes[n]; 316 } 304 317 return 0; 305 318 }, 306 319 307 _hasString: function(str) { for(var i=1 ; i<arguments.length ; i++) if (str.indexOf(arguments[i]) >= 0) return true;return false; },320 _hasString: function(str) { for(var i=1 ; i<arguments.length ; i++) if (str.indexOf(arguments[i]) >= 0) { return true; } return false; }, 308 321 _blend: function(c1, c2) { var cc1 = OpenLayers.Rico.Color.createFromHex(c1); cc1.blend(OpenLayers.Rico.Color.createFromHex(c2)); return cc1; }, 309 322 _background: function(el) { try { return OpenLayers.Rico.Color.createColorFromBackground(el).asHex(); } catch(err) { return "#ffffff"; } }, … … 312 325 _isBottomRounded: function() { return this._hasString(this.options.corners, "all", "bottom", "bl", "br"); }, 313 326 _hasSingleTextChild: function(el) { return el.childNodes.length == 1 && el.childNodes[0].nodeType == 3; } 314 } 327 };
