Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Container must be a string. Sorry.

  • Loading branch information...
commit 91e8c559d44983bf969e083a04f0da0c9a232708 1 parent c9e4d05
@defunkt defunkt authored
Showing with 19 additions and 9 deletions.
  1. +6 −3 README
  2. +13 −6 jquery.pjax.js
View
9 README
@@ -68,11 +68,14 @@ You can find a demo at http://pjax.heroku.com/
## $(link).pjax( container, options )
The $(link).pjax() function accepts a container, an options object,
-or both. The options are the same as jQuery's $.ajax options with the
+or both. The container MUST be a string selector - this is because we
+cannot persist jQuery objects using the History API between page loads.
+
+The options are the same as jQuery's $.ajax options with the
following additions:
- container - The selector of the container to load the reponse body
- into, or the container itself.
+ container - The String selector of the container to load the reponse
+ body. Must be a String.
clickedElement - The element that was clicked to start the pjax call.
push - Whether to pushState the URL. Defaults to true (of course).
replace - Whether to replaceState the URL. Defaults to false.
View
19 jquery.pjax.js
@@ -29,6 +29,13 @@ $.fn.pjax = function( container, options ) {
else
options = $.isPlainObject(container) ? container : {container:container}
+ // We can't persist $objects using the history API so we must use
+ // a String selector. Bail if we got anything else.
+ if ( typeof options.container !== 'string' ) {
+ throw "pjax container must be a string selector!"
+ return false
+ }
+
return this.live('click', function(event){
// Middle click, cmd click, and ctrl click should open
// links in a new tab as normal.
@@ -56,7 +63,7 @@ $.fn.pjax = function( container, options ) {
//
// Accepts these extra keys:
//
-// container - Where to stick the response body.
+// container - Where to stick the response body. Must be a String.
// $(container).html(xhr.responseBody)
// push - Whether to pushState the URL. Defaults to true (of course).
// replace - Want to use replaceState instead? That's cool.
@@ -74,6 +81,11 @@ $.pjax = function( options ) {
// We don't want to let anyone override our success handler.
delete options.success
+ // We can't persist $objects using the history API so we must use
+ // a String selector. Bail if we got anything else.
+ if ( typeof options.container !== 'string' )
+ throw "pjax container must be a string selector!"
+
var defaults = {
timeout: 650,
push: true,
@@ -114,11 +126,6 @@ $.pjax = function( options ) {
timeout: options.timeout
}
- // We can't persist $objects using the history API so we need to store
- // the string selector.
- if ( $.isPlainObject(state.pjax) )
- state.pjax = state.pjax.selector
-
// If there are extra params, save the complete URL in the state object
var query = $.param(options.data)
if ( query != "_pjax=true" )
Please sign in to comment.
Something went wrong with that request. Please try again.