-
Notifications
You must be signed in to change notification settings - Fork 17
/
summary-iframe-implementation-sample.html
247 lines (226 loc) · 7.61 KB
/
summary-iframe-implementation-sample.html
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<!--
This file is published via GitHub Pages at the URL: https://orcid.github.io/orcid-angular.
To make it publicly accessible, it must be included in the `gh-pages` branch of the repository.
If you need to update this file ensure the changes are correctly committed
and pushed to the `gh-pages` branch.
For more information about GitHub Pages and the `gh-pages` branch, visit:
https://docs.github.com/en/pages/getting-started-with-github-pages/about-github-pages
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ORCID Summary iFrame Display Tester</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: rgba(0, 0, 0, 0.1);
}
.controls {
margin-bottom: 20px;
}
label {
font-weight: bold;
margin-right: 10px;
}
select,
input,
button {
margin: 5px;
padding: 5px 10px;
}
.dialog-box {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
display: none;
overflow: hidden;
}
.dialog-box iframe {
width: 100%;
height: 100%;
border: none;
}
.close-button {
position: absolute;
top: 10px;
right: 10px;
background: #ff5e5e;
border: none;
border-radius: 50%;
width: 25px;
height: 25px;
cursor: pointer;
font-size: 16px;
color: white;
display: flex;
justify-content: center;
align-items: center;
}
.close-button:hover {
background: #ff3d3d;
}
.header {
text-align: center;
margin-bottom: 30px;
}
h1 {
margin: 0;
font-size: 2em;
}
p {
margin: 10px 0 0;
font-size: 1.2em;
color: #555;
}
</style>
</head>
<body>
<div class="header">
<h1>ORCID Summary iFrame Display Tester</h1>
<p>
This tool allows you to display ORCID IDs within iframes of various
sizes. Test how the content adapts to different iframe dimensions.
</p>
</div>
<!-- Controls to set URL -->
<div class="controls">
<label for="iframe-url">Previously Open URLs:</label>
<select id="iframe-url" onchange="selectUrl()">
<option value="">-- Select a URL --</option>
</select>
<input type="text" id="new-url" placeholder="Enter ORCID URL" size="50" />
</div>
<!-- Buttons to open dialogs -->
<div class="controls">
<button onclick="openDialog(400, 600)">Open Dialog (400x600)</button>
<button onclick="openDialog(840, 500)">Open Dialog (840x500)</button>
<button onclick="openDialog(840, 700)">Open Dialog (840x700)</button>
<button onclick="openDialog(1200, 1200)">Open Dialog (1200x1200)</button>
</div>
<!-- Single Dialog Box -->
<div class="dialog-box" id="dialog-box">
<button class="close-button" onclick="closeDialog()">×</button>
<iframe id="dialog-iframe" src=""></iframe>
</div>
<script>
// Default URLs
const defaultUrls = [
'https://orcid.org/0000-0001-9389-7387/summary',
'https://sandbox.orcid.org/0000-0003-3363-7801/summary',
'https://qa.orcid.org/0009-0006-7603-4444/summary',
'https://qa.orcid.org/0009-0007-9334-3617/summary',
'http://localhost:4200/0009-0006-7603-4444/summary',
'http://localhost:4200/0009-0007-9334-3617/summary',
]
// Validate ORCID URL
function validateUrl(url) {
const orcidRegex =
/https?:\/\/.*\/\d{4}-\d{4}-\d{4}-\d{3}[0-9X](\/summary)$/
if (!orcidRegex.test(url)) {
throw new Error(
"Invalid URL. The URL must contain a valid ORCID ID and optionally end with '/summary'."
)
}
}
// Initialize URLs from localStorage or defaults
function loadUrls() {
let savedUrls = JSON.parse(localStorage.getItem('iframeUrls')) || []
savedUrls = savedUrls.concat(defaultUrls)
savedUrls = savedUrls.filter(
(url, index, self) => self.indexOf(url) === index
) // Remove duplicates
localStorage.setItem('iframeUrls', JSON.stringify(savedUrls)) // Ensure defaults are saved
updateDropdown(savedUrls)
}
function groupUrlsByDomain(urls) {
const grouped = {}
urls.forEach((url) => {
try {
const { hostname } = new URL(url) // Extract base domain
if (!grouped[hostname]) grouped[hostname] = []
grouped[hostname].push(url)
} catch (e) {
console.error(`Invalid URL skipped: ${url}`)
}
})
return grouped
}
// Update dropdown with URLs
function updateDropdown(urls) {
const urlDropdown = document.getElementById('iframe-url')
urlDropdown.innerHTML = '<option value="">-- Select a URL --</option>' // Reset dropdown
// Group URLs by domain
const groupedUrls = groupUrlsByDomain(urls)
// Create optgroups for each domain
Object.keys(groupedUrls).forEach((domain) => {
const optgroup = document.createElement('optgroup')
optgroup.label = domain // Set the group label to the domain
groupedUrls[domain].forEach((url) => {
const option = document.createElement('option')
option.value = url
option.textContent = url
optgroup.appendChild(option)
})
urlDropdown.appendChild(optgroup) // Add the group to the dropdown
})
}
// Select a URL from the dropdown
function selectUrl() {
const selectedUrl = document.getElementById('iframe-url').value
document.getElementById('new-url').value = selectedUrl
}
// Open the dialog with the selected or entered URL
function openDialog(width, height) {
const url = document.getElementById('new-url').value.trim()
if (!url) {
alert('Please enter or select a URL.')
return
}
try {
validateUrl(url) // Validate the URL before proceeding
} catch (error) {
alert(error.message)
return
}
// Save URL to "Previously Open URLs" if not already present
let urls = JSON.parse(localStorage.getItem('iframeUrls')) || []
if (!urls.includes(url)) {
urls.push(url)
localStorage.setItem('iframeUrls', JSON.stringify(urls))
updateDropdown(urls)
}
const dialog = document.getElementById('dialog-box')
const iframe = document.getElementById('dialog-iframe')
// Set iframe URL and dialog dimensions
iframe.src = url
dialog.style.width = `${width}px`
dialog.style.height = `${height}px`
// Display the dialog
dialog.style.display = 'block'
}
// Close the dialog
function closeDialog() {
const dialog = document.getElementById('dialog-box')
const iframe = document.getElementById('dialog-iframe')
// Hide the dialog and clear the iframe URL
dialog.style.display = 'none'
iframe.src = ''
}
// Load URLs when the page loads
window.onload = loadUrls
</script>
</body>
</html>