From: Simon Hewitt Date: Wed, 21 Jan 2015 17:28:22 +0000 (-0800) Subject: simplify and fix check for if events have already been set up X-Git-Tag: v5.5.1~14^2~12^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F6210%2Fhead;p=thirdparty%2Ffoundation%2Ffoundation-sites.git simplify and fix check for if events have already been set up --- 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') {