|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | + |
| 4 | +<head> |
| 5 | + <meta charset="UTF-8"> |
| 6 | + <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> |
| 7 | + <meta name="apple-mobile-web-app-capable" content="yes"> |
| 8 | + <meta name="mobile-web-app-capable" content="yes"> |
| 9 | + <meta name="HandheldFriendly" content="true"/> |
| 10 | + |
| 11 | + <title>Interact with your app</title> |
| 12 | + |
| 13 | + <link rel="stylesheet" href="../examples.css"> |
| 14 | + <style> |
| 15 | + * { |
| 16 | + font-family: "Source Sans Pro",sans-serif; |
| 17 | + } |
| 18 | + nav { |
| 19 | + height: 60px; |
| 20 | + display: flex; |
| 21 | + justify-content: space-between; |
| 22 | + } |
| 23 | + |
| 24 | + nav span { |
| 25 | + display: flex; |
| 26 | + width: 100%; |
| 27 | + } |
| 28 | + |
| 29 | + input { |
| 30 | + width: 100%; |
| 31 | + } |
| 32 | + |
| 33 | + myscript-text-web { |
| 34 | + height: calc(100% - 60px); |
| 35 | + } |
| 36 | + |
| 37 | + #question { |
| 38 | + font-size: 2em; |
| 39 | + background-color: #f5f5f5; |
| 40 | + margin: 0; |
| 41 | + padding: 10px 0 10px; |
| 42 | + border-bottom: 1px solid #D7DDE3; |
| 43 | + text-align: center; |
| 44 | + } |
| 45 | + #result { |
| 46 | + height: 100px; |
| 47 | + display: flex; |
| 48 | + justify-content: center; |
| 49 | + align-items: center; |
| 50 | + overflow: auto; |
| 51 | + } |
| 52 | + |
| 53 | + #result span { |
| 54 | + font-size: xx-large; |
| 55 | + } |
| 56 | + #nextOne { |
| 57 | + text-align: center; |
| 58 | + height: 60px; |
| 59 | + } |
| 60 | + |
| 61 | + #nextOne .btn { |
| 62 | + line-height: 30px; |
| 63 | + background-color: rgba(0,0,0,.08); |
| 64 | + display: inline-block; |
| 65 | + font-weight: 700; |
| 66 | + font-size: 24px; |
| 67 | + text-align: center; |
| 68 | + white-space: nowrap; |
| 69 | + color: #1a9fff; |
| 70 | + text-decoration: none; |
| 71 | + border: 2px solid transparent; |
| 72 | + border-radius: 3px; |
| 73 | + -ms-touch-action: manipulation; |
| 74 | + touch-action: manipulation; |
| 75 | + cursor: pointer; |
| 76 | + transition: all 125ms; |
| 77 | + padding: 4px 2px 4px 2px; |
| 78 | + } |
| 79 | + |
| 80 | + #nextOne .icn { |
| 81 | + margin: 0 0px -2px 12px; |
| 82 | + } |
| 83 | + </style> |
| 84 | + |
| 85 | + <!-- As web components are not fully support --> |
| 86 | + <script src="../../../webcomponentsjs/webcomponents-loader.js"></script> |
| 87 | + <!-- myscript-common-element is import to be used later --> |
| 88 | + <link rel="import" href="../../myscript-text-web.html"> |
| 89 | +</head> |
| 90 | + |
| 91 | +<body> |
| 92 | +<svg style="display: none;"> |
| 93 | + <symbol id="icn-play" viewBox="0 0 16 16"> |
| 94 | + <path |
| 95 | + d="M13.153 8.589c.606-.325.603-.854 0-1.178L4.873 2.97C4.392 2.709 4 2.945 4 3.496v9.008c0 .55.39.787.874.527l8.28-4.442z" |
| 96 | + fill="currentColor" fill-rule="evenodd"></path> |
| 97 | + </symbol> |
| 98 | +</svg> |
| 99 | +<p id="question"></p> |
| 100 | +<div id="result"></div> |
| 101 | +<div id="nextOne"></div> |
| 102 | + <myscript-text-web scheme="https" |
| 103 | + host="webdemoapi.myscript.com" |
| 104 | + applicationkey="515131ab-35fa-411c-bb4d-3917e00faf60" |
| 105 | + hmackey="54b2ca8a-6752-469d-87dd-553bb450e9ad" |
| 106 | + disableexportpanel="true"> |
| 107 | + </myscript-text-web> |
| 108 | +<script> |
| 109 | + var editorElement = document.querySelector('myscript-text-web'); |
| 110 | + var questionElement = document.getElementById('question'); |
| 111 | + var resultElement = document.getElementById('result'); |
| 112 | + var nextElement = document.getElementById('nextOne'); |
| 113 | + |
| 114 | + const countries = ['France', 'Italy', 'Spain', 'Argentina', 'Japan']; |
| 115 | + const capitals = ['Paris', 'Rome', 'Madrid', 'Buenos Aires', 'Tokyo']; |
| 116 | + |
| 117 | + var randomNumber = Math.floor(Math.random() * countries.length); |
| 118 | + |
| 119 | + questionElement.innerText = 'What is the capital of ' + countries[randomNumber] + '?'; |
| 120 | + |
| 121 | + editorElement.addEventListener('exported', function (evt) { |
| 122 | + var exports = evt.detail.exports; |
| 123 | + if (exports && exports['text/plain']) { |
| 124 | + exportedIsAnswer(exports); |
| 125 | + } else { |
| 126 | + resultElement.innerHTML = ''; |
| 127 | + } |
| 128 | + }); |
| 129 | + |
| 130 | + nextElement.addEventListener('click', function () { |
| 131 | + changeQuestion(); |
| 132 | + }); |
| 133 | + |
| 134 | + function exportedIsAnswer(exports) { |
| 135 | + if (exports['text/plain'] === capitals[randomNumber]) { |
| 136 | + resultElement.innerHTML = '<span> Yes, it is ' + exports['text/plain'] + '.</span>'; |
| 137 | + resultElement.style.cssText = "color: green;"; |
| 138 | + nextElement.innerHTML = '<a class="btn">Next question<svg class="icn"><use xmlns:xlink="http://www.w3.org/1999/xlink" href="#icn-play"></use></svg></a>'; |
| 139 | + } else { |
| 140 | + resultElement.innerHTML = '<span> No, it is not ' + exports['text/plain'] + '.</span>'; |
| 141 | + resultElement.style.cssText = "color: red;"; |
| 142 | + nextElement.innerHTML = ''; |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + function changeQuestion() { |
| 147 | + countries.splice(randomNumber, 1); |
| 148 | + capitals.splice(randomNumber, 1); |
| 149 | + randomNumber = Math.floor(Math.random() * countries.length); |
| 150 | + questionElement.innerHTML = countries[randomNumber] ? 'What is the capital of ' + countries[randomNumber] + ' ?' : 'You won !'; |
| 151 | + nextElement.innerHTML = ''; |
| 152 | + editorElement.editor.clear(); |
| 153 | + } |
| 154 | + |
| 155 | + window.addEventListener('resize', function () { |
| 156 | + editorElement.editor.resize(); |
| 157 | + }); |
| 158 | +</script> |
| 159 | +</body> |
| 160 | + |
| 161 | +</html> |
0 commit comments