// test if a parameter value is designer table
let dgIframeId;
function dgIsParamTable(val){
return (val !== null && typeof(val)=='object' && val.hasOwnProperty('cols')
&& val.hasOwnProperty('rows'));
}
// interface to the dglux5 application
function onDGFrameMessage(e){
var data = e.data;
if (typeof(data)=='object'){
if (data.hasOwnProperty('dgIframeInit')){
dgIframeId = data['dgIframeInit'];
console.log(dgIframeId);
if (window.parent !== null){
// the first post back shouldn't contain any data change
window.parent.postMessage({'dgIframe':dgIframeId},'*');
}
} else if (data.hasOwnProperty('dgIframeUpdate')){
var updates = data['updates'];
if (typeof(updates)=='object'){
if (typeof(dgParams) == 'object'){
for (key in dgParams){
if (updates.hasOwnProperty(key)){
dgParams[key](updates[key]);
}}}
if (typeof(dgParamsUpdated) == 'function'){
dgParamsUpdated();
}}}}}
window.addEventListener('message',onDGFrameMessage);
// push parameter changes back to dglux
function dgUpdateParams(changes) {
if (dgIframeId !== null) {
window.parent.postMessage({'dgIframe':dgIframeId, changes:changes},'*');
} else {
throw 'dgUpdateParams failed, handshake not finished';
}
}