Skip to content

Universal nav integration updates #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 26 additions & 35 deletions views/partials/header.tpl
Original file line number Diff line number Diff line change
@@ -1,56 +1,47 @@
<div id="headerNav"></div>
{literal}
<script>
var UNI_NAV_PROD_URL = '//uni-nav.topcoder.com/v1/tc-universal-nav.js';
var UNI_NAV_DEV_URL = '//uni-nav.topcoder-dev.com/v1/tc-universal-nav.js';

var TOPCODER_DOMAIN = 'topcoder.com'
var isProdEnv = window.location.hostname && window.location.hostname.includes(TOPCODER_DOMAIN);
var scriptURL = isProdEnv ? UNI_NAV_PROD_URL : UNI_NAV_DEV_URL;

<script>
const signInUrl = '{$SignInUrl}';
const signUpUrl = '{$SignUpUrl}';
const signOutUrl = '{$SignOutUrl}';
{literal}
!function(n,t,e,a,c,i,o){n['TcUnivNavConfig']=c,n[c]=n[c]||function(){
(n[c].q=n[c].q??[]).push(arguments)},n[c].l=1*new Date();i=t.createElement(e),
o=t.getElementsByTagName(e)[0];i.async=1;i.type="module";i.src=a;o.parentNode.insertBefore(i,o)
}(window,document,"script",scriptURL,"tcUniNav");

var user;

if ('{/literal}{$User.SignedIn}{literal}') {
var photoUrl = '{/literal}{$User.Photo}{literal}' != null ? '{/literal}{$User.Photo}{literal}' : undefined;
var userId = null; // leaving it empty as it's currently not available
var handle = '{/literal}{$User.Name|escape:'html'}{literal}';
var initials = handle ? handle.substr(0, 2).toUpperCase() : '';

user = {
photoUrl,
userId,
initials,
handle
};
}

}(window,document,"script","{/literal}{$UniversalNavUrl}{literal}","tcUniNav");
{/literal}
{if $User.SignedIn}
const handle = '{$User.Name|escape:'html'}';
const initials = handle ? handle.substr(0, 2).toUpperCase() : '';
const userId = {$User.TopcoderUserID};
const photoURL = '{$User.TopcoderPhotoUrl}';
const user = {
photoURL: photoURL,
userId: userId,
initials: initials,
handle: handle,
};
{else}
const user = null;
{/if}
{literal}
tcUniNav('init', 'headerNav', {
type: 'tool',
toolName: 'Discussion',
user,
signIn() {
window.location.href = '/entry/signin?Source=forum';
window.location.replace(signInUrl);
},
signOut() {
var signOutUrl = '/entry/signout';
if (window.gdn && window.gdn.meta && window.gdn.meta.TransientKey) {
signOutUrl += '?TransientKey=' + window.gdn.meta.TransientKey;
}
window.location.href = signOutUrl;
window.location.replace(signOutUrl);
},
signUp() {
window.location.href = '/entry/register?Target=discussions';
window.location.replace(signUpUrl);
}
});

tcUniNav('init', 'footerNav', {
type: 'footer'
});

{/literal}
</script>
{/literal}