Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3395)

Unified Diff: chrome/browser/resources/shared/js/cr.js

Issue 8341081: Add icon-visibility attribute to cr.ui.Tree. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Convert from camelCase to hyphenated-words for defineProperty ATTR setters/getters. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/shared/css/tree.css ('k') | chrome/browser/resources/shared/js/cr/ui/tree.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « chrome/browser/resources/shared/css/tree.css ('k') | chrome/browser/resources/shared/js/cr/ui/tree.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698