Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into abort-xhr
Browse files Browse the repository at this point in the history
Conflicts:
	jquery.pjax.js
  • Loading branch information
mislav committed Mar 7, 2015
2 parents 5631350 + d3e5570 commit a2ae3d3
Show file tree
Hide file tree
Showing 23 changed files with 701 additions and 198 deletions.
12 changes: 3 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
sudo: false
language: ruby
rvm:
- 1.9.3

install: gem install sinatra

before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- ruby ./test/app.rb 2>/dev/null &
- sleep 2

script: phantomjs ./test/run-qunit.coffee "http://localhost:4567/"
install: script/bootstrap
script: script/test

notifications:
email: false
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
source 'http://rubygems.org'

ruby '1.9.3'

gem 'sinatra'
gem 'json'
2 changes: 0 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
GEM
remote: http://rubygems.org/
specs:
json (1.8.1)
rack (1.5.2)
rack-protection (1.5.3)
rack
Expand All @@ -15,5 +14,4 @@ PLATFORMS
ruby

DEPENDENCIES
json
sinatra
53 changes: 44 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Or add `jquery-pjax` to your apps `bower.json`.
pjax can be downloaded directly into your app's public directory - just be sure you've loaded jQuery first.

```
curl -O https://raw.github.com/defunkt/jquery-pjax/master/jquery.pjax.js
curl -LO https://raw.github.com/defunkt/jquery-pjax/master/jquery.pjax.js
```

**WARNING** Do not hotlink the raw script url. GitHub is not a CDN.
Expand Down Expand Up @@ -136,16 +136,40 @@ Or try this selector that matches any `<a data-pjax href=>` links inside a `<div
$(document).pjax('[data-pjax] a, a[data-pjax]', '#pjax-container')
```

When invoking `$.fn.pjax` there are a few different argument styles you can use:
#### Arguments

1. `$(document).pjax(delegation selector, options object)`
2. `$(document).pjax(delegation selector, container selector, options object)`
The synopsis for the `$.fn.pjax` function is:

In other words:
``` javascript
$(document).pjax(selector, [container], options)
```

1. `selector` is a string to be used for click [event delegation][$.fn.on].
2. `container` is a string selector that uniquely identifies the pjax container.
3. `options` is an object with keys described below.

##### pjax options

key | default | description
----|---------|------------
`timeout` | 650 | ajax timeout in milliseconds after which a full refresh is forced
`push` | true | use [pushState][] to add a browser history entry upon navigation
`replace` | false | replace URL without adding browser history entry
`maxCacheLength` | 20 | maximum cache size for previous container contents
`version` | | a string or function returning the current pjax version
`scrollTo` | 0 | vertical position to scroll to after navigation
`type` | `"GET"` | see [$.ajax][]
`dataType` | `"html"` | see [$.ajax][]
`container` | | CSS selector for the element where content should be replaced
`url` | link.href | a string or function that returns the URL for the ajax request
`target` | link | eventually the `relatedTarget` value for [pjax events](#events)
`fragment` | | CSS selector for the fragment to extract from ajax response

You can change the defaults globally by writing to the `$.pjax.defaults` object:

1. The first argument must always be a `String` selector used for delegation.
2. The second argument can either be a `String` container selector or an options object.
3. If there are three arguments the second must be the `String` container selector and the third must be the options object.
``` javascript
$.pjax.defaults.timeout = 1200
```

### `$.pjax.click`

Expand Down Expand Up @@ -174,6 +198,14 @@ $(document).on('submit', 'form[data-pjax]', function(event) {
})
```

### `$.pjax.reload`

Initiates a request for the current URL to the server using pjax mechanism and replaces the container with the response. Does not add a browser history entry.

``` javascript
$.pjax.reload('#pjax-container', options)
```

### `$.pjax`

Manual pjax invocation. Used mainly when you want to start a pjax request in a handler that didn't originate from a click. If you can get access to a click `event`, consider `$.pjax.click(event)` instead.
Expand Down Expand Up @@ -336,7 +368,7 @@ Check if your favorite server framework supports pjax here: https://gist.github.

#### Layout Reloading

Layouts can be forced to do a hard reload assets or html changes.
Layouts can be forced to do a hard reload when assets or html changes.

First set the initial layout version in your header with a custom meta tag.

Expand Down Expand Up @@ -406,3 +438,6 @@ $ open http://localhost:4567/

[compat]: http://caniuse.com/#search=pushstate
[gist]: https://gist.github.com/
[$.fn.on]: http://api.jquery.com/on/
[$.ajax]: http://api.jquery.com/jQuery.ajax/
[pushState]: https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history#Adding_and_modifying_history_entries
6 changes: 5 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
{
"name": "jquery-pjax",
"version": "1.8.2",
"version": "1.9.4",
"main": "./jquery.pjax.js",
"dependencies": {
"jquery": ">=1.8"
},
"ignore": [
".travis.yml",
"Gemfile",
"Gemfile.lock",
"vendor/",
"script/",
"test/"
]
}
Loading

0 comments on commit a2ae3d3

Please sign in to comment.