forked from leonidas/transparency
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.transparency.js
44 lines (44 loc) · 1.22 KB
/
jquery.transparency.js
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
44
(function() {
var $, assign;
$ = jQuery;
assign = function(node, attribute, value) {
var children;
if (attribute) {
return node.attr(attribute, value);
} else {
children = node.children().detach();
node.text(value);
return node.append(children);
}
};
$.fn.render = function(data) {
var context, template;
if (!$.isArray(data)) {
data = [data];
}
context = this;
template = this.clone();
$.each(data, function(index, object) {
var tmp;
tmp = template.clone();
$.each(object, function(key, value) {
var attribute, klass, _ref;
if ($.isArray(value)) {
return tmp.find("." + key).children().first().render(value);
} else if (typeof value === "object") {
return tmp.find("." + key).render(value);
} else {
_ref = key.split('@'), klass = _ref[0], attribute = _ref[1];
if (tmp.hasClass(klass)) {
assign(tmp, attribute, value);
}
return tmp.find("." + klass).each(function() {
return assign($(this), attribute, value);
});
}
});
return context.before(tmp);
});
return context.remove();
};
}).call(this);