Skip to content

Commit

Permalink
added more tags, two new useful functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Zaporzan authored and Benjamin Zaporzan committed Mar 20, 2015
1 parent fc19be4 commit db1e5e1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
31 changes: 31 additions & 0 deletions DOM.Barf.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,18 @@ DOM.Barf = DOM.Barf || {};
context.title = toSpit("title");
context.body = toSpit("body");
context.div = toSpit("div");
context.h1 = toSpit("h1");
context.h2 = toSpit("h2");
context.h3 = toSpit("h3");
context.h4 = toSpit("h4");
context.h5 = toSpit("h5");
context.img = toSpit("img", {bSingular:true});
context.a = toSpit("a");
context.b = toSpit("b");
context.span = toSpit("span");
context.p = toSpit("p");
context.input = toSpit("input");
context.button = toSpit("button");
context.table = toSpit("table");
context.tr = toSpit("tr");
context.td = toSpit("td");
Expand All @@ -226,6 +234,29 @@ DOM.Barf = DOM.Barf || {};
context.ToRaw = function(children) {
return parseTagChildren(children);
}

/*
Merges the object attributes from b into a
*/
context.Merge = function(a, b) {
for (key in b) {
if (b.hasOwnProperty(key)) {
if (typeof a[key] == "object" && typeof b[key] == "object") {
a[key] = merge(a[key], b[key]);
}
else {
a[key] = b[key];
}
}
}
return a;
}

context.ToDOMNode = function(s) {
var wrapper = document.createElement("div");
wrapper.innerHTML = s;
return wrapper.firstChild;
}

})(DOM.Barf);

Expand Down
10 changes: 10 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@
]),
]),
]);

var create_defaultButton = function(attrs, children) {
var attrs = attrs || {};

return _s.ToDOMNode(
_s.button(_s.Merge({value: "Test Button"}, attrs), children)
)
}

console.log(create_defaultButton({value: "New button"}, "test"));

</script>
</body>
Expand Down

0 comments on commit db1e5e1

Please sign in to comment.