Skip to content

Commit

Permalink
merging in jashkenas#758 -- although the API leaves something to be d…
Browse files Browse the repository at this point in the history
…esired.
  • Loading branch information
jashkenas committed Nov 23, 2011
1 parent 43c815a commit 9fc7443
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
18 changes: 5 additions & 13 deletions backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -873,17 +873,6 @@
this.initialize.apply(this, arguments);
};

// Element lookup, scoped to DOM elements within the current view.
// This should be prefered to global lookups, if you're dealing with
// a specific view.
var selectorDelegate = function(selector) {
if (typeof selector == 'undefined') {
return $(this.el);
} else {
return $(selector, this.el);
};
};

// Cached regex to split keys for `delegate`.
var eventSplitter = /^(\S+)\s*(.*)$/;

Expand All @@ -896,8 +885,11 @@
// The default `tagName` of a View's element is `"div"`.
tagName : 'div',

// Attach the `selectorDelegate` function as the `$` property.
$ : selectorDelegate,
// jQuery delegate for element lookup, scoped to DOM elements within the
// current view. This should be prefered to global lookups where possible.
$ : function(selector) {
return (selector == null) ? $(this.el) : $(selector, this.el);
},

// Initialize is an empty function by default. Override it with your own
// initialization logic.
Expand Down
2 changes: 1 addition & 1 deletion test/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ $(document).ready(function() {
var counter = counter2 = 0;
view.el = document.body;
view.increment = function(){ counter++; };
$(view.el).bind('click', function(){ counter2++; });
view.$().bind('click', function(){ counter2++; });
var events = {"click #qunit-banner": "increment"};
view.delegateEvents(events);
$('#qunit-banner').trigger('click');
Expand Down

0 comments on commit 9fc7443

Please sign in to comment.