feat(dom): add getBaseHref method

This commit is contained in:
Brian Ford 2015-05-06 18:23:34 -07:00
parent 4b62a722f0
commit 05219a54cd
4 changed files with 24 additions and 0 deletions

View File

@ -318,4 +318,9 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
getLocation() {
return window.location;
}
getBaseHref() {
var uri = document.baseUri;
var baseUri = Uri.parse(uri);
return baseUri.path;
}
}

View File

@ -381,4 +381,17 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
getLocation() {
return window.location;
}
getBaseHref() {
return relativePath(document.baseURI);
}
}
// based on urlUtils.js in AngularJS 1
var urlParsingNode = null;
function relativePath(url) {
if (isBlank(urlParsingNode)) {
urlParsingNode = document.createElement("a");
}
urlParsingNode.setAttribute('href', url);
return (urlParsingNode.pathname.charAt(0) === '/') ? urlParsingNode.pathname : '/' + urlParsingNode.pathname;
}

View File

@ -292,4 +292,7 @@ export class DomAdapter {
getLocation() {
throw _abstract();
}
getBaseHref() {
throw _abstract();
}
}

View File

@ -297,4 +297,7 @@ class Html5LibDomAdapter implements DomAdapter {
getLocation() {
throw 'not implemented';
}
getBaseHref() {
throw 'not implemented';
}
}