5tarl0rd
var iframeUtilsLogger = 'IframeUtils';
/**
* Import of Post Messages Utilities library, if it haven't been previously imported
*/
if (document.getElementById('postMessagesUtils') == null && window.staticSrcCommonsDir) {
const path = window.staticSrcCommonsDir + "/javascript/postMessagesUtils.js";
const scriptTag = '<script id="postMessagesUtils" type="text/javascript" src="'+path+'"></script>';
document.write(scriptTag);
}
/**
* Functions that resizes the iframe existent at the page
*/
function resizeIframeHeight(height) {
$("#iframeContainer").attr("height", height);
}
function resizeIframeWidth(width) {
$("#iframeContainer").attr("width", width);
}
/**
* Function to call a new GVO
*/
function openGvo(jsonPostMessage) {
openGvoId(jsonPostMessage.payload.gvoId);
}
/**
* Function to call a new GVO
*/
function openGvoId(gvoId) {
var href = window.location.href;
var parts = href.split('/trxm/');
var subparts = parts[1].split('/');
var host = parts[0];
var currentFlavor = subparts[0];
window.location = host + '/trxm/' + currentFlavor + '/goto.dialog.do?gvo=' + gvoId;
}
/**
* Receive the message, parse its data and dispatch to correct method
*/
function trxmPostMessageDispatcher(event) {
if (!validOriginUrl(window.iframeutils_validhost, event, iframeUtilsLogger)) return;
var jsonPostMessage = parseIncomingMsg(event.data, iframeUtilsLogger);
//************************** PLAIN TEXT MESSAGES AND OLD JSON MESSAGES- TO BE DEPRECATED! ******************************//
// Please use the analog JSON based-messages (see section below) instead of these ones,
// which are kept here just for backward compatibility but will be DEPRECATED SOON!
//*************************************************************************************************//
if(event.data.indexOf('resize:') == 0){
resizeIframeHeight(event.data.split(':')[1]);
return;
}
//maps to message with id='loadURL' in the new JSon format (see below)
if(event.data.indexOf('link:') == 0){
var args = event.data.split(':');
openWinFromIframe(args.splice(2).join(':'), args[1]);
return;
}
if (jsonPostMessage) {
if(jsonPostMessage.id == 'iFrameScrollup') {
var xpos = 0;
var ypos = 0;
if(jsonPostMessage.payload){
if (jsonPostMessage.payload.xpos) {
xpos = jsonPostMessage.payload.xpos;
}
if (jsonPostMessage.payload.ypos) {
ypos = jsonPostMessage.payload.ypos;
}
}
window.scrollTo(xpos, ypos);
consoleLog('"iFrameScrollup" received and processed.', iframeUtilsLogger);
}
}
//************ NEW ITEMS FOLLOWING THE STANDARD JSON CONVENTION - PLEASE USE THESE ONES! ***********//
//*************************************************************************************************//
if (jsonPostMessage) {
if (jsonPostMessage.id == 'resize') {
if (jsonPostMessage.payload.height) {
resizeIframeHeight(jsonPostMessage.payload.height);
}
if (jsonPostMessage.payload.width) {
resizeIframeWidth(jsonPostMessage.payload.width);
}
consoleLog('"resize" received and processed.', iframeUtilsLogger);
//equivalent to message 'link' in case of plane text
} else if(jsonPostMessage.id == 'loadURL') {
openWinFromIframe(jsonPostMessage.payload.url,jsonPostMessage.payload.target);
consoleLog('"loadURL" received and processed.', iframeUtilsLogger);
} else if(jsonPostMessage.id == 'scrollFrame') {
var xpos = 0;
var ypos = 0;
if(jsonPostMessage.payload){
if (jsonPostMessage.payload.xpos) {
xpos = jsonPostMessage.payload.xpos;
}
if (jsonPostMessage.payload.ypos) {
ypos = jsonPostMessage.payload.ypos;
}
}
window.scrollTo(xpos, ypos);
consoleLog('"scrollFrame" received and processed.', iframeUtilsLogger);
} else if(jsonPostMessage.id == 'openGvo') {
openGvo(jsonPostMessage);
consoleLog('"openGvo" received and processed.', iframeUtilsLogger);
}
}
}
if(window.addEventListener) {
window.addEventListener('message', trxmPostMessageDispatcher, false);
} else {
window.attachEvent('onmessage', trxmPostMessageDispatcher);
}
5tarL0rd By