Skip to content
This repository was archived by the owner on Jun 11, 2019. It is now read-only.

Commit 1142a6c

Browse files
committed
Merge pull request #40 from jvanwinkle/delegate-if-needed
Delegate events
2 parents 0e51836 + 88415b6 commit 1142a6c

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/thumbs.view.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,7 @@ Thumbs.View = (function () {
389389
this.events = this.events || {};
390390

391391
this.$('[data-thumbs-delegate]').each(function() {
392-
hasEvents = true;
393-
self._bindEvents(this);
392+
hasEvents = self._bindEvents(this) || hasEvents;
394393
});
395394
if (hasEvents) {
396395
this.delegateEvents();
@@ -400,8 +399,10 @@ Thumbs.View = (function () {
400399

401400
_bindEvents: function(element){
402401
var self = this,
402+
bound = false,
403403
thumbsView = viewRegistry.get($(element).attr("thumbs-id"));
404404
if (viewRegistry.getEnclosingView(element) === self) {
405+
bound = true;
405406
var $element = $(element), id = _.uniqueId('thumbs_');
406407
$element.addClass(id);
407408
splitParts($element.data('thumbs-delegate'), function (data) {
@@ -413,6 +414,7 @@ Thumbs.View = (function () {
413414
}
414415
});
415416
}
417+
return bound;
416418
},
417419

418420
render: function () {

thumbs.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,7 @@
682682
this.events = this.events || {};
683683

684684
this.$('[data-thumbs-delegate]').each(function() {
685-
hasEvents = true;
686-
self._bindEvents(this);
685+
hasEvents = self._bindEvents(this) || hasEvents;
687686
});
688687
if (hasEvents) {
689688
this.delegateEvents();
@@ -693,8 +692,10 @@
693692

694693
_bindEvents: function(element){
695694
var self = this,
695+
bound = false,
696696
thumbsView = viewRegistry.get($(element).attr("thumbs-id"));
697697
if (viewRegistry.getEnclosingView(element) === self) {
698+
bound = true;
698699
var $element = $(element), id = _.uniqueId('thumbs_');
699700
$element.addClass(id);
700701
splitParts($element.data('thumbs-delegate'), function (data) {
@@ -706,6 +707,7 @@
706707
}
707708
});
708709
}
710+
return bound;
709711
},
710712

711713
render: function () {

0 commit comments

Comments
 (0)