Skip to content

Commit dd672d5

Browse files
committed
Merge branch 'docs'
Fixes #329 [ci skip]
2 parents 4f162c7 + 1ec6aaf commit dd672d5

File tree

3 files changed

+94
-62
lines changed

3 files changed

+94
-62
lines changed

CONTRIBUTING.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Contributing
2+
3+
For running the tests, you will need:
4+
5+
* Ruby 1.9.3+ with Bundler
6+
* PhantomJS (for headless testing)
7+
8+
First run bootstrap to ensure necessary dependencies:
9+
10+
```
11+
$ script/bootstrap
12+
```
13+
14+
Then run headless tests in the console:
15+
16+
```
17+
$ script/test [<test-file>]
18+
```
19+
20+
To run tests in other browsers, start a server:
21+
22+
```
23+
$ script/server
24+
# now open http://localhost:4567/
25+
```
26+
27+
## Test structure
28+
29+
There are 3 main test modules:
30+
31+
* `test/unit/fn_pjax.js` - Primarily tests the `$.fn.pjax` method and its options
32+
* `test/unit/pjax.js` - Main comprehensive pjax functionality tests
33+
* `test/unit/pjax_fallback.js` - Tests that verify same result after navigation
34+
even if pjax is disabled (like for browsers that don't support pushState).
35+
36+
Each test drives a hidden test page in an `<iframe>`. See other tests to see how
37+
they trigger pjax by using the `frame` reference and remember to do so as well.

README.md

Lines changed: 50 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# pjax
1+
# pjax = pushState + ajax
22

33

44
.--.
@@ -21,11 +21,15 @@
2121
jgs |___\_.\_
2222
`-"--'---'
2323

24-
## pjax = pushState + ajax
24+
## Introduction
2525

2626
pjax is a jQuery plugin that uses ajax and pushState to deliver a fast browsing experience with real permalinks, page titles, and a working back button.
2727

28-
pjax works by grabbing html from your server via ajax and replacing the content of a container on your page with the ajax'd html. It then updates the browser's current url using pushState without reloading your page's layout or any resources (js, css), giving the appearance of a fast, full page load. But really it's just ajax and pushState.
28+
pjax works by grabbing html from your server via ajax and replacing the content
29+
of a container on your page with the ajax'd html. It then updates the browser's
30+
current URL using pushState without reloading your page's layout or any
31+
resources (JS, CSS), giving the appearance of a fast, full page load. But really
32+
it's just ajax and pushState.
2933

3034
For [browsers that don't support pushState][compat] pjax fully degrades.
3135

@@ -50,7 +54,9 @@ Consider the following page.
5054
</html>
5155
```
5256

53-
We want pjax to grab the url `/page/2` then replace `#pjax-container` with whatever it gets back. No styles or scripts will be reloaded and even the h1 can stay the same - we just want to change the `#pjax-container` element.
57+
We want pjax to grab the URL `/page/2` then replace `#pjax-container` with
58+
whatever it gets back. No styles or scripts will be reloaded and even the `<h1>`
59+
can stay the same - we just want to change the `#pjax-container` element.
5460

5561
We do this by telling pjax to listen on `a` tags and use `#pjax-container` as the target container:
5662

@@ -74,21 +80,21 @@ def index
7480
end
7581
```
7682

77-
If you'd like a more automatic solution than pjax for Rails check out [Turbolinks](https://github.com/rails/turbolinks).
83+
If you'd like a more automatic solution than pjax for Rails check out [Turbolinks][].
7884

79-
Also check out [RailsCasts #294 : Playing with PJAX](http://railscasts.com/episodes/294-playing-with-pjax)
85+
Also check out [RailsCasts #294: Playing with PJAX][railscasts].
8086

8187
## Installation
8288

8389
### bower
8490

85-
Via [bower](https://github.com/twitter/bower).
91+
Via [Bower][]:
8692

8793
```
8894
$ bower install jquery-pjax
8995
```
9096

91-
Or add `jquery-pjax` to your apps `bower.json`.
97+
Or, add `jquery-pjax` to your app's `bower.json`.
9298

9399
``` json
94100
"dependencies": {
@@ -112,7 +118,9 @@ Requires jQuery 1.8.x or higher.
112118

113119
## Compatibility
114120

115-
pjax only works with [browsers that support the `history.pushState` API][compat]. When the API isn't supported pjax goes into fallback mode: `$.fn.pjax` calls will be a no-op and `$.pjax` will hard load the given url. This mode targets the browser requirements of the jQuery version being used.
121+
pjax only works with [browsers that support the `history.pushState`
122+
API][compat]. When the API isn't supported pjax goes into fallback mode:
123+
`$.fn.pjax` calls will be a no-op and `$.pjax` will hard load the given URL.
116124

117125
For debugging purposes, you can intentionally disable pjax even if the browser supports `pushState`. Just call `$.pjax.disable()`. To see if pjax is actually supports `pushState`, check `$.support.pjax`.
118126

@@ -190,7 +198,7 @@ if ($.support.pjax) {
190198

191199
### `$.pjax.submit`
192200

193-
Submits a form via pjax. This function is experimental but GitHub uses it on [Gist][gist] so give it a shot!
201+
Submits a form via pjax.
194202

195203
``` javascript
196204
$(document).on('submit', 'form[data-pjax]', function(event) {
@@ -364,7 +372,34 @@ end
364372

365373
An `X-PJAX` request header is set to differentiate a pjax request from normal XHR requests. In this case, if the request is pjax, we skip the layout html and just render the inner contents of the container.
366374

367-
Check if your favorite server framework supports pjax here: https://gist.github.com/4283721
375+
[Check if there is a pjax plugin][plugins] for your favorite server framework.
376+
377+
#### Response types that force a reload
378+
379+
By default, pjax will force a full reload of the page if it receives one of the
380+
following responses from the server:
381+
382+
* Page content that includes `<html>` when `fragment` selector wasn't explicitly
383+
configured. Pjax presumes that the server's response hasn't been properly
384+
configured for pjax. If `fragment` pjax option is given, pjax will simply
385+
extract the content to insert into the DOM based on that selector.
386+
387+
* Page content that is blank. Pjax assumes that the server is unable to deliver
388+
proper pjax contents.
389+
390+
* HTTP response code that is 4xx or 5xx, indicating some server error.
391+
392+
#### Affecting the browser URL
393+
394+
If the server needs to affect the URL which will appear in the browser URL after
395+
pjax navigation (like HTTP redirects work for normal requests), it can set the
396+
`X-PJAX-URL` header:
397+
398+
``` ruby
399+
def index
400+
request.headers['X-PJAX-URL'] = "http://example.com/hello"
401+
end
402+
```
368403

369404
#### Layout Reloading
370405

@@ -386,58 +421,11 @@ end
386421

387422
Deploying a deploy, bumping the version constant to force clients to do a full reload the next request getting the new layout and assets.
388423

389-
### Legacy API
390-
391-
Pre 1.0 versions used an older style syntax that was analogous to the now deprecated `$.fn.live` api. The current api is based off `$.fn.on`.
392-
393-
``` javascript
394-
$('a[data-pjax]').pjax('#pjax-container')
395-
```
396-
397-
Expanded to
398-
399-
``` javascript
400-
$('a[data-pjax]').live('click', function(event) {
401-
$.pjax.click(event, '#pjax-container')
402-
})
403-
```
404-
405-
The new api
406-
407-
``` javascript
408-
$(document).pjax('a[data-pjax]', '#pjax-container')
409-
```
410-
411-
Which is roughly the same as
412-
413-
``` javascript
414-
$(document).on('click', 'a[data-pjax]', function(event) {
415-
$.pjax.click(event, '#pjax-container')
416-
})
417-
```
418-
419-
**NOTE** The new api gives you control over the delegated element container. `$.fn.live` always bound to `document`. This is what you still want to do most of the time.
420-
421-
## Contributing
422-
423-
```
424-
$ git clone https://github.com/defunkt/jquery-pjax.git
425-
$ cd jquery-pjax/
426-
```
427-
428-
To run the test suite locally, start up the Sinatra test application.
429-
430-
```
431-
$ bundle install
432-
$ bundle exec ruby test/app.rb
433-
== Sinatra/1.4.5 has taken the stage on 4567 for development with backup from WEBrick
434-
435-
# in another tab:
436-
$ open http://localhost:4567/
437-
```
438-
439424
[compat]: http://caniuse.com/#search=pushstate
440-
[gist]: https://gist.github.com/
441425
[$.fn.on]: http://api.jquery.com/on/
442426
[$.ajax]: http://api.jquery.com/jQuery.ajax/
443427
[pushState]: https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history#Adding_and_modifying_history_entries
428+
[plugins]: https://gist.github.com/4283721
429+
[turbolinks]: https://github.com/rails/turbolinks
430+
[railscasts]: http://railscasts.com/episodes/294-playing-with-pjax
431+
[bower]: https://github.com/twitter/bower

script/bootstrap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,10 @@
22
set -e
33

44
bundle install
5+
6+
if phantom_version="$(phantomjs --version)"; then
7+
echo "PhantomJS $phantom_version"
8+
else
9+
echo "Warning: script/test will not be able to run, but you can still start" >&2
10+
echo "script/server and open the test suite in your browser." >&2
11+
fi

0 commit comments

Comments
 (0)