From f9342d6ccf0a027c2c99e2a6ac135855a5ae0024 Mon Sep 17 00:00:00 2001 From: Simon Hewitt Date: Wed, 21 Jan 2015 09:28:22 -0800 Subject: [PATCH] simplify and fix check for if events have already been set up --- js/foundation/foundation.js | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/js/foundation/foundation.js b/js/foundation/foundation.js index 0c185a6b3..57182a7f5 100644 --- a/js/foundation/foundation.js +++ b/js/foundation/foundation.js @@ -100,24 +100,20 @@ var bindings = function (method, options) { var self = this, - should_bind_events = !S(this).data(this.attr_name(true)); + bind = function(){ + var $this = S(this), + should_bind_events = !$this.data(self.attr_name(true) + '-init'); + $this.data(self.attr_name(true) + '-init', $.extend({}, self.settings, (options || method), self.data_options($this))); - if (S(this.scope).is('[' + this.attr_name() +']')) { - S(this.scope).data(this.attr_name(true) + '-init', $.extend({}, this.settings, (options || method), this.data_options(S(this.scope)))); - - if (should_bind_events) { - this.events(this.scope); - } + if (should_bind_events) { + self.events(this); + } + }; + if (S(this.scope).is('[' + this.attr_name() +']')) { + bind.call(this.scope); } else { - S('[' + this.attr_name() +']', this.scope).each(function () { - var should_bind_events = !S(this).data(self.attr_name(true) + '-init'); - S(this).data(self.attr_name(true) + '-init', $.extend({}, self.settings, (options || method), self.data_options(S(this)))); - - if (should_bind_events) { - self.events(this); - } - }); + S('[' + this.attr_name() +']', this.scope).each(bind); } // # Patch to fix #5043 to move this *after* the if/else clause in order for Backbone and similar frameworks to have improved control over event binding and data-options updating. if (typeof method === 'string') { -- 2.47.2