From 2944d3f28de8851799dd8ab90aba0345f2d88d69 Mon Sep 17 00:00:00 2001 From: Sinan Ascioglu Date: Wed, 4 Aug 2021 12:16:52 -0400 Subject: [PATCH] OPC is added --- OPC.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 OPC.js diff --git a/OPC.js b/OPC.js new file mode 100644 index 0000000..6e4d8e0 --- /dev/null +++ b/OPC.js @@ -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); + + } + } + +} \ No newline at end of file