From 4a6e180637d1f20b0f61e2efd21ff0b4351afe2d Mon Sep 17 00:00:00 2001 From: Paul Spencer Date: Thu, 18 Oct 2007 23:49:41 +0000 Subject: [PATCH] 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 --- lib/Rico/Color.js | 59 ++++++++++++----------- lib/Rico/Corner.js | 117 +++++++++++++++++++++++++-------------------- 2 files changed, 97 insertions(+), 79 deletions(-) diff --git a/lib/Rico/Color.js b/lib/Rico/Color.js index 0d4bf30e48..bcbfe1c86e 100644 --- a/lib/Rico/Color.js +++ b/lib/Rico/Color.js @@ -91,16 +91,19 @@ OpenLayers.Rico.Color.createFromHex = function(hexCode) { if(hexCode.length==4) { var shortHexCode = hexCode; var hexCode = '#'; - for(var i=1;i<4;i++) hexCode += (shortHexCode.charAt(i) + -shortHexCode.charAt(i)); + for(var i=1;i<4;i++) { + hexCode += (shortHexCode.charAt(i) + +shortHexCode.charAt(i)); + } } - if ( hexCode.indexOf('#') == 0 ) - hexCode = hexCode.substring(1); + if ( hexCode.indexOf('#') == 0 ) { + hexCode = hexCode.substring(1); + } var red = hexCode.substring(0,2); var green = hexCode.substring(2,4); var blue = hexCode.substring(4,6); return new OpenLayers.Rico.Color( parseInt(red,16), parseInt(green,16), parseInt(blue,16) ); -} +}; /** * Factory method for creating a color from the background of @@ -113,12 +116,12 @@ OpenLayers.Rico.Color.createColorFromBackground = function(elem) { "backgroundColor", "background-color"); - if ( actualColor == "transparent" && elem.parentNode ) + if ( actualColor == "transparent" && elem.parentNode ) { return OpenLayers.Rico.Color.createColorFromBackground(elem.parentNode); - - if ( actualColor == null ) + } + if ( actualColor == null ) { return new OpenLayers.Rico.Color(255,255,255); - + } if ( actualColor.indexOf("rgb(") == 0 ) { var colors = actualColor.substring(4, actualColor.length - 1 ); var colorArray = colors.split(","); @@ -130,9 +133,10 @@ OpenLayers.Rico.Color.createColorFromBackground = function(elem) { else if ( actualColor.indexOf("#") == 0 ) { return OpenLayers.Rico.Color.createFromHex(actualColor); } - else + else { return new OpenLayers.Rico.Color(255,255,255); -} + } +}; 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) }; -} +}; OpenLayers.Rico.Color.RGBtoHSB = function(r, g, b) { @@ -196,38 +200,39 @@ OpenLayers.Rico.Color.RGBtoHSB = function(r, g, b) { var brightness; var cmax = (r > g) ? r : g; - if (b > cmax) + if (b > cmax) { cmax = b; - + } var cmin = (r < g) ? r : g; - if (b < cmin) + if (b < cmin) { cmin = b; - + } brightness = cmax / 255.0; - if (cmax != 0) + if (cmax != 0) { saturation = (cmax - cmin)/cmax; - else + } else { saturation = 0; - - if (saturation == 0) + } + if (saturation == 0) { hue = 0; - else { + } else { var redc = (cmax - r)/(cmax - cmin); var greenc = (cmax - g)/(cmax - cmin); var bluec = (cmax - b)/(cmax - cmin); - if (r == cmax) + if (r == cmax) { hue = bluec - greenc; - else if (g == cmax) + } else if (g == cmax) { hue = 2.0 + redc - bluec; - else + } else { hue = 4.0 + greenc - redc; - + } hue = hue / 6.0; - if (hue < 0) + if (hue < 0) { hue = hue + 1.0; + } } return { h : hue, s : saturation, b : brightness }; -} +}; diff --git a/lib/Rico/Corner.js b/lib/Rico/Corner.js index a808c084fe..1f1bd807a7 100644 --- a/lib/Rico/Corner.js +++ b/lib/Rico/Corner.js @@ -17,20 +17,20 @@ OpenLayers.Rico = new Object(); OpenLayers.Rico.Corner = { - round: function(e, options) { - e = OpenLayers.Util.getElement(e); - this._setOptions(options); + round: function(e, options) { + e = OpenLayers.Util.getElement(e); + this._setOptions(options); - var color = this.options.color; - if ( this.options.color == "fromElement" ) - color = this._background(e); - - var bgColor = this.options.bgColor; - if ( this.options.bgColor == "fromParent" ) - bgColor = this._background(e.offsetParent); - - this._roundCornersImpl(e, color, bgColor); - }, + var color = this.options.color; + if ( this.options.color == "fromElement" ) { + color = this._background(e); + } + var bgColor = this.options.bgColor; + if ( this.options.bgColor == "fromParent" ) { + bgColor = this._background(e.offsetParent); + } + this._roundCornersImpl(e, color, bgColor); + }, /** This is a helper function to change the background * color of
that has had Rico rounded corners added. @@ -107,12 +107,15 @@ OpenLayers.Rico.Corner = { }, _roundCornersImpl: function(e, color, bgColor) { - if(this.options.border) + if(this.options.border) { this._renderBorder(e,bgColor); - if(this._isTopRounded()) + } + if(this._isTopRounded()) { this._roundTopCorners(e,color,bgColor); - if(this._isBottomRounded()) + } + if(this._isBottomRounded()) { this._roundBottomCorners(e,color,bgColor); + } }, _renderBorder: function(el,bgColor) { @@ -120,21 +123,23 @@ OpenLayers.Rico.Corner = { var borderL = "border-left: " + borderValue; var borderR = "border-right: " + borderValue; var style = "style='" + borderL + ";" + borderR + "'"; - el.innerHTML = "
" + el.innerHTML + "
" + el.innerHTML = "
" + el.innerHTML + "
"; }, _roundTopCorners: function(el, color, 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")); + } el.style.paddingTop = 0; el.insertBefore(corner,el.firstChild); }, _roundBottomCorners: function(el, color, 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")); + } el.style.paddingBottom = 0; el.appendChild(corner); }, @@ -171,9 +176,9 @@ OpenLayers.Rico.Corner = { 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"; - + } this._setMargin(slice, n, position); this._setBorder(slice, n, position); return slice; @@ -187,51 +192,56 @@ OpenLayers.Rico.Corner = { blend : true, border : false, compact : false - } + }; OpenLayers.Util.extend(this.options, options || {}); this.options.numSlices = this.options.compact ? 2 : 4; - if ( this._isTransparent() ) + if ( this._isTransparent() ) { this.options.blend = false; + } }, _whichSideTop: function() { - if ( this._hasString(this.options.corners, "all", "top") ) + if ( this._hasString(this.options.corners, "all", "top") ) { 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 ""; - - if (this.options.corners.indexOf("tl") >= 0) + } + if (this.options.corners.indexOf("tl") >= 0) { return "left"; - else if (this.options.corners.indexOf("tr") >= 0) + } else if (this.options.corners.indexOf("tr") >= 0) { return "right"; + } return ""; }, _whichSideBottom: function() { - if ( this._hasString(this.options.corners, "all", "bottom") ) + if ( this._hasString(this.options.corners, "all", "bottom") ) { 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 ""; + } - if(this.options.corners.indexOf("bl") >=0) + if(this.options.corners.indexOf("bl") >=0) { return "left"; - else if(this.options.corners.indexOf("br")>=0) + } else if(this.options.corners.indexOf("br")>=0) { return "right"; + } return ""; }, _borderColor : function(color,bgColor) { - if ( color == "transparent" ) + if ( color == "transparent" ) { return bgColor; - else if ( this.options.border ) + } else if ( this.options.border ) { return this.options.border; - else if ( this.options.blend ) + } else if ( this.options.blend ) { return this._blend( bgColor, color ); - else + } else { return ""; + } }, @@ -262,27 +272,29 @@ OpenLayers.Rico.Corner = { else { 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"; + } }, _marginSize: function(n) { - if ( this._isTransparent() ) + if ( this._isTransparent() ) { return 0; - + } var marginSizes = [ 5, 3, 2, 1 ]; var blendedMarginSizes = [ 3, 2, 1, 0 ]; var compactMarginSizes = [ 2, 1 ]; var smBlendedMarginSizes = [ 1, 0 ]; - if ( this.options.compact && this.options.blend ) + if ( this.options.compact && this.options.blend ) { return smBlendedMarginSizes[n]; - else if ( this.options.compact ) + } else if ( this.options.compact ) { return compactMarginSizes[n]; - else if ( this.options.blend ) + } else if ( this.options.blend ) { return blendedMarginSizes[n]; - else + } else { return marginSizes[n]; + } }, _borderSize: function(n) { @@ -291,24 +303,25 @@ OpenLayers.Rico.Corner = { var compactBorderSizes = [ 1, 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; - else if ( this.options.compact ) + } else if ( this.options.compact ) { return compactBorderSizes[n]; - else if ( this.options.blend ) + } else if ( this.options.blend ) { return blendedBorderSizes[n]; - else if ( this.options.border ) + } else if ( this.options.border ) { return actualBorderSizes[n]; - else if ( this._isTransparent() ) + } else if ( this._isTransparent() ) { return transparentBorderSizes[n]; + } return 0; }, - _hasString: function(str) { for(var i=1 ; i= 0) return true; return false; }, + _hasString: function(str) { for(var i=1 ; 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; }, _background: function(el) { try { return OpenLayers.Rico.Color.createColorFromBackground(el).asHex(); } catch(err) { return "#ffffff"; } }, _isTransparent: function() { return this.options.color == "transparent"; }, _isTopRounded: function() { return this._hasString(this.options.corners, "all", "top", "tl", "tr"); }, _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; } -} +}; \ No newline at end of file