pjax-debug.js revision d5718409d7c1c4cbbd2be4605305c045a68a9136
/**
Provides seamless, gracefully degrading Pjax (pushState + Ajax) functionality,
which makes it easy to progressively enhance standard links on the page so that
they can be loaded normally in old browsers, or via Ajax (with HTML5 history
support) in newer browsers.
@module pjax
@main
@since 3.5.0
**/
/**
Provides seamless, gracefully degrading Pjax (pushState + Ajax) functionality,
which makes it easy to progressively enhance standard links on the page so that
they can be loaded normally in old browsers, or via Ajax (with HTML5 history
support) in newer browsers.
@class Pjax
@extends Router
@uses PjaxBase
@constructor
@param {Object} [config] Config attributes.
@since 3.5.0
**/
/**
Fired when an error occurs while attempting to load a URL via Ajax.
@event error
@param {String} content Content extracted from the response using the
`contentSelector`, if any.
@param {String} responseText Raw Ajax response text.
@param {Number} status HTTP status code for the Ajax response.
**/
var EVT_ERROR = 'error',
/**
Fired when a URL is successfully loaded via Ajax.
@event load
@param {String} content Content extracted from the response using the
`contentSelector`, if any.
@param {String} responseText Raw Ajax response text.
@param {Number} status HTTP status code for the Ajax response.
**/
EVT_LOAD = 'load';
// -- Lifecycle Methods ----------------------------------------------------
initializer: function () {
},
// -- Public Methods -------------------------------------------------------
/**
Extracts and returns the relevant HTML content from an Ajax response. The
content is extracted using the `contentSelector` attribute as a CSS
selector. If `contentSelector` is `null`, the entire response will be
returned.
The return value is an object containing two properties:
- **node**: A `Y.Node` instance for a document fragment containing the
extracted HTML content.
- **title**: The title of the HTML page, if any, extracted using the
`titleSelector` attribute (which defaults to looking for a `<title>`
element). If `titleSelector` is not set or if a title could not be
found, this property will be `undefined`.
@method getContent
@param {String} responseText Raw Ajax response text.
@return {Object} Content object with the properties described above.
**/
getContent: function (responseText) {
var content = {},
if (contentSelector) {
} else {
}
if (titleSelector) {
if (titleNode) {
}
}
return content;
},
// -- Private Methods ------------------------------------------------------
/**
Default Pjax route handler. Makes an Ajax request for the requested URL.
@method _defaultRoute
@param {Object} req Request object.
@protected
**/
_defaultRoute: function (req) {
// If there's an outstanding request, abort it.
// Send a request.
context: this,
on: {
end : this._onPjaxIOEnd,
failure: this._onPjaxIOFailure,
success: this._onPjaxIOSuccess
}
});
},
// -- Event Handlers -------------------------------------------------------
/**
Default event handler for both the `error` and `load` events. Attempts to
insert the loaded content into the `container` node and update the page's
title.
@method _defCompleteFn
@param {EventFacade} e
@protected
**/
_defCompleteFn: function (e) {
}
}
},
/**
Handles IO end events.
@method _onPjaxIOEnd
@protected
**/
_onPjaxIOEnd: function () {
this._request = null;
},
/**
Handles IO failure events and fires our own `error` event.
@method _onPjaxIOFailure
@protected
**/
});
},
/**
Handles IO success events and fires our own 'load' event.
@method _onPjaxIOSuccess
@protected
**/
});
}
}, {
ATTRS: {
/**
Node into which content should be inserted when a page is loaded via
Pjax. This node's existing contents will be removed to make way for the
new content.
If not set, loaded content will not be automatically inserted into the
page.
@attribute container
@type Node
@default null
**/
container: {
value: null,
}
},
/**
CSS selector used to extract a specific portion of the content of a page
loaded via Pjax.
For example, if you wanted to load the page `example.html` but only use
the content within an element with the id "pjax-content", you'd set
`contentSelector` to "#pjax-content".
If not set, the entire page will be used.
@attribute contentSelector
@type String
@default null
**/
value: null
},
// Inherited from Router and already documented there.
routes: {
value: [
]
},
/**
CSS selector used to extract a page title from the content of a page
loaded via Pjax.
By default this is set to extract the title from the `<title>` element,
but you could customize it to extract the title from an `<h1>`, or from
any other element, if that's more appropriate for the content you're
loading.
@attribute titleSelector
@type String
@default "title"
**/
value: 'title'
},
/**
Time in milliseconds after which an Ajax request should time out. When a
timeout occurs, the `error` event will be fired.
@attribute timeout
@type Number
@default 30000
**/
timeout: {
value: 30000
}
}
});