Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Tridion GoToPage Bookmarklet
(function(){
function getTCM(locationURL) {
return locationURL.replace('#id=','');
}
function getItem(tcm) {
return $models.getItem(tcm);
}
function getPath(fileName,itemInfo, fileExtension) {
let result;
const path = itemInfo.FilePath.replace('\\','/');
if (itemInfo.IsPublished ) {
result = `${path}/${fileName}.${fileExtension}`;
}
return result;
}
function getRoot(knownPath, shouldPrompt = false) {
let storedRoot = localStorage['gotopage-root'] && localStorage.getItem('gotopage-root');
let root;
if (!storedRoot || shouldPrompt) {
root = window.prompt(`Looks like the root part of the URL isn't stored. What comes in front of ${knownPath}?`);
localStorage.setItem('gotopage-root', root);
}
return storedRoot || root;
}
function getURL() {
let result;
const tcm = getTCM(window.location.hash);
const item = getItem(tcm);
const fileName = item.getFileName();
const pageTemplate = item.getPageTemplate();
const info = item.getInfo();
const path = getPath(fileName,info,pageTemplate.properties.staticFileExtension);
const root = getRoot(path);
if (root && path) {
result = `${root}${path}`;
}
return result;
}
getURL() && window.open(getURL());
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment