Template:EmbedLiveSample

  • Revision slug: Template:EmbedLiveSample
  • Revision title: Template:EmbedLiveSample
  • Revision id: 425025
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment

Revision Content

<% // 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) // // See also : LiveSampleLink var str = ""; var sampleUrl = ""; if ($4) { sampleUrl = "https://developer.mozilla.org/" + env.locale + "/docs"; if ($4.charAt(0) != "/") { sampleUrl += "/"; } sampleUrl += $4; } %>

Sample URL: <%-sampleUrl%>

<% var widthHeight = ""; if ($1 && $2) { widthHeight = "width='" + $1 + "' height='" + $2 + "' "; } var liveSample = ''; if ($3) { str += ''; str += ''; str += ''; str += ''; str += ''; str += ''; str += '
ScreenshotLive sample
' + liveSample + '
'; } else { str += liveSample; } %> <%- str %>

Revision Source

<%
// 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)
//
// See also : LiveSampleLink
 
var str = "";
var sampleUrl = "";

if ($4) {
    sampleUrl = "https://developer.mozilla.org/" + env.locale + "/docs";
    if ($4.charAt(0) != "/") {
        sampleUrl += "/";
    }
    sampleUrl += $4;
}
 
%><p>Sample URL: <%-sampleUrl%></p><%
 
var widthHeight = "";
if ($1 && $2) {
    widthHeight = "width='" + $1 + "' height='" + $2 + "' ";
}
var liveSample = '<iframe  frameborder="0" ' + widthHeight + 'src="' + template('LiveSampleURL', [$0, sampleUrl]) + '"></iframe>';
if ($3) {
    str += '<table><thead><tr>';
    str += '<th scope="col" style="text-align: center;">Screenshot</th>';
    str += '<th scope="col" style="text-align: center;">Live sample</th>';
    str += '</tr></thead><tbody><tr>';
    str += '<td><img alt="" class="internal" src="' + $3 + '" /></td>';
    str += '<td>' + liveSample + '</td>';
    str += '</tr></tbody></table>';
} else {
    str += liveSample;
}
%>
<%- str %>
Revert to this revision