Pjax: don't match external links #186

Open
wants to merge 3 commits into
from

Projects

None yet

3 participants

@rstacruz
Contributor
rstacruz commented Jan 2, 2017 edited

Fix for docpress/docpress#116.

This opts-out of in-page ajax loading behavior (via pjax) for links that lead to an external page:

- [GitHub](https://github.com)

Also allows for data-no-pjax, which you can apply to any link:

This is a [link](foo.html).
<!-- {a:data-no-pjax} -->
@rstacruz rstacruz changed the title from Only match internal links to Pjax: only match internal links Jan 2, 2017
@rstacruz rstacruz Only match internal links
5305f92
data/script.js
new Pjax({ // eslint-disable-line
- selectors: ['.body', '.toc-menu', 'title'],
+ selectors: ['.body' + link, '.toc-menu' + link, 'title' + link],
@rstacruz
rstacruz Jan 2, 2017 Contributor

oh crap wait this is wrong

@rstacruz rstacruz Don't mess with <a id>
7e95320
@coveralls

Coverage Status

Coverage remained the same at 81.152% when pulling 7e95320 on fix/http-links into 3eacc60 on master.

data/script.js
@@ -13,6 +13,7 @@ var Scrollclass = require('./scrollclass')
void (function () {
ready(function () {
new Pjax({ // eslint-disable-line
+ elements: 'a[href]:not([href^="http://"]):not([href^="https://"])',
@coveralls
coveralls commented Jan 2, 2017 edited

Coverage Status

Coverage remained the same at 81.152% when pulling 7e95320 on fix/http-links into 3eacc60 on master.

@rstacruz rstacruz Honor [data-no-pjax]
c1d96aa
@coveralls
coveralls commented Jan 2, 2017 edited

Coverage Status

Coverage remained the same at 81.152% when pulling c1d96aa on fix/http-links into 3eacc60 on master.

@coveralls
coveralls commented Jan 2, 2017 edited

Coverage Status

Coverage remained the same at 81.152% when pulling c1d96aa on fix/http-links into 3eacc60 on master.

@rstacruz rstacruz changed the title from Pjax: only match internal links to Pjax: don't match external links Jan 2, 2017
@knownasilya
Contributor
knownasilya commented Jan 2, 2017 edited

Nice and simple, ready to merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment