]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Use correct 'this' when setting data-interchange-last-path. 5230/head
authorBilly Monk <billy.monk@gmail.com>
Tue, 27 May 2014 01:00:00 +0000 (21:00 -0400)
committerBilly Monk <billy.monk@gmail.com>
Tue, 27 May 2014 01:00:00 +0000 (21:00 -0400)
Because the 'this' being used was for the wrong scope
data-interchange-last-path is not set. This can lead to making multiple
requests for the same content unnecessarily.

js/foundation/foundation.interchange.js
spec/interchange/interchange.js

index c9fb7f59fb3f00a67161af0ec3d4e2d77d72098e..7e99dd6d90d5f10e2f2d0ac7aef37fd15efe1157 100644 (file)
@@ -53,7 +53,8 @@
 
             return trigger(el[0].src);
           }
-          var last_path = el.data(this.data_attr + '-last-path');
+          var last_path = el.data(this.data_attr + '-last-path'),
+              self = this;
 
           if (last_path == path) return;
 
@@ -65,7 +66,7 @@
 
           return $.get(path, function (response) {
             el.html(response);
-            el.data(this.data_attr + '-last-path', path);
+            el.data(self.data_attr + '-last-path', path);
             trigger();
           });
 
index 97bca03bd63c332ab38513ee19f5c706c2426c8a..be67bdc621bac8843fff2326427279171b545800 100644 (file)
@@ -57,4 +57,17 @@ describe('interchange:', function() {
         });
       });
   }));
+
+  describe('setting data-interchange-last-path', function() {
+    beforeEach(function() {
+      document.body.innerHTML = __html__['spec/interchange/basic.html'];
+    });
+
+    it('should set data-interchange-last-path on element when replace occurs', function() {
+      Foundation.libs.interchange.update_nodes();
+      Foundation.libs.interchange.resize();
+
+      expect($('div[data-interchange]').data('data-interchange-last-path')).toMatch(/.+html$/)
+    });
+  });
 });