PjaxBase Class
Y.Router
extension that provides the core plumbing for enhanced navigation
implemented using the pjax technique (HTML5 pushState
+ Ajax).
This makes it easy to enhance the navigation between the URLs of an application in HTML5 history capable browsers by delegating to the router to fulfill the "request" and seamlessly falling-back to using standard full-page reloads in older, less-capable browsers.
The PjaxBase
class isn't useful on its own, but can be mixed into a
Router
-based class to add Pjax functionality to that Router. For a pre-made
standalone Pjax router, see the Pjax
class.
var MyRouter = Y.Base.create('myRouter', Y.Router, [Y.PjaxBase], {
// ...
});
Item Index
Properties
Attributes
Events
Methods
_isLinkSameOrigin
-
link
Utility method to test whether a specified link/anchor node's href
is of
the same origin as the page's current location.
This normalize browser inconsistencies with how the port
is reported for
anchor elements (IE reports a value for the default port, e.g. "80").
Parameters:
-
link
NodeThe anchor element to test whether its
href
is of the same origin as the page's current location.
Returns:
href
is of the same origin as
the page's current location.
_onLinkClick
-
e
Handler for delegated link-click events which match the linkSelector
.
This will attempt to enhance the navigation to the link element's href
by
passing the URL to the _navigate()
method. When the navigation is being
enhanced, the default action is prevented.
If the user clicks a link with the middle/right mouse buttons, or is holding down the Ctrl or Command keys, this method's behavior is not applied and allows the native behavior to occur. Similarly, if the router is not capable or handling the URL because no route-handlers match, the link click will behave natively.
Parameters:
_pjaxBindUI
()
protected
Binds the delegation of link-click events that match the linkSelector
to
the _onLinkClick()
handler.
By default this method will only be called if the browser is capable of using HTML5 history.
Properties
_regexURL
RegExp
protected
Regex used to break up a URL string around the URL's path.
Subpattern captures:
- Origin, everything before the URL's path-part.
- The URL's path-part.
- Suffix, everything after the URL's path-part.
Attributes
linkSelector
String | Function
CSS selector string used to filter link click events so that only the links which match it will have the enhanced navigation behavior of Pjax applied.
When a link is clicked and that link matches this selector, Pjax will
attempt to dispatch to any route handlers matching the link's href
URL. If
HTML5 history is not supported or if no route handlers match, the link click
will be handled by the browser just like any old link.
Default: "a.yui3-pjax"
Fires event linkSelectorChange
Fires when the value for the configuration attribute linkSelector
is
changed. You can listen for the event using the on
method if you
wish to be notified before the attribute's value has changed, or
using the after
method if you wish to be notified after the
attribute's value has changed.
Parameters:
-
e
EventFacadeAn Event Facade object with the following attribute-specific properties added:
scrollToTop
Boolean
Whether the page should be scrolled to the top after navigating to a URL.
When the user clicks the browser's back button, the previous scroll position will be maintained.
Default: true
Fires event scrollToTopChange
Fires when the value for the configuration attribute scrollToTop
is
changed. You can listen for the event using the on
method if you
wish to be notified before the attribute's value has changed, or
using the after
method if you wish to be notified after the
attribute's value has changed.
Parameters:
-
e
EventFacadeAn Event Facade object with the following attribute-specific properties added: