Skip to content

Commit

Permalink
Use correct 'this' when setting data-interchange-last-path.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Billy Monk committed May 27, 2014
1 parent 4e1ef6c commit b2118dd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions js/foundation/foundation.interchange.js
Expand Up @@ -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;

Expand All @@ -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();
});

Expand Down
13 changes: 13 additions & 0 deletions spec/interchange/interchange.js
Expand Up @@ -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$/)
});
});
});

0 comments on commit b2118dd

Please sign in to comment.