Skip to content

Commit

Permalink
color palette selector added
Browse files Browse the repository at this point in the history
  • Loading branch information
msawired committed Mar 31, 2022
1 parent e44a75d commit 9fd0596
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions opc.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,30 @@ class OPC {
return true;
}

static palette(variableName, value, options) {
//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: 'palette',
value: value,
options: options
}
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);
Expand All @@ -88,6 +112,33 @@ class OPC {
return true;
}

static text(variableName, value, placeholder = null, maxChars = 1000) {
//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: 'text',
value: value,
placeholder: placeholder,
max: maxChars
}
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 Down

0 comments on commit 9fd0596

Please sign in to comment.