semi-colon and curly brace stuff for the Rico library.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@5015 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Paul Spencer
2007-10-18 23:49:41 +00:00
parent dc6466c621
commit 4a6e180637
2 changed files with 97 additions and 79 deletions
+32 -27
View File
@@ -91,16 +91,19 @@ OpenLayers.Rico.Color.createFromHex = function(hexCode) {
if(hexCode.length==4) { if(hexCode.length==4) {
var shortHexCode = hexCode; var shortHexCode = hexCode;
var hexCode = '#'; var hexCode = '#';
for(var i=1;i<4;i++) hexCode += (shortHexCode.charAt(i) + for(var i=1;i<4;i++) {
shortHexCode.charAt(i)); hexCode += (shortHexCode.charAt(i) +
shortHexCode.charAt(i));
}
} }
if ( hexCode.indexOf('#') == 0 ) if ( hexCode.indexOf('#') == 0 ) {
hexCode = hexCode.substring(1); hexCode = hexCode.substring(1);
}
var red = hexCode.substring(0,2); var red = hexCode.substring(0,2);
var green = hexCode.substring(2,4); var green = hexCode.substring(2,4);
var blue = hexCode.substring(4,6); var blue = hexCode.substring(4,6);
return new OpenLayers.Rico.Color( parseInt(red,16), parseInt(green,16), parseInt(blue,16) ); return new OpenLayers.Rico.Color( parseInt(red,16), parseInt(green,16), parseInt(blue,16) );
} };
/** /**
* Factory method for creating a color from the background of * Factory method for creating a color from the background of
@@ -113,12 +116,12 @@ OpenLayers.Rico.Color.createColorFromBackground = function(elem) {
"backgroundColor", "backgroundColor",
"background-color"); "background-color");
if ( actualColor == "transparent" && elem.parentNode ) if ( actualColor == "transparent" && elem.parentNode ) {
return OpenLayers.Rico.Color.createColorFromBackground(elem.parentNode); return OpenLayers.Rico.Color.createColorFromBackground(elem.parentNode);
}
if ( actualColor == null ) if ( actualColor == null ) {
return new OpenLayers.Rico.Color(255,255,255); return new OpenLayers.Rico.Color(255,255,255);
}
if ( actualColor.indexOf("rgb(") == 0 ) { if ( actualColor.indexOf("rgb(") == 0 ) {
var colors = actualColor.substring(4, actualColor.length - 1 ); var colors = actualColor.substring(4, actualColor.length - 1 );
var colorArray = colors.split(","); var colorArray = colors.split(",");
@@ -130,9 +133,10 @@ OpenLayers.Rico.Color.createColorFromBackground = function(elem) {
else if ( actualColor.indexOf("#") == 0 ) { else if ( actualColor.indexOf("#") == 0 ) {
return OpenLayers.Rico.Color.createFromHex(actualColor); return OpenLayers.Rico.Color.createFromHex(actualColor);
} }
else else {
return new OpenLayers.Rico.Color(255,255,255); return new OpenLayers.Rico.Color(255,255,255);
} }
};
OpenLayers.Rico.Color.HSBtoRGB = function(hue, saturation, brightness) { OpenLayers.Rico.Color.HSBtoRGB = function(hue, saturation, brightness) {
@@ -187,7 +191,7 @@ OpenLayers.Rico.Color.HSBtoRGB = function(hue, saturation, brightness) {
} }
return { r : parseInt(red), g : parseInt(green) , b : parseInt(blue) }; return { r : parseInt(red), g : parseInt(green) , b : parseInt(blue) };
} };
OpenLayers.Rico.Color.RGBtoHSB = function(r, g, b) { OpenLayers.Rico.Color.RGBtoHSB = function(r, g, b) {
@@ -196,38 +200,39 @@ OpenLayers.Rico.Color.RGBtoHSB = function(r, g, b) {
var brightness; var brightness;
var cmax = (r > g) ? r : g; var cmax = (r > g) ? r : g;
if (b > cmax) if (b > cmax) {
cmax = b; cmax = b;
}
var cmin = (r < g) ? r : g; var cmin = (r < g) ? r : g;
if (b < cmin) if (b < cmin) {
cmin = b; cmin = b;
}
brightness = cmax / 255.0; brightness = cmax / 255.0;
if (cmax != 0) if (cmax != 0) {
saturation = (cmax - cmin)/cmax; saturation = (cmax - cmin)/cmax;
else } else {
saturation = 0; saturation = 0;
}
if (saturation == 0) if (saturation == 0) {
hue = 0; hue = 0;
else { } else {
var redc = (cmax - r)/(cmax - cmin); var redc = (cmax - r)/(cmax - cmin);
var greenc = (cmax - g)/(cmax - cmin); var greenc = (cmax - g)/(cmax - cmin);
var bluec = (cmax - b)/(cmax - cmin); var bluec = (cmax - b)/(cmax - cmin);
if (r == cmax) if (r == cmax) {
hue = bluec - greenc; hue = bluec - greenc;
else if (g == cmax) } else if (g == cmax) {
hue = 2.0 + redc - bluec; hue = 2.0 + redc - bluec;
else } else {
hue = 4.0 + greenc - redc; hue = 4.0 + greenc - redc;
}
hue = hue / 6.0; hue = hue / 6.0;
if (hue < 0) if (hue < 0) {
hue = hue + 1.0; hue = hue + 1.0;
}
} }
return { h : hue, s : saturation, b : brightness }; return { h : hue, s : saturation, b : brightness };
} };
+65 -52
View File
@@ -17,20 +17,20 @@
OpenLayers.Rico = new Object(); OpenLayers.Rico = new Object();
OpenLayers.Rico.Corner = { OpenLayers.Rico.Corner = {
round: function(e, options) { round: function(e, options) {
e = OpenLayers.Util.getElement(e); e = OpenLayers.Util.getElement(e);
this._setOptions(options); this._setOptions(options);
var color = this.options.color; var color = this.options.color;
if ( this.options.color == "fromElement" ) if ( this.options.color == "fromElement" ) {
color = this._background(e); color = this._background(e);
}
var bgColor = this.options.bgColor; var bgColor = this.options.bgColor;
if ( this.options.bgColor == "fromParent" ) if ( this.options.bgColor == "fromParent" ) {
bgColor = this._background(e.offsetParent); bgColor = this._background(e.offsetParent);
}
this._roundCornersImpl(e, color, bgColor); this._roundCornersImpl(e, color, bgColor);
}, },
/** This is a helper function to change the background /** This is a helper function to change the background
* color of <div> that has had Rico rounded corners added. * color of <div> that has had Rico rounded corners added.
@@ -107,12 +107,15 @@ OpenLayers.Rico.Corner = {
}, },
_roundCornersImpl: function(e, color, bgColor) { _roundCornersImpl: function(e, color, bgColor) {
if(this.options.border) if(this.options.border) {
this._renderBorder(e,bgColor); this._renderBorder(e,bgColor);
if(this._isTopRounded()) }
if(this._isTopRounded()) {
this._roundTopCorners(e,color,bgColor); this._roundTopCorners(e,color,bgColor);
if(this._isBottomRounded()) }
if(this._isBottomRounded()) {
this._roundBottomCorners(e,color,bgColor); this._roundBottomCorners(e,color,bgColor);
}
}, },
_renderBorder: function(el,bgColor) { _renderBorder: function(el,bgColor) {
@@ -120,21 +123,23 @@ OpenLayers.Rico.Corner = {
var borderL = "border-left: " + borderValue; var borderL = "border-left: " + borderValue;
var borderR = "border-right: " + borderValue; var borderR = "border-right: " + borderValue;
var style = "style='" + borderL + ";" + borderR + "'"; var style = "style='" + borderL + ";" + borderR + "'";
el.innerHTML = "<div " + style + ">" + el.innerHTML + "</div>" el.innerHTML = "<div " + style + ">" + el.innerHTML + "</div>";
}, },
_roundTopCorners: function(el, color, bgColor) { _roundTopCorners: function(el, color, bgColor) {
var corner = this._createCorner(bgColor); var corner = this._createCorner(bgColor);
for(var i=0 ; i < this.options.numSlices ; i++ ) for(var i=0 ; i < this.options.numSlices ; i++ ) {
corner.appendChild(this._createCornerSlice(color,bgColor,i,"top")); corner.appendChild(this._createCornerSlice(color,bgColor,i,"top"));
}
el.style.paddingTop = 0; el.style.paddingTop = 0;
el.insertBefore(corner,el.firstChild); el.insertBefore(corner,el.firstChild);
}, },
_roundBottomCorners: function(el, color, bgColor) { _roundBottomCorners: function(el, color, bgColor) {
var corner = this._createCorner(bgColor); var corner = this._createCorner(bgColor);
for(var i=(this.options.numSlices-1) ; i >= 0 ; i-- ) for(var i=(this.options.numSlices-1) ; i >= 0 ; i-- ) {
corner.appendChild(this._createCornerSlice(color,bgColor,i,"bottom")); corner.appendChild(this._createCornerSlice(color,bgColor,i,"bottom"));
}
el.style.paddingBottom = 0; el.style.paddingBottom = 0;
el.appendChild(corner); el.appendChild(corner);
}, },
@@ -171,9 +176,9 @@ OpenLayers.Rico.Corner = {
inStyle.borderWidth = "0px 1px"; inStyle.borderWidth = "0px 1px";
} }
if ( !this.options.compact && (n == (this.options.numSlices-1)) ) if ( !this.options.compact && (n == (this.options.numSlices-1)) ) {
inStyle.height = "2px"; inStyle.height = "2px";
}
this._setMargin(slice, n, position); this._setMargin(slice, n, position);
this._setBorder(slice, n, position); this._setBorder(slice, n, position);
return slice; return slice;
@@ -187,51 +192,56 @@ OpenLayers.Rico.Corner = {
blend : true, blend : true,
border : false, border : false,
compact : false compact : false
} };
OpenLayers.Util.extend(this.options, options || {}); OpenLayers.Util.extend(this.options, options || {});
this.options.numSlices = this.options.compact ? 2 : 4; this.options.numSlices = this.options.compact ? 2 : 4;
if ( this._isTransparent() ) if ( this._isTransparent() ) {
this.options.blend = false; this.options.blend = false;
}
}, },
_whichSideTop: function() { _whichSideTop: function() {
if ( this._hasString(this.options.corners, "all", "top") ) if ( this._hasString(this.options.corners, "all", "top") ) {
return ""; return "";
}
if ( this.options.corners.indexOf("tl") >= 0 && this.options.corners.indexOf("tr") >= 0 ) if ( this.options.corners.indexOf("tl") >= 0 && this.options.corners.indexOf("tr") >= 0 ) {
return ""; return "";
}
if (this.options.corners.indexOf("tl") >= 0) if (this.options.corners.indexOf("tl") >= 0) {
return "left"; return "left";
else if (this.options.corners.indexOf("tr") >= 0) } else if (this.options.corners.indexOf("tr") >= 0) {
return "right"; return "right";
}
return ""; return "";
}, },
_whichSideBottom: function() { _whichSideBottom: function() {
if ( this._hasString(this.options.corners, "all", "bottom") ) if ( this._hasString(this.options.corners, "all", "bottom") ) {
return ""; return "";
}
if ( this.options.corners.indexOf("bl")>=0 && this.options.corners.indexOf("br")>=0 ) if ( this.options.corners.indexOf("bl")>=0 && this.options.corners.indexOf("br")>=0 ) {
return ""; return "";
}
if(this.options.corners.indexOf("bl") >=0) if(this.options.corners.indexOf("bl") >=0) {
return "left"; return "left";
else if(this.options.corners.indexOf("br")>=0) } else if(this.options.corners.indexOf("br")>=0) {
return "right"; return "right";
}
return ""; return "";
}, },
_borderColor : function(color,bgColor) { _borderColor : function(color,bgColor) {
if ( color == "transparent" ) if ( color == "transparent" ) {
return bgColor; return bgColor;
else if ( this.options.border ) } else if ( this.options.border ) {
return this.options.border; return this.options.border;
else if ( this.options.blend ) } else if ( this.options.blend ) {
return this._blend( bgColor, color ); return this._blend( bgColor, color );
else } else {
return ""; return "";
}
}, },
@@ -262,27 +272,29 @@ OpenLayers.Rico.Corner = {
else { else {
el.style.borderLeftWidth = borderSize + "px"; el.style.borderRightWidth = borderSize + "px"; el.style.borderLeftWidth = borderSize + "px"; el.style.borderRightWidth = borderSize + "px";
} }
if (this.options.border != false) if (this.options.border != false) {
el.style.borderLeftWidth = borderSize + "px"; el.style.borderRightWidth = borderSize + "px"; el.style.borderLeftWidth = borderSize + "px"; el.style.borderRightWidth = borderSize + "px";
}
}, },
_marginSize: function(n) { _marginSize: function(n) {
if ( this._isTransparent() ) if ( this._isTransparent() ) {
return 0; return 0;
}
var marginSizes = [ 5, 3, 2, 1 ]; var marginSizes = [ 5, 3, 2, 1 ];
var blendedMarginSizes = [ 3, 2, 1, 0 ]; var blendedMarginSizes = [ 3, 2, 1, 0 ];
var compactMarginSizes = [ 2, 1 ]; var compactMarginSizes = [ 2, 1 ];
var smBlendedMarginSizes = [ 1, 0 ]; var smBlendedMarginSizes = [ 1, 0 ];
if ( this.options.compact && this.options.blend ) if ( this.options.compact && this.options.blend ) {
return smBlendedMarginSizes[n]; return smBlendedMarginSizes[n];
else if ( this.options.compact ) } else if ( this.options.compact ) {
return compactMarginSizes[n]; return compactMarginSizes[n];
else if ( this.options.blend ) } else if ( this.options.blend ) {
return blendedMarginSizes[n]; return blendedMarginSizes[n];
else } else {
return marginSizes[n]; return marginSizes[n];
}
}, },
_borderSize: function(n) { _borderSize: function(n) {
@@ -291,24 +303,25 @@ OpenLayers.Rico.Corner = {
var compactBorderSizes = [ 1, 0 ]; var compactBorderSizes = [ 1, 0 ];
var actualBorderSizes = [ 0, 2, 0, 0 ]; var actualBorderSizes = [ 0, 2, 0, 0 ];
if ( this.options.compact && (this.options.blend || this._isTransparent()) ) if ( this.options.compact && (this.options.blend || this._isTransparent()) ) {
return 1; return 1;
else if ( this.options.compact ) } else if ( this.options.compact ) {
return compactBorderSizes[n]; return compactBorderSizes[n];
else if ( this.options.blend ) } else if ( this.options.blend ) {
return blendedBorderSizes[n]; return blendedBorderSizes[n];
else if ( this.options.border ) } else if ( this.options.border ) {
return actualBorderSizes[n]; return actualBorderSizes[n];
else if ( this._isTransparent() ) } else if ( this._isTransparent() ) {
return transparentBorderSizes[n]; return transparentBorderSizes[n];
}
return 0; return 0;
}, },
_hasString: function(str) { for(var i=1 ; i<arguments.length ; i++) if (str.indexOf(arguments[i]) >= 0) return true; return false; }, _hasString: function(str) { for(var i=1 ; i<arguments.length ; i++) if (str.indexOf(arguments[i]) >= 0) { return true; } return false; },
_blend: function(c1, c2) { var cc1 = OpenLayers.Rico.Color.createFromHex(c1); cc1.blend(OpenLayers.Rico.Color.createFromHex(c2)); return cc1; }, _blend: function(c1, c2) { var cc1 = OpenLayers.Rico.Color.createFromHex(c1); cc1.blend(OpenLayers.Rico.Color.createFromHex(c2)); return cc1; },
_background: function(el) { try { return OpenLayers.Rico.Color.createColorFromBackground(el).asHex(); } catch(err) { return "#ffffff"; } }, _background: function(el) { try { return OpenLayers.Rico.Color.createColorFromBackground(el).asHex(); } catch(err) { return "#ffffff"; } },
_isTransparent: function() { return this.options.color == "transparent"; }, _isTransparent: function() { return this.options.color == "transparent"; },
_isTopRounded: function() { return this._hasString(this.options.corners, "all", "top", "tl", "tr"); }, _isTopRounded: function() { return this._hasString(this.options.corners, "all", "top", "tl", "tr"); },
_isBottomRounded: function() { return this._hasString(this.options.corners, "all", "bottom", "bl", "br"); }, _isBottomRounded: function() { return this._hasString(this.options.corners, "all", "bottom", "bl", "br"); },
_hasSingleTextChild: function(el) { return el.childNodes.length == 1 && el.childNodes[0].nodeType == 3; } _hasSingleTextChild: function(el) { return el.childNodes.length == 1 && el.childNodes[0].nodeType == 3; }
} };