-
Jacek Lebioda authoredJacek Lebioda authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
---
---
function UrlExists(url, cb) {
jQuery.ajax({
url: url,
dataType: 'text',
type: 'GET',
cache: false,
complete: function(xhr){
if(typeof cb === 'function')
cb.apply(this, [xhr.status]);
}
});
}
function GetShortcutDestination() {
var s = window.location.href;
var pathArray = s.split('?');
// Cut the query if it exists
if (pathArray.length > 1) {
return pathArray[1];
} else {
return '';
}
}
function RedirectTo(newLocation) {
document.location.replace(newLocation);
}
// Pick the shortcut link destination from URL, like: `category:subcategory:card-name`
var sub = GetShortcutDestination();
// If there's a shortcut to handle
if (sub.length > 0) {
var externalCardURL = '/external/cards/' + sub;
var internalCardURL = '/internal/cards/' + sub;
UrlExists(externalCardURL, function(status){
if (status == 200) { // The sub-card is external and accessible
RedirectTo(externalCardURL);
} else {
UrlExists(internalCardURL, function(status){
if (status == 200) { // The sub-card is internal and accessible
RedirectTo(internalCardURL);
} else {
// No external, no internal - probably no access
RedirectTo('/404.html');
}
})
}
});
}