-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoptions.js
More file actions
43 lines (38 loc) · 1010 Bytes
/
options.js
File metadata and controls
43 lines (38 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
(function() {
function attributes(el) {
var attrs = {},
attr;
el = (_.isElement(el)) ? el : el[0];
_(el.attributes.length).times(function(i) {
attr = el.attributes.item(i);
if(attr.specified) attrs[attr.name]=attr.value;
});
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),
options = {};
_(attributes(el)).each(function(v, k) {
if(k.match(r)) {
k = k.replace(prefix+"-", "");
k = dashesToCamelCase(k);
options[k] = v;
}
});
return options;
}
});
})();