Revert "Removing camelize method."

This reverts commit 43ef0920c2.
This commit is contained in:
Éric Lemoine
2012-03-04 23:22:21 +01:00
parent 55a52008d6
commit c58f093615
7 changed files with 63 additions and 14 deletions

View File

@@ -64,6 +64,28 @@ OpenLayers.String = {
return str.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}, },
/**
* APIFunction: camelize
* Camel-case a hyphenated string.
* Ex. "chicken-head" becomes "chickenHead", and
* "-chicken-head" becomes "ChickenHead".
*
* Parameters:
* str - {String} The string to be camelized. The original is not modified.
*
* Returns:
* {String} The string, camelized
*/
camelize: function(str) {
var oStringList = str.split('-');
var camelizedString = oStringList[0];
for (var i=1, len=oStringList.length; i<len; i++) {
var s = oStringList[i];
camelizedString += s.charAt(0).toUpperCase() + s.substring(1);
}
return camelizedString;
},
/** /**
* APIFunction: format * APIFunction: format
* Given a string with tokens in the form ${token}, return a string * Given a string with tokens in the form ${token}, return a string

View File

@@ -163,7 +163,7 @@ OpenLayers.Element = {
var value = null; var value = null;
if (element && element.style) { if (element && element.style) {
value = element.style[style]; value = element.style[OpenLayers.String.camelize(style)];
if (!value) { if (!value) {
if (document.defaultView && if (document.defaultView &&
document.defaultView.getComputedStyle) { document.defaultView.getComputedStyle) {
@@ -171,7 +171,7 @@ OpenLayers.Element = {
var css = document.defaultView.getComputedStyle(element, null); var css = document.defaultView.getComputedStyle(element, null);
value = css ? css.getPropertyValue(style) : null; value = css ? css.getPropertyValue(style) : null;
} else if (element.currentStyle) { } else if (element.currentStyle) {
value = element.currentStyle[style]; value = element.currentStyle[OpenLayers.String.camelize(style)];
} }
} }

View File

@@ -493,14 +493,14 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
this.ovmap.zoomToMaxExtent(); this.ovmap.zoomToMaxExtent();
// check extent rectangle border width // check extent rectangle border width
this.wComp = parseInt(OpenLayers.Element.getStyle(this.extentRectangle, this.wComp = parseInt(OpenLayers.Element.getStyle(this.extentRectangle,
'borderLeftWidth')) + 'border-left-width')) +
parseInt(OpenLayers.Element.getStyle(this.extentRectangle, parseInt(OpenLayers.Element.getStyle(this.extentRectangle,
'borderRightWidth')); 'border-right-width'));
this.wComp = (this.wComp) ? this.wComp : 2; this.wComp = (this.wComp) ? this.wComp : 2;
this.hComp = parseInt(OpenLayers.Element.getStyle(this.extentRectangle, this.hComp = parseInt(OpenLayers.Element.getStyle(this.extentRectangle,
'border-top-width')) + 'border-top-width')) +
parseInt(OpenLayers.Element.getStyle(this.extentRectangle, parseInt(OpenLayers.Element.getStyle(this.extentRectangle,
'borderBottomWidth')); 'border-bottom-width'));
this.hComp = (this.hComp) ? this.hComp : 2; this.hComp = (this.hComp) ? this.hComp : 2;
this.handlers.drag = new OpenLayers.Handler.Drag( this.handlers.drag = new OpenLayers.Handler.Drag(

View File

@@ -221,13 +221,13 @@ OpenLayers.Handler.Box = OpenLayers.Class(OpenLayers.Handler, {
document.body.removeChild(testDiv); document.body.removeChild(testDiv);
var left = parseInt(OpenLayers.Element.getStyle(this.zoomBox, var left = parseInt(OpenLayers.Element.getStyle(this.zoomBox,
"borderLeftWidth")); "border-left-width"));
var right = parseInt(OpenLayers.Element.getStyle( var right = parseInt(OpenLayers.Element.getStyle(
this.zoomBox, "borderRightWidth")); this.zoomBox, "border-right-width"));
var top = parseInt(OpenLayers.Element.getStyle(this.zoomBox, var top = parseInt(OpenLayers.Element.getStyle(this.zoomBox,
"borderTopWidth")); "border-top-width"));
var bottom = parseInt(OpenLayers.Element.getStyle( var bottom = parseInt(OpenLayers.Element.getStyle(
this.zoomBox, "borderBottomWidth")); this.zoomBox, "border-bottom-width"));
this.boxOffsets = { this.boxOffsets = {
left: left, left: left,
right: right, right: right,

View File

@@ -847,10 +847,10 @@ OpenLayers.Popup = OpenLayers.Class({
//read the padding settings from css, put them in an OL.Bounds //read the padding settings from css, put them in an OL.Bounds
contentDivPadding = new OpenLayers.Bounds( contentDivPadding = new OpenLayers.Bounds(
OpenLayers.Element.getStyle(this.contentDiv, "paddingLeft"), OpenLayers.Element.getStyle(this.contentDiv, "padding-left"),
OpenLayers.Element.getStyle(this.contentDiv, "paddingBottom"), OpenLayers.Element.getStyle(this.contentDiv, "padding-bottom"),
OpenLayers.Element.getStyle(this.contentDiv, "paddingRight"), OpenLayers.Element.getStyle(this.contentDiv, "padding-right"),
OpenLayers.Element.getStyle(this.contentDiv, "paddingTop") OpenLayers.Element.getStyle(this.contentDiv, "padding-top")
); );
//cache the value //cache the value

View File

@@ -60,6 +60,33 @@
t.eq(OpenLayers.String.trim(str), "", "whitespace string is trimmed correctly"); t.eq(OpenLayers.String.trim(str), "", "whitespace string is trimmed correctly");
} }
function test_String_camelize(t) {
t.plan(7);
var str = "chickenhead";
t.eq(OpenLayers.String.camelize(str), "chickenhead", "string with no hyphens is left alone");
str = "chicken-head";
t.eq(OpenLayers.String.camelize(str), "chickenHead", "string with one middle hyphen is camelized correctly");
str = "chicken-head-man";
t.eq(OpenLayers.String.camelize(str), "chickenHeadMan", "string with multiple middle hyphens is camelized correctly");
str = "-chickenhead";
t.eq(OpenLayers.String.camelize(str), "Chickenhead", "string with starting hyphen is camelized correctly (capitalized)");
str = "-chicken-head-man";
t.eq(OpenLayers.String.camelize(str), "ChickenHeadMan", "string with starting hypen and multiple middle hyphens is camelized correctly");
str = "chicken-";
t.eq(OpenLayers.String.camelize(str), "chicken", "string ending in hyphen is camelized correctly (hyphen dropped)");
str = "chicken-head-man-";
t.eq(OpenLayers.String.camelize(str), "chickenHeadMan", "string with multiple middle hyphens and end hyphen is camelized correctly (end hyphen dropped)");
}
function test_String_format(t) { function test_String_format(t) {
var unchanged = [ var unchanged = [
"", "${ ", "${", " ${", "${${", "${}", "${${}}", " ${ ${", "", "${ ", "${", " ${", "${${", "${}", "${${}}", " ${ ${",

View File

@@ -41,7 +41,7 @@
// Chromium 10: left is 0 // Chromium 10: left is 0
var testdiv = OpenLayers.Util.createDiv('testdiv', new OpenLayers.Pixel(5, 5)); var testdiv = OpenLayers.Util.createDiv('testdiv', new OpenLayers.Pixel(5, 5));
map.div.appendChild(testdiv); map.div.appendChild(testdiv);
var left = parseInt(OpenLayers.Element.getStyle(testdiv, 'borderLeftWidth')); var left = parseInt(OpenLayers.Element.getStyle(testdiv, 'border-left-width'));
map.div.removeChild(testdiv); map.div.removeChild(testdiv);
var testAll = !isNaN(left); var testAll = !isNaN(left);