From 9fd0596fd2f270412dfa420e0d6418bd07943ba4 Mon Sep 17 00:00:00 2001 From: Sinan Ascioglu Date: Thu, 31 Mar 2022 14:55:32 +0100 Subject: [PATCH] color palette selector added --- opc.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/opc.js b/opc.js index ce07104..b343b82 100644 --- a/opc.js +++ b/opc.js @@ -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); @@ -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') {