[Pkg-javascript-commits] [backbone] 30/211: Merging Issue #149. View#el can be a string.

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 16:59:59 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 12f7ae91370dc4247e0abb3771bf80049835e4a2
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Fri Dec 17 13:56:19 2010 -0500

    Merging Issue #149. View#el can be a string.
---
 backbone.js  |  6 ++----
 index.html   | 28 +++++++++++++++++++++-------
 test/view.js |  4 +---
 3 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/backbone.js b/backbone.js
index a3b288e..4e7e423 100644
--- a/backbone.js
+++ b/backbone.js
@@ -883,15 +883,13 @@
     // matching element, and re-assign it to `el`. Otherwise, create
     // an element from the `id`, `className` and `tagName` proeprties.
     _ensureElement : function() {
-      if (_.isString(this.el)) {
-        this.el = $(this.el).get(0);
-      }
-
       if (!this.el) {
         var attrs = {};
         if (this.id) attrs.id = this.id;
         if (this.className) attrs["class"] = this.className;
         this.el = this.make(this.tagName, attrs);
+      } else if (_.isString(this.el)) {
+        this.el = $(this.el).get(0);
       }
     }
 
diff --git a/index.html b/index.html
index af0341b..c8b1d22 100644
--- a/index.html
+++ b/index.html
@@ -1656,17 +1656,31 @@ new DocumentRow({
       whether they've already been inserted into the page or not. In this
       fashion, views can be rendered at any time, and inserted into the DOM all
       at once, in order to get high-performance UI rendering with as few
-      reflows and repaints as possible.
+      reflows and repaints as possible. <tt>this.el</tt> is created from the 
+      view's <tt>tagName</tt>, <tt>className</tt>, and <tt>id</tt> properties, 
+      if specified. If not, <b>el</b> is an empty <tt>div</tt>.
     </p>
 
     <p>
-      <tt>this.el</tt> is created from the view's <tt>tagName</tt>, <tt>className</tt>,
-      and <tt>id</tt> properties, if specified. If not, <b>el</b> is an empty <tt>div</tt>.
-      You may assign <b>el</b> directly in your view's 
-      <a href="View-constructor">initialize</a> function, if the view is being 
-      created for an element that already exists in the DOM. Make sure to assign
-      a real DOM element, and not a jQuery object.
+      You may assign <b>el</b> directly if the view is being 
+      created for an element that already exists in the DOM. Use either a 
+      reference to a real DOM element, or a css selector string.
     </p>
+    
+<pre class="runnable">
+var ItemView = Backbone.View.extend({
+  tagName: 'li'
+});
+
+var BodyView = Backbone.View.extend({
+  el: 'body'
+});
+
+var item = new ItemView();
+var body = new BodyView();
+
+alert(item.el + ' ' + body.el);
+</pre>
 
     <p id="View-dollar">
       <b class="header">$ (jQuery or Zepto)</b><code>view.$(selector)</code>
diff --git a/test/view.js b/test/view.js
index f67df41..44ce9f8 100644
--- a/test/view.js
+++ b/test/view.js
@@ -81,9 +81,7 @@ $(document).ready(function() {
       el: "#nonexistent"
     });
     view = new ViewClass;
-    ok(view.el);
-    equals(view.el.tagName.toLowerCase(), "div");
-    equals(view.el.parentNode, null);
+    ok(!view.el);
   });
 
   test("View: multiple views per element", function() {

-- 
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