Permalink
Browse files

version 1.4.6

  • Loading branch information...
glebm committed May 1, 2012
1 parent dc79bb5 commit 0537676e6d91d6479423d739e3f1e9602d1d9591
Showing with 50 additions and 16 deletions.
  1. +4 −0 README.md
  2. +2 −2 dombrew.coffee
  3. +39 −13 dombrew.js
  4. +1 −1 dombrew.min.js
  5. +4 −0 test/test.html
View
@@ -70,6 +70,10 @@ You will need node and coffee-script installed:
# Changelog / What's new
+v1.4.6
+
+* css: null and undefined values are skipped
+
v1.4.5
* #append and #prepend skip falsy values
View
@@ -68,7 +68,7 @@ class Node
attr['class'] && (@e.className = joinValues(attr['class'])) && delete attr['class']
attr['text'] && (@e.innerText = joinValues(attr['text'])) && delete attr['text']
attr['html'] && (@e.innerHTML = joinValues(attr['html'])) && delete attr['html']
- (s[prop] = value for prop, value of css) if attr['css'] && (s = @e.style) && (css = attr['css']) && delete attr['css']
+ (s[prop] = value for prop, value of css when value?) if attr['css'] && (s = @e.style) && (css = attr['css']) && delete attr['css']
flattenHash(attr)
@e.setAttribute(name, value) for name, value of attr
@@ -111,7 +111,7 @@ Node::asHTML = Node::html
a = [frag]
new Node(a[0], a[1], a[2])
-D.VERSION = D.version = '1.4.5'
+D.VERSION = D.version = '1.4.6'
# innerText fix (Firefox)
if (navigator.appName != 'Microsoft Internet Explorer') && !HTMLElement::innerText && HTMLElement::__defineGetter__
View
@@ -5,6 +5,8 @@ d = document;
Node = (function() {
var dotHashRe, flattenHash, joinValues, parseElem;
+ Node.name = 'Node';
+
Node.prototype._brew = 1;
flattenHash = function(attr) {
@@ -25,10 +27,16 @@ Node = (function() {
parseElem = function(elem, attr) {
var classes, elemType, piece, pieces, pos, _i, _len;
- if (!dotHashRe.test(elem)) return elem;
+ if (!dotHashRe.test(elem)) {
+ return elem;
+ }
attr['class'] || (attr['class'] = []);
- if (typeof attr['class'] === 'string') attr['class'] = [attr['class']];
- if (dotHashRe.test(elem.charAt(0))) elem = "div" + elem;
+ if (typeof attr['class'] === 'string') {
+ attr['class'] = [attr['class']];
+ }
+ if (dotHashRe.test(elem.charAt(0))) {
+ elem = "div" + elem;
+ }
pieces = elem.split(dotHashRe);
elemType = pieces.shift();
pos = elemType.length;
@@ -42,25 +50,33 @@ Node = (function() {
}
pos += piece.length + 1;
}
- if (!attr['class'].length) delete attr['class'];
+ if (!attr['class'].length) {
+ delete attr['class'];
+ }
return elemType;
};
joinValues = function(value) {
var i, length, r;
- if (typeof value !== 'object') return value;
+ if (typeof value !== 'object') {
+ return value;
+ }
r = [];
i = -1;
length = value.length;
while (++i < length) {
- if (value[i]) r.push(value[i]);
+ if (value[i]) {
+ r.push(value[i]);
+ }
}
return r.join(' ');
};
function Node(elem, attr, more) {
var css, name, prop, s, value;
- if (!(attr != null)) attr = {};
+ if (!(attr != null)) {
+ attr = {};
+ }
if (elem.nodeType) {
this.e = elem;
return;
@@ -81,7 +97,9 @@ Node = (function() {
if (attr['css'] && (s = this.e.style) && (css = attr['css']) && delete attr['css']) {
for (prop in css) {
value = css[prop];
- s[prop] = value;
+ if (value != null) {
+ s[prop] = value;
+ }
}
}
flattenHash(attr);
@@ -94,10 +112,14 @@ Node = (function() {
Node.prototype.append = function() {
var a, node, _i, _len;
a = arguments;
- if (a && a[0] && "splice" in a[0]) a = a[0];
+ if (a && a[0] && "splice" in a[0]) {
+ a = a[0];
+ }
for (_i = 0, _len = a.length; _i < _len; _i++) {
node = a[_i];
- if (!(node)) continue;
+ if (!(node)) {
+ continue;
+ }
('_brew' in node) && (node = node.dom());
this.e.appendChild(node);
}
@@ -107,10 +129,14 @@ Node = (function() {
Node.prototype.prepend = function() {
var a, node, _i, _len;
a = arguments;
- if (a && a[0] && "splice" in a[0]) a = a[0];
+ if (a && a[0] && "splice" in a[0]) {
+ a = a[0];
+ }
for (_i = 0, _len = a.length; _i < _len; _i++) {
node = a[_i];
- if (!(node)) continue;
+ if (!(node)) {
+ continue;
+ }
('_brew' in node) && (node = node.dom());
this.e.insertBefore(node, this.e.firstChild);
}
@@ -155,7 +181,7 @@ this.DOMBrew = D = function() {
return new Node(a[0], a[1], a[2]);
};
-D.VERSION = D.version = '1.4.5';
+D.VERSION = D.version = '1.4.6';
if ((navigator.appName !== 'Microsoft Internet Explorer') && !HTMLElement.prototype.innerText && HTMLElement.prototype.__defineGetter__) {
HTMLElement.prototype.__defineGetter__("innerText", function() {
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -181,6 +181,10 @@ <h2>Benchmarks</h2>
assert(/style.*color.*red/.test($b('span', {css: { color: 'red' }}).html()));
});
+ test("$b('span', css: { marginLeft: null }) // should ignore marginLeft", function() {
+ assert(!/margin/.test($b('span', {css: { marginLeft: null }}).html()));
+ });
+
test("$b(DOMElement).prepend($b('em'))", function() {
var $elem = $('<div><span></span></div>');

0 comments on commit 0537676

Please sign in to comment.