Skip to content

Instantly share code, notes, and snippets.

@bfosterscripps
Last active August 1, 2018 17:54
Show Gist options
  • Save bfosterscripps/c6169fe5e0beae118e6fd4fe3d19e459 to your computer and use it in GitHub Desktop.
Save bfosterscripps/c6169fe5e0beae118e6fd4fe3d19e459 to your computer and use it in GitHub Desktop.
Toggle between editing in Touch UI and preview mode on AEM author pages.
(function() {
var newUrl = '',
prevUrl = document.URL,
isWcmmodeDisabled = /wcmmode=disabled/.test(prevUrl);
if (/author\./.test(prevUrl)) {
if (/^.*?\/editor.html/.test(prevUrl)) {
newUrl = prevUrl.replace(/\/editor.html/, '');
if (!isWcmmodeDisabled) {
newUrl = newUrl + ((/\.html\?/.test(newUrl)) ? '&' : '?') + 'wcmmode=disabled';
}
} else {
newUrl = prevUrl.replace(/^(.*?\.[\w]+?)\//, '$1/editor.html/');
if (isWcmmodeDisabled) {
newUrl = newUrl.replace(/[?|&]{1}wcmmode=disabled/, '').replace(/\.html&/, '.html?');
}
}
}
window.location = newUrl;
})();
// Compressed bookmarklet:
// javascript:(function(){var a="",b=document.URL,c=/wcmmode=disabled/.test(b);/author\./.test(b)&&(/^.*?\/editor.html/.test(b)?(a=b.replace(/\/editor.html/,""),c||(a=a+(/\.html\?/.test(a)?"&":"?")+"wcmmode=disabled")):(a=b.replace(/^(.*?\.[\w]+?)\//,"$1/editor.html/"),c&&(a=a.replace(/[?|&]{1}wcmmode=disabled/,"").replace(/\.html&/,".html?")))),window.location=a})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment