This repository has been archived by the owner on Jun 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 171
/
Copy pathEmbedLiveSample.ejs
60 lines (56 loc) · 1.98 KB
/
EmbedLiveSample.ejs
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
<%
// Embeds a live sample given the ID of its header block.
//
// Parameters:
// $0 - The ID of the header block containing the sample
// $1 - The width of the iframe (optional)
// $2 - The height of the iframe (optional)
// $3 - The url of a screenshot of the sample working as intended (optional)
// $4 - The slug from which to load the sample (optional; current page used if not provided)
// $5 - The class name of the frame; defaults to "sample-code-frame". If you
// pass this parameter and give it a value other than "sample-code-frame",
// then the "Open in CodePen"/"Open in JSFiddle" buttons will not be displayed.
// $6 - Allowed features, separated by semicolons (optional)
//
// See also : LiveSampleLink
var sampleId = $0;
var width = $1;
var height = $2;
var screenshotUrl = $3;
var sampleSlug = $4;
var className = $5 || "sample-code-frame";
var allowedFeatures = $6;
var hasScreenshot = (screenshotUrl && (screenshotUrl.length > 0));
var sampleUrl = "";
if (sampleSlug) {
sampleUrl = "https://developer.mozilla.org/" + env.locale + "/docs";
if (sampleSlug.charAt(0) != "/") {
sampleUrl += "/";
}
sampleUrl += sampleSlug;
}
var url = await template('LiveSampleURL', [sampleId, sampleUrl]);
if (hasScreenshot) {
%><table class="sample-code-table"><%
%><thead><%
%><tr><%
%><th scope="col" style="text-align: center;">Screenshot</th><%
%><th scope="col" style="text-align: center;">Live sample</th><%
%></tr><%
%></thead><%
%><tbody><%
%><tr><%
%><td><%
%><img alt="" class="internal" src="<%= screenshotUrl %>" /><%
%></td><%
%><td><%
} // end hasScreenshot
%><iframe class="live-sample-frame <%= className %>"<%
%> id="frame_<%= sampleId %>"<%
%> frameborder="0"<%
if (width) { %> width="<%= width %>"<% }
if (height) { %> height="<%= height %>"<% }
%> src="<%- url %>"<%
if (allowedFeatures) { %> allow="<%= allowedFeatures %>"<% }
%>></iframe><%
if (hasScreenshot) { %></td></tr></tbody></table><% } %>