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
Methods
Properties
Attributes
Events
Methods
_getRoot
()
String
protected
Returns the current path root after popping off the last path segment, making it useful for resolving other URL paths against.
The path root will always begin and end with a '/'.
Returns:
_normalizePath
-
path
Returns a normalized path, ridding it of any '..' segments and properly handling leading and trailing slashes.
Parameters:
-
path
StringURL path to normalize.
Returns:
_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.
_resolvePath
-
path
Returns the normalized result of resolving the path
against the current
path. Falsy values for path
will return just the current path.
Parameters:
-
path
StringURL path to resolve.
Returns:
_resolveURL
-
url
Resolves the specified URL against the current URL.
This method resolves URLs like a browser does and will always return an absolute URL. When the specified URL is already absolute, it is assumed to be fully resolved and is simply returned as is. Scheme-relative URLs are prefixed with the current protocol. Relative URLs are giving the current URL's origin and are resolved and normalized against the current path root.
Parameters:
-
url
StringURL to resolve.
Returns:
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.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: