Compare commits

...

7 Commits

Author SHA1 Message Date
Behind The Math
03ebc657f0 0.2.7 2018-08-15 15:26:02 -04:00
BehindTheMath
6f39767cf9 Ensure correct XHR encoding for multipart/form-data forms (#174)
Fixes #168
2018-08-15 15:07:04 -04:00
BehindTheMath
03d64863c8 Fix README. Also pass the current options object to loadContent() (#171)
Fixes #167
2018-07-23 20:46:13 -04:00
BehindTheMath
c36225a24c Fix options.history to correctly parse being set to false (#165)
Fixes #164
2018-06-18 15:42:42 -04:00
Behind The Math
c589ab9c25 Add index.d.ts to package.json so it will be installed by npm 2018-06-17 22:29:58 -04:00
BehindTheMath
8abb21e1e9 Fix parsing values of option elements in forms (#162)
* Fix a bug where the value of <option> would not get sent if falsy

According to the spec, the value attribute should be sent if it
exists, even if it's falsy.

* Don't send an <option> tag if it's disabled, even if it's selected
2018-05-30 15:39:08 -04:00
Robin North
8dbe7553b9 Document refresh and reload methods (#160) 2018-05-29 22:23:23 -04:00
8 changed files with 46 additions and 10 deletions

View File

@@ -1,3 +1,18 @@
# 0.2.7 - 2018-08-15
- Fixed: Parsing values of option elements in forms.
([#162](https://github.com/MoOx/pjax/pull/162) - @BehindTheMath)
- Fixed: Added index.d.ts to package.json so it will be installed by npm.
([c589ab9](https://github.com/MoOx/pjax/commit/c589ab9c25bee6161bf3e557eaca44e51c14fb89) - @BehindTheMath)
- Fixed: `options.history` to correctly parse being set to false.
([#165](https://github.com/MoOx/pjax/pull/165) - @BehindTheMath).
- Fixed: Pass the current `options` object to `loadContent()`.
([#171](https://github.com/MoOx/pjax/pull/171) - @BehindTheMath)
- Fixed: Ensure correct XHR encoding for multipart/form-data forms
([#174](https://github.com/MoOx/pjax/pull/174) - @BehindTheMath)
- Added: More documentation.
([#160](https://github.com/MoOx/pjax/pull/160), [#171](https://github.com/MoOx/pjax/pull/171) - @robinnorth, @BehindTheMath)
# 0.2.6 - 2018-04-30
- Fixed: Form submission for GET requests.

View File

@@ -172,7 +172,7 @@ pjax.loadUrl("/your-url")
pjax.loadUrl("/your-other-url", {timeout: 10})
```
#### `handleResponse(responseText, request, href)`
#### `handleResponse(responseText, request, href, options)`
This method takes the raw response, processes the URL, then calls `pjax.loadContent()` to actually load it into the DOM.
@@ -181,6 +181,7 @@ It is passed the following arguments:
* **responseText** (string): This is the raw response text. This is equivalent to `request.responseText`.
* **request** (XMLHttpRequest): This is the XHR object.
* **href** (string): This is the URL that was passed to `loadUrl()`.
* **options** (object): This is an object with the options for this request. The structure basically matches the regular options object, with a few extra internal properties.
You can override this if you want to process the data before, or instead of, it being loaded into the DOM.
@@ -191,15 +192,33 @@ var pjax = new Pjax();
pjax._handleResponse = pjax.handleResponse;
pjax.handleResponse = function(responseText, request, href) {
pjax.handleResponse = function(responseText, request, href, options) {
if (request.responseText.match("<html")) {
pjax._handleResponse(responseText, request, href);
pjax._handleResponse(responseText, request, href, options);
} else {
// handle response here
}
}
```
#### `refresh([el])`
Use this method to bind Pjax to children of a DOM element that didn't exist when Pjax was initialised e.g. content inserted dynamically by another library or script. If called with no arguments, Pjax will parse the entire document again to look for newly-inserted elements.
```js
// Inside a callback or Promise that runs after new DOM content has been inserted
var newContent = document.querySelector(".new-content");
pjax.refresh(newContent);
```
#### `reload()`
A helper shortcut for `window.location.reload()`. Used to force a page reload.
### Options
##### `elements` (String, default: `"a[href], form[action]"`)

View File

@@ -36,6 +36,7 @@ var Pjax = function(options) {
var opt = clone(this.options)
opt.url = st.state.url
opt.title = st.state.title
// Since state already exists, prevent it from being pushed again
opt.history = false
opt.scrollPos = st.state.scrollPos
if (st.state.uid < this.lastUid) {

View File

@@ -8,7 +8,7 @@ module.exports = function(options) {
options.selectors = options.selectors || ["title", ".js-Pjax"]
options.switches = options.switches || {}
options.switchesOptions = options.switchesOptions || {}
options.history = options.history || true
options.history = (typeof options.history === "undefined") ? true : options.history
options.analytics = (typeof options.analytics === "function" || options.analytics === false) ? options.analytics : defaultAnalytics
options.scrollTo = (typeof options.scrollTo === "undefined") ? 0 : options.scrollTo
options.scrollRestoration = (typeof options.scrollRestoration !== "undefined") ? options.scrollRestoration : true

View File

@@ -67,8 +67,8 @@ function parseFormElements(el) {
for (var i = 0; i < element.options.length; i++) {
opt = element.options[i]
if (opt.selected) {
values.push(opt.value || opt.text)
if (opt.selected && !opt.disabled) {
values.push(opt.hasAttribute("value") ? opt.value : opt.text)
}
}
}

View File

@@ -52,7 +52,7 @@ module.exports = function(responseText, request, href, options) {
this.state.options = options
try {
this.loadContent(responseText, this.options)
this.loadContent(responseText, options)
}
catch (e) {
trigger(document, "pjax:error", options)

View File

@@ -68,7 +68,7 @@ module.exports = function(location, options, callback) {
request.setRequestHeader("X-PJAX-Selectors", JSON.stringify(options.selectors))
// Send the proper header information for POST forms
if (requestPayload && requestMethod === "POST") {
if (requestPayload && requestMethod === "POST" && !formData) {
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
}

View File

@@ -1,6 +1,6 @@
{
"name": "pjax",
"version": "0.2.6",
"version": "0.2.7",
"description": "Easily enable fast AJAX navigation on any website (using pushState + XHR)",
"keywords": [
"pjax",
@@ -22,7 +22,8 @@
"index.js",
"lib",
"pjax.js",
"pjax.min.js"
"pjax.min.js",
"index.d.ts"
],
"types": "index.d.ts",
"devDependencies": {