Skip to content

Commit

Permalink
color option added
Browse files Browse the repository at this point in the history
  • Loading branch information
msawired committed Mar 29, 2022
1 parent 2c74b56 commit e44a75d
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion opc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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({
Expand Down

0 comments on commit e44a75d

Please sign in to comment.