Permalink
Browse files

* options.js: follow HTML attribute naming rules

  • Loading branch information...
1 parent 532a590 commit c5031749b029a23b42a1d76b679c50789956cc2d David Nolen committed May 20, 2010
Showing with 21 additions and 4 deletions.
  1. +21 −4 options.js
View
@@ -1,6 +1,6 @@
(function() {
- function attributes (el) {
+ function attributes(el) {
var attrs = {},
attr;
el = (_.isElement(el)) ? el : el[0];
@@ -10,16 +10,33 @@
});
return attrs;
};
+
+ function capitalize(str) {
+ return str.charAt(0).toUpperCase() + str.substring(1).toLowerCase();
+ };
+
+ function dashesToCamelCase(str) {
+ return _(str.split("-")).map(function(s, i) {
+ if(i == 0) return s;
+ return capitalize(s);
+ }).join("");
+ };
var root = this;
root.Options = _.Module({
name: "Options",
getOptions: function(el, prefix) {
prefix = "data-" + (prefix || "");
- var r = new RegExp("^"+prefix);
- return _(attributes(el)).filter(function(v, k) {
- return k.search(r) != -1;
+ var r = new RegExp("^"+prefix),
+ options = {};
+ _(attributes(el)).each(function(v, k) {
+ if(k.match(r)) {
+ k = k.replace(prefix+"-", "");
+ k = dashesToCamelCase(k);
+ options[k] = v;
+ }
});
+ return options;
}
});

0 comments on commit c503174

Please sign in to comment.