Last active
December 5, 2017 16:54
-
-
Save paceaux/1eda5009858da10d38300af9f1086ec9 to your computer and use it in GitHub Desktop.
Tridion GoToPage Bookmarklet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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