Skip to content

Commit

Permalink
OPC is added
Browse files Browse the repository at this point in the history
  • Loading branch information
msawired committed Aug 4, 2021
1 parent d165f82 commit 2944d3f
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions OPC.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
class OPC {
static options = {};
static variables = [];
constructor(container = null) {
this.container = container;
this.options = {};
this.variables = [];
}

static slider(variableName, value, min = 0, max = null, step = null){
max = max == null? value*2: max;
step = step == null? value/10: step;

this.options[variableName] = {
name: variableName,
type: 'slider',
value: value,
min: min,
max: max,
step: step
}
this.callParentFunction('OPC', this.options[variableName] );
//delete existing
Object.defineProperty(window, variableName, {
get: function () {
return OPC.options[variableName].value;
}
});
this.callParentFunction('OPC', this.options[variableName]);
return true;
}

static set = function (variableName, value){
OPC.options[variableName].value = value;
}

static callParentFunction = function (functionName, arg = {}) {
//this.console.log(arg);
// below might fail if arg can not be cloned to be sent over.
// console.profile('callParentFunction');
try {
//try sending as is
window.parent.postMessage({
'messageType': functionName,
'message': window.OP_makeTransmittable(arg, 0)
}, '*');
} catch (error) {
console.log('postMessage', error);

}
}

}

0 comments on commit 2944d3f

Please sign in to comment.