├── .editorconfig ├── .eslintignore ├── .eslintrc.json ├── .gitignore ├── .prettierignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── example ├── example.js ├── forms.html ├── index.html ├── page2.html └── page3.html ├── index.d.ts ├── index.js ├── lib ├── abort-request.js ├── eval-script.js ├── events │ ├── off.js │ ├── on.js │ └── trigger.js ├── execute-scripts.js ├── foreach-els.js ├── foreach-selectors.js ├── is-supported.js ├── parse-options.js ├── proto │ ├── attach-form.js │ ├── attach-link.js │ ├── handle-response.js │ ├── log.js │ └── parse-element.js ├── send-request.js ├── switches-selectors.js ├── switches.js ├── uniqueid.js └── util │ ├── clone.js │ ├── contains.js │ ├── extend.js │ ├── noop.js │ └── update-query-string.js ├── package.json ├── pjax.js ├── pjax.min.js └── tests ├── lib ├── abort-request.js ├── eval-scripts.js ├── events.js ├── execute-scripts.js ├── foreach-els.js ├── foreach-selectors.js ├── is-supported.js ├── parse-options.js ├── proto │ ├── attach-form.js │ ├── attach-link.js │ ├── handle-response.js │ └── parse-element.js ├── send-request.js ├── switch-selectors.js ├── switches.js ├── uniqueid.js └── util │ ├── clone.js │ ├── contains.js │ ├── extend.js │ ├── noop.js │ └── update-query-string.js ├── setup.js └── test.ts /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | indent_style = space 10 | indent_size = 2 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | 15 | [Makefile] 16 | indent_style = tab 17 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | pjax.js 2 | pjax.min.js 3 | *.json 4 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["eslint-config-i-am-meticulous/es5"], 3 | "rules": { 4 | "import/order": "off", 5 | "import/max-dependencies": "off", 6 | "import/extensions": ["error", "never"] 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | .nyc_output/ 4 | .idea/ 5 | dist/ 6 | coverage/ 7 | tests/scripts/index.html 8 | package-lock.json 9 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | pjax.js 2 | pjax.min.js 3 | *.json 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: "node_js" 2 | node_js: 3 | - "10" 4 | 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 0.2.8 - 2019-03-09 2 | 3 | - Fixed: Edge form support. 4 | ([#178](https://github.com/MoOx/pjax/pull/178) - @robinnorth) 5 | - Fixed: Removed keyup event listener for forms. 6 | ([#184](https://github.com/MoOx/pjax/pull/184) - @BehindTheMath) 7 | - Fixed: Bugs in evalScripts(). 8 | ([#186](https://github.com/MoOx/pjax/pull/186) - @BehindTheMath) 9 | - Fixed: Handle non-string HTML passed to loadContent(). 10 | ([#200](https://github.com/MoOx/pjax/pull/200) - @BehindTheMath) 11 | - Tooling: Switch linting to ESLint and Prettier. 12 | ([#191](https://github.com/MoOx/pjax/pull/191) - @BehindTheMath) 13 | 14 | # 0.2.7 - 2018-08-15 15 | 16 | - Fixed: Parsing values of option elements in forms. 17 | ([#162](https://github.com/MoOx/pjax/pull/162) - @BehindTheMath) 18 | - Fixed: Added index.d.ts to package.json so it will be installed by npm. 19 | ([c589ab9](https://github.com/MoOx/pjax/commit/c589ab9c25bee6161bf3e557eaca44e51c14fb89) - @BehindTheMath) 20 | - Fixed: `options.history` to correctly parse being set to false. 21 | ([#165](https://github.com/MoOx/pjax/pull/165) - @BehindTheMath). 22 | - Fixed: Pass the current `options` object to `loadContent()`. 23 | ([#171](https://github.com/MoOx/pjax/pull/171) - @BehindTheMath) 24 | - Fixed: Ensure correct XHR encoding for multipart/form-data forms 25 | ([#174](https://github.com/MoOx/pjax/pull/174) - @BehindTheMath) 26 | - Added: More documentation. 27 | ([#160](https://github.com/MoOx/pjax/pull/160), [#171](https://github.com/MoOx/pjax/pull/171) - @robinnorth, @BehindTheMath) 28 | 29 | # 0.2.6 - 2018-04-30 30 | 31 | - Fixed: Form submission for GET requests. 32 | ([#129](https://github.com/MoOx/pjax/pull/129) - @robinnorth) 33 | - Fixed: Refactor `loadUrl()` to make manually calling simpler. 34 | ([#134](https://github.com/MoOx/pjax/pull/134) - @robinnorth) 35 | - Fixed: Support multiple select fields in form submissions. 36 | ([#147](https://github.com/MoOx/pjax/pull/147) - @robinnorth) 37 | - Fixed: Use the same options object in `handle-response` as in `send-request`. This way, `pjax.state.options` will also have the request options. 38 | ([#148](https://github.com/MoOx/pjax/pull/148) - @BehindTheMath) 39 | - Added: Move the XHR callback to a separate method, and trigger an error event if the response cannot be parsed. 40 | ([#137](https://github.com/MoOx/pjax/pull/137) - @BehindTheMath) 41 | - Added: TypeScript definitions. 42 | ([#138](https://github.com/MoOx/pjax/pull/138) - @BehindTheMath) 43 | - Added: `replaceNode` switch, as an alternative to the `outerHTML` switch. 44 | ([#141](https://github.com/MoOx/pjax/pull/141) - @BehindTheMath) 45 | - Added: `X-PJAX-Selectors` HTTP header. This is a serialized JSON array of selectors, taken from `options.selectors`. You can use this to send back only the elements that Pjax will use to switch, instead of sending the whole page. 46 | ([#144](https://github.com/MoOx/pjax/pull/144) - @BehindTheMath) 47 | - Added: An option to use `FormData` to submit forms. 48 | ([#153](https://github.com/MoOx/pjax/pull/153) - @BehindTheMath) 49 | - Added: Tests. 50 | ([f98f2dd](https://github.com/MoOx/pjax/commit/f98f2dd63b48113ff91b6bd8808257bfc723ef6b), [#145](https://github.com/MoOx/pjax/pull/145) - @robinnorth, @BehindTheMath) 51 | 52 | # 0.2.5 - 2018-02-02 53 | 54 | - Fixed: Async switch functions now work correctly, because the DOM is now parsed after all the switches finish. 55 | ([#79](https://github.com/MoOx/pjax/pull/79), [#110](https://github.com/MoOx/pjax/pull/110) - @oskarrough, @BehindTheMath, @robinnorth) 56 | - Fixed: Bug on IE11 preventing AJAX page refresh. 57 | ([#81](https://github.com/MoOx/pjax/pull/81) - @CPTechnikVX) 58 | - Fixed: Default switches are now available as `Pjax.switches`. 59 | ([#92](https://github.com/MoOx/pjax/pull/92) - @BehindTheMath) 60 | - Fixed: An error that was caused by a missing `switchElementsAlt`. 61 | ([#93](https://github.com/MoOx/pjax/pull/93), [#104](https://github.com/MoOx/pjax/pull/104) - @BehindTheMath, @robinnorth) 62 | - Fixed: Incorrect `main` field in npm package 63 | ([#105](https://github.com/MoOx/pjax/pull/105) - @robinnorth) 64 | - Fixed: A pending XHR is now aborted if the user navigates somewhere else before the request is finished. 65 | ([#114](https://github.com/MoOx/pjax/pull/114) - @robinnorth) 66 | - Fixed: When rendering new content, focus will now be removed only from elements within one of the containers manipulated by Pjax. 67 | ([#116](https://github.com/MoOx/pjax/pull/116) - @BehindTheMath) 68 | - Fixed: Stop dispatching extraneous `pjax:complete` events when external scripts load 69 | ([#118](https://github.com/MoOx/pjax/pull/118) - @robinnorth) 70 | - Added: Send the `X-PJAX` header with XHR requests. 71 | ([#80](https://github.com/MoOx/pjax/pull/80) - @bram1028) 72 | - Added: Direct download link for script tags. (@MoOx) 73 | - Added: Pass the element that triggered Pjax to the `pjax:send` event. 74 | ([#94](https://github.com/MoOx/pjax/pull/94) - @BehindTheMath) 75 | - Added: An option to set a timeout for XHR requests. 76 | ([#95](https://github.com/MoOx/pjax/pull/95) - @BehindTheMath) 77 | - Added: Checks for XHR redirects 78 | ([#101](https://github.com/MoOx/pjax/pull/101) - @BehindTheMath) 79 | - Added: Save scroll position with history, and restore when navigating backwards or forwards. 80 | ([#110](https://github.com/MoOx/pjax/pull/110), [#119](https://github.com/MoOx/pjax/pull/119) - @BehindTheMath, @robinnorth) 81 | - Added: Scroll to element position when URL contains a hash 82 | ([#110](https://github.com/MoOx/pjax/pull/110) - @BehindTheMath) 83 | - Added: Minified version of the Pjax bundle. 84 | ([#115](https://github.com/MoOx/pjax/pull/115) - @BehindTheMath) 85 | - Changed: Miscellaneous code and tests cleanup. 86 | ([#96](https://github.com/MoOx/pjax/pull/96), [#98](https://github.com/MoOx/pjax/pull/98), [#99](https://github.com/MoOx/pjax/pull/99), [#100](https://github.com/MoOx/pjax/pull/1070), [#107](https://github.com/MoOx/pjax/pull/107), [#113](https://github.com/MoOx/pjax/pull/113), [#120](https://github.com/MoOx/pjax/pull/120) - @BehindTheMath, @MoOx, @robinnorth) 87 | 88 | # 0.2.4 - 2016-06-28 89 | 90 | - Fixed: ``refresh`` should now work (use `this.parseDOM` for refresh) 91 | ([#67](https://github.com/MoOx/pjax/pull/67) - @compressed) 92 | - Fixed: Some attributes, such as `itemscope` have no corresponding value. 93 | This change allows them to still be set. 94 | ([#67](https://github.com/MoOx/pjax/pull/67) - @compressed) 95 | - Added: ``cacheBust`` option 96 | ([#71](https://github.com/MoOx/pjax/pull/71) - @tremby) 97 | 98 | # 0.2.3 - 2016-03-24 99 | 100 | - Fixed: ``currentUrlFullReload`` option now works 101 | - Fixed: ``this.reload`` is now a Function 102 | ([#65](https://github.com/MoOx/pjax/issues/65)) 103 | 104 | # 0.2.2 - 2016-03-12 105 | 106 | - Fixed: added back standalone version in `./pjax.js` 107 | ([#57](https://github.com/MoOx/pjax/issues/57) 108 | - Fixed: error when using pjax with google analytics (``options`` was undefined) 109 | ([#59](https://github.com/MoOx/pjax/pull/59)) 110 | - Fixed: HierarchyRequestError error 111 | ([#49](https://github.com/MoOx/pjax/pull/49)) 112 | - Fixed: ``TypeError: Pjax.forEachEls is not a function`` 113 | ([#52](https://github.com/MoOx/pjax/pull/52)) 114 | - Fixed: ``TypeError: Pjax.executeScripts is not a function`` 115 | ([#52](https://github.com/MoOx/pjax/pull/52)) 116 | - Fixed: ``TypeError: Pjax.clone is not a function`` 117 | ([#52](https://github.com/MoOx/pjax/pull/52)) 118 | - Added: Ignore events with prevented defaults 119 | ([#50](https://github.com/MoOx/pjax/pull/50)) 120 | 121 | # 0.2.1 - 2015-02-04 122 | 123 | - Fixed: it's better when a release have actual files. 124 | 125 | # 0.2.0 - 2015-02-04 126 | 127 | - Fixed: prevent scrollTo from being converted from false to 0 ([#33](https://github.com/MoOx/pjax/pull/33)) 128 | - Changed: code exploded in commonjs style 129 | - Added: lots of tests 130 | - Added: `refresh` method to force update a DOM element ([#36](https://github.com/MoOx/pjax/pull/36)) 131 | 132 | # 0.1.4 - 2014-10-14 133 | 134 | - Fixed: allow to load pages without any attributes on `` element (fix [#6](https://github.com/MoOx/pjax/issues/6)) 135 | - Fixed: make `Pjax.switches.sideBySide` method usable (fix [#13](https://github.com/MoOx/pjax/issues/13)) 136 | 137 | # 0.1.3 - 2014-09-16 138 | 139 | - Fixed: clicking on the current url somewhere does not produce a full reload by default (see option `currentUrlFullReload`) 140 | - Fixed: `document.implementation.createHTMLDocument` error (in IE10, ref [#16](https://github.com/MoOx/pjax/pull/16)) 141 | 142 | # 0.1.2 - 2014-04-03 143 | 144 | - Changed: `pjax.js` relocated in `src/` 145 | - Fixed: `` attributes of pjaxified document are now available 146 | 147 | # 0.1.1 - 2014-04-02 148 | 149 | - Fixed: safer UMD wrapper (fix concat issue) 150 | 151 | # 0.1.0 - 2014-03-24 152 | 153 | ✨ Initial release 154 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Maxime Thirouin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

PJAX for NexT

2 | 3 |

Installation

4 | 5 |

If you want to use the CDN instead of clone this repo, please jump to the Step 3.

6 | 7 |

Step 1 → Go to NexT dir

8 | 9 | Change dir to **NexT** directory. There must be `layout`, `source`, `languages` and other directories: 10 | 11 | ```sh 12 | $ cd themes/next 13 | $ ls 14 | _config.yml crowdin.yml docs gulpfile.js languages layout LICENSE.md package.json README.md scripts source 15 | ``` 16 | 17 |

Step 2 → Get module

18 | 19 | Install module to `source/lib` directory: 20 | 21 | ```sh 22 | $ git clone https://github.com/theme-next/theme-next-pjax source/lib/pjax 23 | ``` 24 | 25 |

Step 3 → Set it up

26 | 27 | Enable module in **NexT** `_config.yml` file and select your theme: 28 | 29 | ```yml 30 | pjax: true 31 | ``` 32 | 33 | **And, if you wants to use the CDN, then need to set:** (you also need to find your corresponding theme css link in jsdelivr) 34 | 35 | ```yml 36 | vendors: 37 | ... 38 | pjax: //cdn.jsdelivr.net/gh/theme-next/theme-next-pjax@0/pjax.min.js 39 | ``` 40 | 41 |

Update

42 | 43 | ```sh 44 | $ cd themes/next/source/lib/pjax 45 | $ git pull 46 | ``` 47 | 48 | # Pjax 49 | 50 | [![Build Status](https://img.shields.io/travis/MoOx/pjax.svg)](https://travis-ci.org/MoOx/pjax). 51 | 52 | > Easily enable fast AJAX navigation on any website (using pushState() + XHR) 53 | 54 | Pjax is **a standalone JavaScript module** that uses [AJAX](https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX) (XmlHttpRequest) and [pushState()](https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history) to deliver a fast browsing experience. 55 | 56 | _It allows you to completely transform the user experience of standard websites (server-side generated or static ones) to make users feel like they are browsing an app, especially for those with low bandwidth connections._ 57 | 58 | **No more full page reloads. No more multiple HTTP requests.** 59 | 60 | _Pjax does not rely on other libraries, like jQuery or similar. It is written entirely in vanilla JS._ 61 | 62 | ## Installation 63 | 64 | - You can link directly to the [bundle](https://cdn.jsdelivr.net/npm/pjax/pjax.js): 65 | ```html 66 | 67 | ``` 68 | 69 | - Or the [minified bundle](https://cdn.jsdelivr.net/npm/pjax/pjax.min.js): 70 | ```html 71 | 72 | ``` 73 | 74 | - You can also install Pjax from **npm**: 75 | ```shell 76 | npm install pjax 77 | ``` 78 | **Note**: If you use this option, you will need to do one of the following: 79 | - Link a script tag to either `pjax.js` or `pjax.min.js`. E.g.: 80 | ```html 81 | 82 | ``` 83 | - Use a bundler like Webpack. (`index.js` cannot be used in the browser without a bundler). 84 | 85 | - Or you can clone the repo and build the bundle from the source using npm: 86 | ```shell 87 | git clone https://github.com/MoOx/pjax.git 88 | cd pjax 89 | npm install 90 | npm run build 91 | ``` 92 | and then link a script tag to either `pjax.js` or `pjax.min.js`. E.g.: 93 | ```html 94 | 95 | ``` 96 | 97 | --- 98 | 99 | ## What Pjax Does 100 | 101 | _Under the hood, it's just ONE HTTP request with a `pushState()` call._ 102 | 103 | Pjax loads pages using AJAX and updates the browser's current URL using `pushState()` _without_ reloading your page's layout or any resources (JS, CSS), giving a fast page load. 104 | 105 | It works with all permalinks and can update all the parts of the page you want (including HTML metas, title, and navigation state). 106 | 107 | In the case of [browsers that don't support `history.pushState()`](http://caniuse.com/#search=pushstate), Pjax gracefully degrades and does not do anything at all. 108 | 109 | Additionally, Pjax: 110 | 111 | - Is not limited to one container, like jQuery-Pjax is. 112 | - Fully supports browser history (back and forward buttons). 113 | - Supports keyboard browsing. 114 | - Automatically falls back to standard navigation for external pages (thanks to Captain Obvious's help). 115 | - Automatically falls back to standard navigation for internal pages that do not have an appropriate DOM tree. 116 | - Allows for CSS transitions (animations) very easily. 117 | - Is only around 6kb (minified and gzipped). 118 | 119 | ## How Pjax Works 120 | 121 | - It listens to every click on links _you want_ (by default all of them). 122 | - When an internal link is clicked, Pjax fetches the page's HTML via AJAX. 123 | - Pjax renders the page's DOM tree (without loading any resources - images, CSS, JS, etc). 124 | - It checks that all defined parts can be replaced: 125 | - If the page doesn't meet the requirements, standard navigation is used. 126 | - If the page meets the requirements, Pjax does all defined DOM replacements. 127 | - Then it updates the browser's current URL using `pushState()`. 128 | 129 | ## Overview 130 | 131 | _Pjax is fully automatic_. You don't need to change anything about your existing HTML, 132 | you just need to designate which elements on your page that you want to be replaced when your site is navigated. 133 | 134 | Consider the following page. 135 | 136 | ```html 137 | 138 | 139 | 140 | 141 | My Cool Blog 142 | 143 | 144 | 145 | 146 | 147 |
148 | 153 |
154 | 155 |
156 |

My Cool Blog

157 |

158 | Thanks for stopping by! 159 | 160 | Click Here to find out more about me. 161 |

162 |
163 | 164 | 168 | 169 | 172 | 173 | 174 | 177 | 178 | 179 | ``` 180 | 181 | We want Pjax to intercept the URL `/about`, and replace `.the-content` with the resulting content of the request. 182 | 183 | It would also be nice if we could replace the `