From: Billy Monk Date: Tue, 27 May 2014 01:00:00 +0000 (-0400) Subject: Use correct 'this' when setting data-interchange-last-path. X-Git-Tag: v5.3.1~36^2 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=refs%2Fpull%2F5230%2Fhead;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Use correct 'this' when setting data-interchange-last-path. 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. --- diff --git a/js/foundation/foundation.interchange.js b/js/foundation/foundation.interchange.js index c9fb7f59f..7e99dd6d9 100644 --- a/js/foundation/foundation.interchange.js +++ b/js/foundation/foundation.interchange.js @@ -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(); }); diff --git a/spec/interchange/interchange.js b/spec/interchange/interchange.js index 97bca03bd..be67bdc62 100644 --- a/spec/interchange/interchange.js +++ b/spec/interchange/interchange.js @@ -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$/) + }); + }); });