Modify anchors to use dynamically-generated relative links

Because the gr-app.html payload may be served from a CDN,
relative links will be resolved based on the CDN host, not
the document at load time. Defer to having them resolve after
the html is loaded.

Change-Id: I8bf971776b2b308f8acd3bc3404b0853f853cd6f
This commit is contained in:
Andrew Bonventre
2016-05-15 17:00:49 -07:00
parent a0f308e3ed
commit 780c57ccf1
4 changed files with 13 additions and 5 deletions

View File

@@ -82,8 +82,8 @@ limitations under the License.
<div>[[account.email]]</div>
</div>
</li>
<li><a href="/switch-account">Switch account</a></li>
<li><a href="/logout">Sign out</a></li>
<li><a href$="[[_computeRelativeURL('/switch-account')]]">Switch account</a></li>
<li><a href$="[[_computeRelativeURL('/logout')]]">Sign out</a></li>
</ul>
</div>
</iron-dropdown>

View File

@@ -31,5 +31,9 @@
_showDropdownTapHandler: function(e) {
this.$.dropdown.open();
},
_computeRelativeURL: function(path) {
return '//' + window.location.host + path;
},
});
})();

View File

@@ -130,7 +130,7 @@ limitations under the License.
}
</style>
<nav>
<a href="/" class="bigTitle">PolyGerrit</a>
<a href$="[[_computeRelativeURL('/')]]" class="bigTitle">PolyGerrit</a>
<ul class="links">
<template is="dom-repeat" items="[[_links]]" as="linkGroup">
<li>
@@ -139,7 +139,7 @@ limitations under the License.
</span>
<ul>
<template is="dom-repeat" items="[[linkGroup.links]]" as="link">
<li><a href="[[link.url]]">[[link.name]]</a></li>
<li><a href$="[[link.url]]">[[link.name]]</a></li>
</template>
</ul>
</li>
@@ -148,7 +148,7 @@ limitations under the License.
<div class="rightItems">
<gr-search-bar value="{{searchQuery}}" role="search"></gr-search-bar>
<div class="accountContainer" id="accountContainer">
<a class="loginButton" href="/login" on-tap="_loginTapHandler">Sign in</a>
<a class="loginButton" href$="[[_computeRelativeURL('/login')]]" on-tap="_loginTapHandler">Sign in</a>
<gr-account-dropdown account="[[_account]]"></gr-account-dropdown>
</div>
</div>

View File

@@ -70,6 +70,10 @@
this._loadAccount();
},
_computeRelativeURL: function(path) {
return '//' + window.location.host + path;
},
_computeLinks: function(defaultLinks, userLinks) {
var links = defaultLinks.slice();
if (userLinks && userLinks.length > 0) {