Index: chrome/browser/resources/shared/js/cr.js |
diff --git a/chrome/browser/resources/shared/js/cr.js b/chrome/browser/resources/shared/js/cr.js |
index 2a370a1c0ab5f2b3a9d5d75cbc21c42c51f459b2..9bc2cbe63ca48dc80536cb5f8005aba86580262c 100644 |
--- a/chrome/browser/resources/shared/js/cr.js |
+++ b/chrome/browser/resources/shared/js/cr.js |
@@ -134,6 +134,19 @@ const cr = (function() { |
} |
/** |
+ * Converts a camelCase javascript property name to a hyphenated-lower-case |
+ * attribute name. |
+ * @param {string} jsName The javascript camelCase property name. |
+ * @return {string} The equivalent hyphenated-lower-case attribute name. |
+ */ |
+ function getAttributeName(jsName) { |
+ // Convert common case aB to a-b, and ABc to a-bc to cover acronyms such as |
+ // getHTMLElement. |
+ return jsName.replace(/([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-z]))/g, '$&-') |
arv1
2011/11/01 17:46:24
This looks overly complex. The following works jus
flackr
2011/11/01 17:55:46
Done. I guess worrying about handling uppercase ac
|
+ .toLowerCase(); |
+ } |
+ |
+ /** |
* The kind of property to define in {@code defineProperty}. |
* @enum {number} |
*/ |
@@ -171,12 +184,14 @@ const cr = (function() { |
return this[privateName]; |
}; |
case PropertyKind.ATTR: |
+ var attributeName = getAttributeName(name); |
return function() { |
- return this.getAttribute(name); |
+ return this.getAttribute(attributeName); |
}; |
case PropertyKind.BOOL_ATTR: |
+ var attributeName = getAttributeName(name); |
return function() { |
- return this.hasAttribute(name); |
+ return this.hasAttribute(attributeName); |
}; |
} |
} |
@@ -207,13 +222,14 @@ const cr = (function() { |
}; |
case PropertyKind.ATTR: |
+ var attributeName = getAttributeName(name); |
return function(value) { |
- var oldValue = this[name]; |
+ var oldValue = this[attributeName]; |
if (value !== oldValue) { |
if (value == undefined) |
- this.removeAttribute(name); |
+ this.removeAttribute(attributeName); |
else |
- this.setAttribute(name, value); |
+ this.setAttribute(attributeName, value); |
if (opt_setHook) |
opt_setHook.call(this, value, oldValue); |
dispatchPropertyChange(this, name, value, oldValue); |
@@ -221,13 +237,14 @@ const cr = (function() { |
}; |
case PropertyKind.BOOL_ATTR: |
+ var attributeName = getAttributeName(name); |
return function(value) { |
- var oldValue = this[name]; |
+ var oldValue = this[attributeName]; |
if (value !== oldValue) { |
if (value) |
- this.setAttribute(name, name); |
+ this.setAttribute(attributeName, name); |
else |
- this.removeAttribute(name); |
+ this.removeAttribute(attributeName); |
if (opt_setHook) |
opt_setHook.call(this, value, oldValue); |
dispatchPropertyChange(this, name, value, oldValue); |