Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds test updates to #1874 #1937

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/pjax/js/pjax-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ PjaxBase.prototype = {

if (!this._hasSameOrigin(url)) {
Y.error('Security error: The new URL must be of the same origin as the current URL.');
return false;
}

if (this.get('allowFallThrough')) {
// Send paths with the same origin but no matching routes to window.location if specified.
win.location = url;
return true;
}

return false;
Expand Down Expand Up @@ -413,7 +420,20 @@ PjaxBase.ATTRS = {
**/
scrollToTop: {
value: true
},

/**
Whether to set `window.location` when calling `navigate()`
if no routes match the specified URL.

@attribute allowFallThrough
@type Boolean
@default true
@since @SINCE@
**/
allowFallThrough: {
value: true
}
};

Y.PjaxBase = PjaxBase;
Y.PjaxBase = PjaxBase;
12 changes: 10 additions & 2 deletions src/pjax/tests/unit/assets/pjax-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ suite.add(new Y.Test.Case({
'`navigate` event should not fire when a modifier key is pressed': !html5,
'`navigate` event should not fire when a click element is not an anchor': !html5,
'`navigate` event should not fire when a link is clicked with a URL from another origin': !html5,
'`navigate` event should not fire for a hash URL that resolves to the current page': !html5,
'`navigate` event should not fire for a hash URL that resolves to the current page when allowFallThrough is set to `false`': !html5,
'`navigate` event should fire for a hash-less URL that resolves to the current page': !html5,
'`navigate` event should fire for a hash URL that resolves to the current page when `navigateOnHash` is `true`': !html5
}
Expand Down Expand Up @@ -427,7 +427,8 @@ suite.add(new Y.Test.Case({
});
},

'`navigate` event should not fire for a hash URL that resolves to the current page': function () {
'`navigate` event should not fire for a hash URL that resolves to the current page when allowFallThrough is set to `false`': function () {
this.pjax.set("allowFallThrough", false);
this.pjax.on('navigate', function (e) {
Assert.fail();
});
Expand Down Expand Up @@ -569,6 +570,13 @@ suite.add(new Y.Test.Case({

didNavigate = this.pjax.navigate('http://some.random.host.example.com/foo/bar/');
Assert.areSame(false, didNavigate, '`navigate()` did not return `false`');
},

'`navigate()` should fall through to window.location with no matching route': function() {
var currentLocation = win.location;

Assert.isTrue(this.pjax.navigate('#unmatched-route'), 'navigate() did not return `true`');
Assert.areEqual(currentLocation, win.location, 'The current `window.location` does not match the `window.location` before `navigate()`.');
}
}));

Expand Down
1 change: 1 addition & 0 deletions src/pjax/tests/unit/pjax.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<a href="assets/page-full.html" id="link-full" class="yui3-pjax">full page</a>
<a href="assets/page-minimal.html" id="link-minimal" class="yui3-pjax">minimal page</a>
<a href="assets/page-text.html" id="link-text" class="yui3-pjax">text page</a>
<a href="assets/missing/pagedoesnotexist.html" id="unmatched-route" class="yui-pjax">missing page</a>
<a href="#log" id="link-in-page" class="yui3-pjax">in-page</a>
<a href="" id="link-current" class="yui3-pjax">current page</a>
<span id="link-fake" class="yui3-pjax">fake</span>
Expand Down