From e44a75def5379003e1affce61941c37aa4f936e8 Mon Sep 17 00:00:00 2001 From: Sinan Ascioglu Date: Tue, 29 Mar 2022 15:53:33 +0100 Subject: [PATCH] color option added --- opc.js | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/opc.js b/opc.js index 5ac5d83..ce07104 100644 --- a/opc.js +++ b/opc.js @@ -40,6 +40,54 @@ class OPC { return true; } + static toggle(variableName, value = true) { + //check existing params + let url = new URL(document.location.href); + if (url && url.searchParams.has(variableName)) { + //if found, ignore requested value, replace with URL param + value = +url.searchParams.get(variableName) == 1 ? true: false; + } + + this.options[variableName] = { + name: variableName, + type: 'toggle', + value: value + } + 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 color(variableName, value = '#333') { + //check existing params + let url = new URL(document.location.href); + if (url && url.searchParams.has(variableName)) { + //if found, ignore requested value, replace with URL param + value = url.searchParams.get(variableName); + } + + this.options[variableName] = { + name: variableName, + type: 'color', + value: value + } + 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; if (typeof window.parameterChanged == 'function') { @@ -57,7 +105,7 @@ class OPC { } static callParentFunction = function (functionName, arg = {}) { - console.log(arg); + // console.log(arg); try { //try sending as is window.parent.postMessage({