pjax-base-debug.js revision dff8d056ecfb52c863b7ad28e8ecea3a3789ad92
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo CLASS_PJAX = Y.ClassNameManager.getClassName('pjax'),
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo var segments = (win && win.location.pathname.split('/')) || [];
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo// PjaxBase is a mixin for Controller.
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo // -- Properties -----------------------------------------------------------
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo _regexUrl: /^((?:([^:]+):(?:\/\/)?|\/\/)[^\/]*)?([^?#]*)(.*)$/i,
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo // -- Lifecycle Methods ----------------------------------------------------
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo this.publish(EVT_NAVIGATE, {defaultFn: this._defNavigateFn});
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo this._pjaxEvents && this._pjaxEvents.detach();
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo // -- Public Prototype Methods ---------------------------------------------
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo if (this.get('scrollToTop') && Y.config.win) {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo // Scroll to the top of the page. The timeout ensures that the
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo // scroll happens after navigation begins, so that the current
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo // scroll position will be restored if the user clicks the back
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo // -- Protected Prototype Methods ------------------------------------------
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo for (i = 0, len = parts.length; i < len; ++i) {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo } else if (part) {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo // Append a slash if necessary.
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo if (path.charAt(path.length - 1) === slash) {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo this._pjaxEvents = Y.one('body').delegate('click',
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo this._onLinkClick, this.get('linkSelector'), this);
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo // Path is host relative.
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo return this._normalizePath(root + '/' + path);
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo function resolve(match, prefix, scheme, path, suffix) {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo if (scheme && scheme.toLowerCase().indexOf('http') !== 0) {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo return (prefix || '') + self._resolvePath(path) + (suffix || '');
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo // Cache resolved URL.
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo resolvedUrl = resolved[url] = url.replace(self._regexUrl, resolve);
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo // -- Protected Event Handlers ---------------------------------------------
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo _onLinkClick: function (e) {
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo var url = this._resolveUrl(e.currentTarget.get('href'));
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo // Allow the native behavior on middle/right-click, or when Ctrl or
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo // Command are pressed.
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo if (e.button !== 1 || e.ctrlKey || e.metaKey) { return; }
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo // Do nothing if there's no matching route for this URL.
23c56a064638d10a6057e991c7dc113cc15c379aEric Ferraiuolo}, '@VERSION@' ,{requires:['classnamemanager', 'controller', 'node-event-delegate']});