[Pkg-javascript-commits] [backbone] 79/211: merging #179 + refactor, view 'attributes' for this.el
Jonas Smedegaard
js at moszumanska.debian.org
Sat May 3 17:00:05 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.5.0
in repository backbone.
commit a5079aba1c4646ba0b7d50a1a76798841da6ad83
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date: Mon Feb 7 16:10:08 2011 -0500
merging #179 + refactor, view 'attributes' for this.el
---
backbone.js | 16 ++++++++--------
test/view.js | 6 ++++++
2 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/backbone.js b/backbone.js
index 15e65f3..7a8ee41 100644
--- a/backbone.js
+++ b/backbone.js
@@ -826,6 +826,9 @@
// Cached regex to split keys for `delegate`.
var eventSplitter = /^(\w+)\s*(.*)$/;
+ // List of view options to be merged as properties.
+ var viewOptions = ['model', 'collection', 'el', 'id', 'attributes', 'className', 'tagName'];
+
// Set up all inheritable **Backbone.View** properties and methods.
_.extend(Backbone.View.prototype, Backbone.Events, {
@@ -901,12 +904,10 @@
// attached directly to the view.
_configure : function(options) {
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;
+ for (var i = 0, l = viewOptions.length; i < l; i++) {
+ var attr = viewOptions[i];
+ if (options[attr]) this[attr] = options[attr];
+ }
this.options = options;
},
@@ -916,8 +917,7 @@
// an element from the `id`, `className` and `tagName` proeprties.
_ensureElement : function() {
if (!this.el) {
- var attrs = {};
- if (this.attributes) attrs = this.attributes;
+ var attrs = this.attributes || {};
if (this.id) attrs.id = this.id;
if (this.className) attrs['class'] = this.className;
this.el = this.make(this.tagName, attrs);
diff --git a/test/view.js b/test/view.js
index 9d9e6a6..0eba3ca 100644
--- a/test/view.js
+++ b/test/view.js
@@ -84,6 +84,12 @@ $(document).ready(function() {
ok(!view.el);
});
+ test("View: with attributes", function() {
+ var view = new Backbone.View({attributes : {'class': 'one', id: 'two'}});
+ equals(view.el.className, 'one');
+ equals(view.el.id, 'two');
+ });
+
test("View: multiple views per element", function() {
var count = 0, ViewClass = Backbone.View.extend({
el: $("body"),
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git
More information about the Pkg-javascript-commits
mailing list