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set="UTF-8" />
|
| 5 |
+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
+
<title>Document</title>
|
| 8 |
+
<style>
|
| 9 |
+
.modal {
|
| 10 |
+
display: block;
|
| 11 |
+
position: fixed;
|
| 12 |
+
z-index: 1;
|
| 13 |
+
left: 0;
|
| 14 |
+
top: 0;
|
| 15 |
+
width: 100%;
|
| 16 |
+
height: 100%;
|
| 17 |
+
overflow: auto;
|
| 18 |
+
background-color: rgb(0, 0, 0);
|
| 19 |
+
background-color: rgba(0, 0, 0, 0.4);
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
.modal-content {
|
| 23 |
+
background-color: #fefefe;
|
| 24 |
+
margin: 0% auto;
|
| 25 |
+
padding: 20px;
|
| 26 |
+
border: 1px solid #888;
|
| 27 |
+
width: 80%;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.close {
|
| 31 |
+
color: #aaa;
|
| 32 |
+
float: right;
|
| 33 |
+
font-size: 28px;
|
| 34 |
+
font-weight: bold;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.close:hover,
|
| 38 |
+
.close:focus {
|
| 39 |
+
color: black;
|
| 40 |
+
text-decoration: none;
|
| 41 |
+
cursor: pointer;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
.inputs {
|
| 45 |
+
display: flex;
|
| 46 |
+
flex-direction: column;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
.columns {
|
| 50 |
+
width: 100%;
|
| 51 |
+
display: flex;
|
| 52 |
+
gap: 40px;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
.columns > div:nth-child(2) {
|
| 56 |
+
width: 80%;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
textarea {
|
| 60 |
+
width: 100%;
|
| 61 |
+
height: 500px;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
input {
|
| 65 |
+
margin: 5px 0;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
label {
|
| 69 |
+
margin-right: 20px;
|
| 70 |
+
}
|
| 71 |
+
</style>
|
| 72 |
+
</head>
|
| 73 |
+
<body>
|
| 74 |
+
<div class="columns">
|
| 75 |
+
<div>
|
| 76 |
+
<button>Open Modal</button>
|
| 77 |
+
<div class="inputs">
|
| 78 |
+
<div>
|
| 79 |
+
<label>Height</label>
|
| 80 |
+
<input placeholder="height" class="height" />
|
| 81 |
+
</div>
|
| 82 |
+
<div>
|
| 83 |
+
<label>Width</label>
|
| 84 |
+
<input placeholder="width" class="width" />
|
| 85 |
+
</div>
|
| 86 |
+
</div>
|
| 87 |
+
</div>
|
| 88 |
+
<div>
|
| 89 |
+
<textarea
|
| 90 |
+
class="molecule"
|
| 91 |
+
placeholder="Insert a molecule here..."
|
| 92 |
+
></textarea>
|
| 93 |
+
</div>
|
| 94 |
+
</div>
|
| 95 |
+
<script defer>
|
| 96 |
+
const button = document.querySelector('button')
|
| 97 |
+
const textarea = document.querySelector('.molecule')
|
| 98 |
+
const width = document.querySelector('.width')
|
| 99 |
+
const height = document.querySelector('.height')
|
| 100 |
+
const modalContent = `
|
| 101 |
+
<div class="modal-content">
|
| 102 |
+
<span class="close">×</span>
|
| 103 |
+
<iframe
|
| 104 |
+
width="784"
|
| 105 |
+
height="624"
|
| 106 |
+
id="iframe"
|
| 107 |
+
src="env_url"
|
| 108 |
+
sandbox="allow-scripts allow-same-origin"
|
| 109 |
+
></iframe>
|
| 110 |
+
</div>
|
| 111 |
+
`
|
| 112 |
+
let modal
|
| 113 |
+
let closeIcon;
|
| 114 |
+
let iframe;
|
| 115 |
+
|
| 116 |
+
function closeModal() {
|
| 117 |
+
closeIcon.removeEventListener('click', closeModal)
|
| 118 |
+
modal.remove()
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
function createModal() {
|
| 122 |
+
modal = document.createElement('div')
|
| 123 |
+
modal.classList.add('modal')
|
| 124 |
+
modal.innerHTML = modalContent
|
| 125 |
+
document.body.appendChild(modal)
|
| 126 |
+
|
| 127 |
+
closeIcon = document.querySelector('.close')
|
| 128 |
+
iframe = document.getElementById('iframe')
|
| 129 |
+
iframe.style.height = height.value + 'px'
|
| 130 |
+
iframe.style.width = width.value + 'px'
|
| 131 |
+
|
| 132 |
+
closeIcon.addEventListener('click', closeModal)
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
button.onclick = createModal
|
| 136 |
+
window.onclick = function (event) {
|
| 137 |
+
if (event.target == modal) {
|
| 138 |
+
closeModal()
|
| 139 |
+
}
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
window.addEventListener('message', (event) => {
|
| 143 |
+
if (event.data.eventType === 'init') {
|
| 144 |
+
iframe.contentWindow.ketcher.setMolecule(textarea.value)
|
| 145 |
+
}
|
| 146 |
+
})
|
| 147 |
+
</script>
|
| 148 |
+
</body>
|
| 149 |
+
</html>
|