From c7b784b1266ff3beb16c4ea938ecbed96a5f6546 Mon Sep 17 00:00:00 2001 From: Ovidiu Alexandru Toma Date: Wed, 10 Oct 2018 18:13:38 +0300 Subject: [PATCH] adds implementation --- assets/app.js | 40 +++++++++++++++++++++++++++------------- index.html | 5 +++-- template/color_test.html | 31 +++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 15 deletions(-) create mode 100644 template/color_test.html diff --git a/assets/app.js b/assets/app.js index e616068..7a597df 100644 --- a/assets/app.js +++ b/assets/app.js @@ -1,6 +1,6 @@ console.log("app.js loaded"); -var getTemplateHtml = template => { +var getTemplateHtml = (template, primary_color="#ffffff", secondary_color="#ffffff") => { document.getElementById('iframe').src = "about:blank"; fetch('template/'+template+'.html') .then(function(response) { @@ -9,28 +9,42 @@ var getTemplateHtml = template => { .then(function(html) { document.getElementById('iframe').contentWindow.document.write(html); // console.log(document.getElementById('iframe').contentWindow.document) + primary_elements = document.getElementById('iframe').contentWindow.document.getElementsByClassName("primary_color"); + applyColor(primary_elements, primary_color); - var elements = document.getElementById('iframe').contentWindow.document.querySelectorAll("body *"); - var numElements = elements.length; - var i; - for (i = 0; i < numElements; i++) { - elements[i].addEventListener("click", addColorTrigger); - } + secondary_elements = document.getElementById('iframe').contentWindow.document.getElementsByClassName("secondary_color"); + applyColor(secondary_elements, secondary_color); + document.getElementById("primary").value = primary_color + document.getElementById("secondary").value = secondary_color }); } +var changeColor = (el) => { + color = el.value + iframe_doc = document.getElementById('iframe').contentWindow.document + if(el.id == "primary") + { + divs = iframe_doc.getElementsByClassName("primary_color") + } + else + { + divs = iframe_doc.getElementsByClassName("secondary_color") + } + applyColor(divs, color); +} + +var applyColor = (elements, color) => { + var i; + for (i = 0; i < elements.length; i++) { + elements[i].style["background-color"] = color; + } +} var valueChange = value => { var iframehtml = document.getElementById('iframe').contentWindow.document.getElementById(value); val = document.getElementById(value).value; iframehtml.innerHTML = val } -var addColorTrigger = (e) => { - console.log("click"); - console.log(e.currentTarget); - -} - var downloadPage = () => { var pageContents = new XMLSerializer().serializeToString(document.getElementById('iframe').contentWindow.document) pageContents = pageContents.replace("rep_DEVNAME", document.getElementById("devname").value) diff --git a/index.html b/index.html index a29fedd..f15a489 100644 --- a/index.html +++ b/index.html @@ -20,12 +20,13 @@ +

Colours

- - + +

Values

diff --git a/template/color_test.html b/template/color_test.html new file mode 100644 index 0000000..27b3918 --- /dev/null +++ b/template/color_test.html @@ -0,0 +1,31 @@ + + + + + rep_SNAME + + + + + + + + + +
+

rep_SNAME will be back soon!

+
+

Sorry for the inconvenience but rep_URL is performing some maintenance at the moment. We’ll be back online shortly!

+

— rep_DEVNAME

+
+
+ + \ No newline at end of file