mirror of
https://github.com/jashkenas/backbone.git
synced 2026-01-23 13:58:06 -05:00
Issue #33. Refactor towards View#_ensureElement
This commit is contained in:
19
backbone.js
19
backbone.js
@@ -515,14 +515,7 @@
|
||||
// if an existing element is not provided...
|
||||
Backbone.View = function(options) {
|
||||
this._configure(options || {});
|
||||
if (this.options.el) {
|
||||
this.el = this.options.el;
|
||||
} else {
|
||||
var attrs = {};
|
||||
if (this.id) attrs.id = this.id;
|
||||
if (this.className) attrs.className = this.className;
|
||||
this.el = this.make(this.tagName, attrs);
|
||||
}
|
||||
this._ensureElement();
|
||||
if (this.initialize) this.initialize(options);
|
||||
};
|
||||
|
||||
@@ -603,10 +596,20 @@
|
||||
if (this.options) options = _.extend({}, this.options, options);
|
||||
if (options.model) this.model = options.model;
|
||||
if (options.collection) this.collection = options.collection;
|
||||
if (options.el) this.el = options.el;
|
||||
if (options.id) this.id = options.id;
|
||||
if (options.className) this.className = options.className;
|
||||
if (options.tagName) this.tagName = options.tagName;
|
||||
this.options = options;
|
||||
},
|
||||
|
||||
// Ensure that the View has a DOM element to render into.
|
||||
_ensureElement : function() {
|
||||
if (this.el) return;
|
||||
var attrs = {};
|
||||
if (this.id) attrs.id = this.id;
|
||||
if (this.className) attrs.className = this.className;
|
||||
this.el = this.make(this.tagName, attrs);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user