|
| 1 | +const wdrLoader = require("wdr-loader"); |
| 2 | + |
| 3 | +wdrLoader(data=> { |
| 4 | + render(data); |
| 5 | +}) |
| 6 | + |
| 7 | +function render(data) { |
| 8 | + document.title = 'WDR example'; |
| 9 | + loadScript("/dist/evaluatly.js", () => Evaluatly.loadVar(template(data))); |
| 10 | +} |
| 11 | + |
| 12 | +function template(data) { |
| 13 | + |
| 14 | + return ( |
| 15 | + { |
| 16 | + "hash": "example/wdr", |
| 17 | + "story": { |
| 18 | + "env": { |
| 19 | + "back_label": "Back" |
| 20 | + }, |
| 21 | + "pages": [ |
| 22 | + { |
| 23 | + "items": [ |
| 24 | + { "type": "question", "value": data.title}, |
| 25 | + { "type": "radio", "save_key": "fruit", "required": true, |
| 26 | + "options": data.options.map(item => ({ "label": item })) |
| 27 | + } |
| 28 | + ], |
| 29 | + "submit" : { "label": "Next", "program": {"next_page": true} } |
| 30 | + }, |
| 31 | + { |
| 32 | + "items": [ |
| 33 | + { "type": "title", "value": "{{fruit.label}} is awesome!" } |
| 34 | + ] |
| 35 | + } |
| 36 | + ] |
| 37 | + }, |
| 38 | + "theme": { |
| 39 | + "page": { |
| 40 | + "font-family": "google:Lato", |
| 41 | + "font-size": "20px", |
| 42 | + "color": "#4b3f32", |
| 43 | + "background-color": "#f5f1ed" |
| 44 | + }, |
| 45 | + "content": { |
| 46 | + "align-items": "center", |
| 47 | + "text-align": "center", |
| 48 | + "justify-content": "center" |
| 49 | + }, |
| 50 | + "title": { |
| 51 | + "color" : "#000000" |
| 52 | + }, |
| 53 | + "subtitle": { |
| 54 | + "color" : "#000000" |
| 55 | + }, |
| 56 | + "question": { |
| 57 | + "color" : "#000000" |
| 58 | + }, |
| 59 | + "button": { |
| 60 | + "background-color": "#f1574b", |
| 61 | + "color": "#ffffff", |
| 62 | + "border-radius" : "100px", |
| 63 | + "border-width" : "3px" |
| 64 | + }, |
| 65 | + "button:hover": { |
| 66 | + "background-color": "#ffffff", |
| 67 | + "color": "#f1574b" |
| 68 | + }, |
| 69 | + "link": { |
| 70 | + "color": "#f1574b" |
| 71 | + }, |
| 72 | + "form_submit.inputs": { |
| 73 | + "background-color": "#fff" |
| 74 | + }, |
| 75 | + "form_submit .input": { |
| 76 | + "color": "#000" |
| 77 | + }, |
| 78 | + "form .option:hover": { |
| 79 | + "color": "#3e306e" |
| 80 | + }, |
| 81 | + "form_submit .option:hover": { |
| 82 | + "color": "#3e306e" |
| 83 | + } |
| 84 | + } |
| 85 | + }); |
| 86 | + |
| 87 | +} |
| 88 | + |
| 89 | +function loadScript(url, onload) { |
| 90 | + const script = document.createElement('script'); |
| 91 | + script.type = 'text/javascript'; |
| 92 | + script.async = true; |
| 93 | + document.head.appendChild(script); |
| 94 | + script.onload = onload; |
| 95 | + script.src = url; |
| 96 | +} |
0 commit comments