Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
EvandroLG committed Sep 13, 2016
2 parents 3cb7d4c + 59a13fa commit 173e846
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dist/page-accelerator.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/page-accelerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@
var links = doc.querySelectorAll('a:not([data-pageAccelerator="false"])');

[].forEach.call(links, function(element) {
if (element.hostname !== window.location.hostname ||
element.protocol !== window.location.protocol) {
return;
}

element.addEventListener('click', function(e) {
e.preventDefault();
that._onClick.call(that, this);
Expand Down
1 change: 1 addition & 0 deletions test/SpecRunner.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<div id="container-test" style="display: none;">
<a href="#" id="link_1">mock 1</a>
<a href="#" id="link_2" data-pageAccelerator="false">mock 2</a>
<a href="http://github.com" id="link_3">mock 3</a>
</div>
<script src="../src/ajax.js"></script>
<script src="../src/page-accelerator.js"></script>
Expand Down
4 changes: 4 additions & 0 deletions test/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
it('should not call ajax method when user requests a new page by a link with data-pageAccelerator="false"', function() {
verifyAjaxWasCalled(_find('#link_2'), 'false');
});

it('should not call ajax method when user requests a new page on an external domain', function() {
verifyAjaxWasCalled(_find('#link_3'), 'false');
});
});

});
Expand Down

0 comments on commit 173e846

Please sign in to comment.