From 20392226fc1f41a86930ede9045c2e58bbe019a6 Mon Sep 17 00:00:00 2001 From: Matt Ezell Date: Sun, 30 Jun 2013 20:20:59 -0400 Subject: [PATCH] Add documentation for pjax options --- README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/README.md b/README.md index 9bdad36d..86cd52fb 100644 --- a/README.md +++ b/README.md @@ -228,6 +228,29 @@ $(document).on('pjax:timeout', function(event) { }) ``` +### Options + +The following options might be useful to customize behavior: + +* `timeout` - A timeout on ajax requests +* `type` - The HTTP method to use (defaults to GET) +* `dataType` - Defaults to html +* `scrollTo` - A position to scroll the page to after pjax. Defaults to 0 +* `maxCacheLength` - The number of history states to cache +* `fragment` - Set to load only a part of the target URL's content + +By default, the `scrollTo` parameter causes each click to scroll to the top of the page. This simulates normal browsing behavior. To disable this behavior, set the `scrollTo` parameter to false. + +``` javascript +$(document).pjax('a', '#pjax-container', {scrollTo: false}); +``` + +or set a default for requests + +``` javascript +$.pjax.defaults.scrollTo = false; +``` + ### Server side Server configuration will vary between languages and frameworks. The following example shows how you might configure Rails. @@ -244,6 +267,12 @@ An `X-PJAX` request header is set to differentiate a pjax request from normal XH Check if your favorite server framework supports pjax here: https://gist.github.com/4283721 +If you are not using a server framework that can detect the `X-PJAX` header (or if you are using static HTML files), use the `fragment` option to restrict what gets loaded. + +``` javascript +$(document).pjax('a', '#pjax-container', {fragment: '#pjax-container'}); +``` + #### Layout Reloading Layouts can be forced to do a hard reload assets or html changes.