feat(dom): add getBaseHref method
This commit is contained in:
parent
4b62a722f0
commit
05219a54cd
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -292,4 +292,7 @@ export class DomAdapter {
|
|||
getLocation() {
|
||||
throw _abstract();
|
||||
}
|
||||
getBaseHref() {
|
||||
throw _abstract();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -297,4 +297,7 @@ class Html5LibDomAdapter implements DomAdapter {
|
|||
getLocation() {
|
||||
throw 'not implemented';
|
||||
}
|
||||
getBaseHref() {
|
||||
throw 'not implemented';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue