[Pkg-javascript-commits] [backbone] 168/281: fixes #838 -- allow View#attributes to be defined as a function, as well as a value.
Jonas Smedegaard
js at moszumanska.debian.org
Sat May 3 17:02:08 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.9.0
in repository backbone.
commit cb7090db7709c6545e9857a6cc66cda00d729fa2
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date: Wed Jan 11 16:47:50 2012 -0500
fixes #838 -- allow View#attributes to be defined as a function, as well as a value.
---
backbone.js | 2 +-
test/view.js | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/backbone.js b/backbone.js
index dbae70b..5c7dae6 100644
--- a/backbone.js
+++ b/backbone.js
@@ -967,7 +967,7 @@
// an element from the `id`, `className` and `tagName` properties.
_ensureElement : function() {
if (!this.el) {
- var attrs = this.attributes || {};
+ var attrs = getValue(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 152f1d4..3182e0f 100644
--- a/test/view.js
+++ b/test/view.js
@@ -111,6 +111,15 @@ $(document).ready(function() {
equals(view.el.id, 'two');
});
+ test("View: with attributes as a function", function() {
+ var viewClass = Backbone.View.extend({
+ attributes: function() {
+ return {'class': 'dynamic'};
+ }
+ });
+ equals((new viewClass).el.className, 'dynamic');
+ });
+
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