Merge pull request #1234 from braddunbar/tagname

Fix #1228 - tagName can be provided as a function.
This commit is contained in:
Jeremy Ashkenas
2012-04-17 08:48:00 -07:00
2 changed files with 7 additions and 2 deletions

View File

@@ -1268,7 +1268,7 @@
var attrs = _.extend({}, getValue(this, 'attributes'));
if (this.id) attrs.id = this.id;
if (this.className) attrs['class'] = this.className;
this.setElement(this.make(this.tagName, attrs), false);
this.setElement(this.make(getValue(this, 'tagName'), attrs), false);
} else {
this.setElement(this.el, false);
}

View File

@@ -217,8 +217,13 @@ $(document).ready(function() {
test("Clone attributes object", function() {
var View = Backbone.View.extend({attributes: {foo: 'bar'}});
var v1 = new View({id: 'foo'});
ok(v1.el.id === 'foo');
strictEqual(v1.el.id, 'foo');
var v2 = new View();
ok(!v2.el.id);
});
test("#1228 - tagName can be provided as a function", function() {
var View = Backbone.View.extend({tagName: function(){ return 'p'; }});
ok(new View().$el.is('p'));
});
});