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