Skip to content

Commit

Permalink
Merge branch 'pjax-root'
Browse files Browse the repository at this point in the history
  • Loading branch information
ericf committed Nov 14, 2011
2 parents 501bb93 + 83f398b commit 15518e1
Show file tree
Hide file tree
Showing 15 changed files with 258 additions and 71 deletions.
38 changes: 20 additions & 18 deletions build/pjax-base/pjax-base-debug.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
YUI.add('pjax-base', function(Y) {

var win = Y.config.win,
originalRoot = getRoot(),
var win = Y.config.win,

CLASS_PJAX = Y.ClassNameManager.getClassName('pjax'),
EVT_NAVIGATE = 'navigate';

function getRoot() {
var segments = (win && win.location.pathname.split('/')) || [];
segments.pop();
return segments.join('/');
}

// PjaxBase is a mixin for Router.
function PjaxBase() {}

Expand All @@ -22,9 +15,11 @@ PjaxBase.prototype = {

// -- Lifecycle Methods ----------------------------------------------------
initializer: function () {
this._pjaxRoot = originalRoot;
this.publish(EVT_NAVIGATE, {defaultFn: this._defNavigateFn});
this._pjaxBindUI();

if (this.get('html5')) {
this._pjaxBindUI();
}
},

destructor: function () {
Expand All @@ -40,7 +35,11 @@ PjaxBase.prototype = {
},

// -- Protected Prototype Methods ------------------------------------------
_getRoot: getRoot,
_getRoot: function () {
var segments = (win && win.location.pathname.split('/')) || [];
segments.pop();
return segments.join('/');
},

_normalizePath: function (path) {
var dots = '..',
Expand Down Expand Up @@ -75,14 +74,14 @@ PjaxBase.prototype = {
},

_pjaxBindUI: function () {
if (this.get('html5')) {
if (!this._pjaxEvents) {
this._pjaxEvents = Y.one('body').delegate('click',
this._onLinkClick, this.get('linkSelector'), this);
}
},

_resolvePath: function (path) {
var root = this._pjaxRoot;
_resolvePath: function (path, root) {
root || (root = this._getRoot());

if (!path) {
return root;
Expand All @@ -97,9 +96,12 @@ PjaxBase.prototype = {
},

_resolveUrl: function (url) {
var self = this,
resolved = self._resolved,
resolvedUrl = resolved[url];
var self = this,
root = self._getRoot(),
resolved, resolvedUrl;

resolved = self._resolved[root] || (self._resolved[root] = {});
resolvedUrl = resolved[url];

if (resolvedUrl) {
return resolvedUrl;
Expand All @@ -110,7 +112,7 @@ PjaxBase.prototype = {
return match;
}

return (prefix || '') + self._resolvePath(path) + (suffix || '');
return (prefix || '') + self._resolvePath(path, root) + (suffix || '');
}

// Cache resolved URL.
Expand Down
2 changes: 1 addition & 1 deletion build/pjax-base/pjax-base-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 20 additions & 18 deletions build/pjax-base/pjax-base.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
YUI.add('pjax-base', function(Y) {

var win = Y.config.win,
originalRoot = getRoot(),
var win = Y.config.win,

CLASS_PJAX = Y.ClassNameManager.getClassName('pjax'),
EVT_NAVIGATE = 'navigate';

function getRoot() {
var segments = (win && win.location.pathname.split('/')) || [];
segments.pop();
return segments.join('/');
}

// PjaxBase is a mixin for Router.
function PjaxBase() {}

Expand All @@ -22,9 +15,11 @@ PjaxBase.prototype = {

// -- Lifecycle Methods ----------------------------------------------------
initializer: function () {
this._pjaxRoot = originalRoot;
this.publish(EVT_NAVIGATE, {defaultFn: this._defNavigateFn});
this._pjaxBindUI();

if (this.get('html5')) {
this._pjaxBindUI();
}
},

destructor: function () {
Expand All @@ -40,7 +35,11 @@ PjaxBase.prototype = {
},

// -- Protected Prototype Methods ------------------------------------------
_getRoot: getRoot,
_getRoot: function () {
var segments = (win && win.location.pathname.split('/')) || [];
segments.pop();
return segments.join('/');
},

_normalizePath: function (path) {
var dots = '..',
Expand Down Expand Up @@ -75,14 +74,14 @@ PjaxBase.prototype = {
},

_pjaxBindUI: function () {
if (this.get('html5')) {
if (!this._pjaxEvents) {
this._pjaxEvents = Y.one('body').delegate('click',
this._onLinkClick, this.get('linkSelector'), this);
}
},

_resolvePath: function (path) {
var root = this._pjaxRoot;
_resolvePath: function (path, root) {
root || (root = this._getRoot());

if (!path) {
return root;
Expand All @@ -97,9 +96,12 @@ PjaxBase.prototype = {
},

_resolveUrl: function (url) {
var self = this,
resolved = self._resolved,
resolvedUrl = resolved[url];
var self = this,
root = self._getRoot(),
resolved, resolvedUrl;

resolved = self._resolved[root] || (self._resolved[root] = {});
resolvedUrl = resolved[url];

if (resolvedUrl) {
return resolvedUrl;
Expand All @@ -110,7 +112,7 @@ PjaxBase.prototype = {
return match;
}

return (prefix || '') + self._resolvePath(path) + (suffix || '');
return (prefix || '') + self._resolvePath(path, root) + (suffix || '');
}

// Cache resolved URL.
Expand Down
8 changes: 3 additions & 5 deletions build/router/router-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -821,10 +821,8 @@ Y.Router = Y.extend(Router, Y.Base, {
url: urlIsString ? this._joinURL(url) : url
});
} else {
if (urlIsString && url.charAt(0) !== '/') {
url = '/' + url;
}

// Remove the root from the URL before it's set as the hash.
urlIsString && (url = this.removeRoot(url));
HistoryHash[replace ? 'replaceHash' : 'setHash'](url);
}

Expand Down Expand Up @@ -969,4 +967,4 @@ version of YUI.
Y.Controller = Y.Router;


}, '@VERSION@' ,{requires:['array-extras', 'base-build', 'history'], optional:['querystring-parse']});
}, '@VERSION@' ,{optional:['querystring-parse'], requires:['array-extras', 'base-build', 'history']});
2 changes: 1 addition & 1 deletion build/router/router-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions build/router/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -819,10 +819,8 @@ Y.Router = Y.extend(Router, Y.Base, {
url: urlIsString ? this._joinURL(url) : url
});
} else {
if (urlIsString && url.charAt(0) !== '/') {
url = '/' + url;
}

// Remove the root from the URL before it's set as the hash.
urlIsString && (url = this.removeRoot(url));
HistoryHash[replace ? 'replaceHash' : 'setHash'](url);
}

Expand Down Expand Up @@ -967,4 +965,4 @@ version of YUI.
Y.Controller = Y.Router;


}, '@VERSION@' ,{requires:['array-extras', 'base-build', 'history'], optional:['querystring-parse']});
}, '@VERSION@' ,{optional:['querystring-parse'], requires:['array-extras', 'base-build', 'history']});
Loading

0 comments on commit 15518e1

Please sign in to comment.