]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
simplify and fix check for if events have already been set up 6210/head
authorSimon Hewitt <si@sjhewitt.co.uk>
Wed, 21 Jan 2015 17:28:22 +0000 (09:28 -0800)
committerSimon Hewitt <si@sjhewitt.co.uk>
Wed, 21 Jan 2015 17:28:31 +0000 (09:28 -0800)
js/foundation/foundation.js

index 0c185a6b32f746a7276a81afedb64d4851b3fcf9..57182a7f5870ed42a954b32c3a4c92b0c689bd27 100644 (file)
 
   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') {