mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-30 03:00:06 -04:00
Merge pull request #3085 from nhunzaker/master
Proposal: View.prototype._createElement to allow for overrideable DOM element creation
This commit is contained in:
@@ -1145,6 +1145,11 @@
|
||||
this.$el.off(eventName + '.delegateEvents' + this.cid, selector, listener);
|
||||
},
|
||||
|
||||
// Produces a DOM element according to the `tagName` parameter.
|
||||
_createElement: function(tagName) {
|
||||
return document.createElement(tagName);
|
||||
},
|
||||
|
||||
// Ensure that the View has a DOM element to render into.
|
||||
// If `this.el` is a string, pass it through `$()`, take the first
|
||||
// matching element, and re-assign it to `el`. Otherwise, create
|
||||
@@ -1154,7 +1159,7 @@
|
||||
var attrs = _.extend({}, _.result(this, 'attributes'));
|
||||
if (this.id) attrs.id = _.result(this, 'id');
|
||||
if (this.className) attrs['class'] = _.result(this, 'className');
|
||||
this.setElement(document.createElement(_.result(this, 'tagName')));
|
||||
this.setElement(this._createElement(_.result(this, 'tagName')));
|
||||
this._setAttributes(attrs);
|
||||
} else {
|
||||
this.setElement(_.result(this, 'el'));
|
||||
|
||||
@@ -176,6 +176,14 @@
|
||||
view.$el.trigger('click');
|
||||
});
|
||||
|
||||
test("_createElement produces the correct DOM el", 1, function() {
|
||||
var View = Backbone.View.extend({
|
||||
tagName: 'span'
|
||||
});
|
||||
|
||||
equal(new View().el.tagName, 'SPAN');
|
||||
});
|
||||
|
||||
test("_ensureElement with DOM node el", 1, function() {
|
||||
var View = Backbone.View.extend({
|
||||
el: document.body
|
||||
|
||||
Reference in New Issue
Block a user