HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<fieldset class="bcls-fieldset"><legend>Input</legend>
<p>If you don't include values below, a Brightcove sample account will be used.</p>
<p>Account id: <input type="text" id="account_id_input" style="width:40%;" /></p>
<p>Policy key: <input type="text" id="policy_key_input" style="width:70%;" /></p>
<p>Playlist id: <input type="text" id="playlist_id_input" style="width:40%;" /></p>
<p>Feed description: <input type="text" id="feedDescription" value="My MRSS Feed" /> <span style="color:#FDCD0B;">Required!</span></p>
<p>Site or video portal URL: <input type="text" size="40" id="siteURL" value="https://mysite.com" /> <span style="color:#FDCD0B;">Required!</span></p>
<p>MRSS feed URL (atom link): <input type="text" size="40" id="feedURL" value="https://mysite.com/mrss.xml" /> <span style="color:#FDCD0B;">Required!</span></p>
<button id="showJSON" class="bcls-button">Show JSON</button><button id="showMRSS" class="bcls-button">Show MRSS</button>
<div><textarea id="feed" class="bcls-code" style="height:400px;">Feed will appear here...</textarea></div>
</fieldset>
/* * The body style is just for the
* background color of the codepen.
* Do not include in your code.
*/
body {
background-color: #111;
color: #f5f5f5;
font-family: sans-serif;
margin: 2em;
}
/*
* Styles essential to the sample
* are below
*/
.bcls-code {
color: #111;
font-family: 'Source Code Pro',monospace;
padding: 1em;
width: 90%;
min-height: 5em;
background-color: #cfcfcf;
font-size: 1rem;
}
.bcls-button {
padding: .5em;
background-color: #333;
border: 1px yellow solid;
border-radius: .5em;
color: yellow;
cursor: pointer;
}
fieldset {
color: #64AAB2;
border: 1px #64AAB2 solid;
border-radius: .5em;
}
code {
color: #E4B842;
font-family: 'Source Code Pro',monospace;
}
var BCLS = (function(window, document) {
var showJSON = document.getElementById("showJSON"),
showMRSS = document.getElementById("showMRSS"),
mrssOutput = false,
feed = document.getElementById("feed"),
account_id_input = document.getElementById("account_id_input"),
videoData,
policy_key_input = document.getElementById("policy_key_input"),
playlist_id_input = document.getElementById("playlist_id_input"),
siteURL = document.getElementById('siteURL'),
feedURL = document.getElementById('feedURL'),
feedDescription = document.getElementById('feedDescription'),
account_id,
policyKey,
playlist_id,
feedname,
// the next three lines are the ones that need to be changed
account_id_default = "1752604059001",
policyKey_default =
"BCpkADawqM3_9ax216PJYuUTLApMLkLJ3apjFlTRKHHS4q0DE33J0XsiDWmc6SfKwrwRAhejCZpTbwljz4-OlUwyqKi64L25Dwy4yhY1eSZ9ZduI-dO0mjSNVcR9C8nz0jtkimOOtzQgswCr",
playlist_id_default = "5492280057001",
// vars for MRSS generation
mrssStr =
'<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" xmlns:atom="http://www.w3.org/2005/Atom">',
sCdata = '<![CDATA[',
eCdata = ']]>',
sChannel = "<channel>",
eChannel = "</channel>",
sTitle = "<title>",
eTitle = "</title>",
sDescription = "<description>",
eDescription = "</description>",
sItem = "<item>",
eItem = "</item>",
sLink = "<link>",
eLink = "</link>",
sPubDate = "<pubDate>",
ePubDate = "</pubDate>",
sGuid = '<guid isPermaLink="false">',
eGuid = '</guid>',
sMediaContent = "<media:content",
eMediaContent = " />",
sMediaPlayer = "<media:player",
eMediaPlayer = " />",
sMediaDescription = "<description>",
eMediaDescription = "</description>",
sMediaThumbnail = "<media:thumbnail",
eMediaThumbnail = "/>",
sMediaTitle = "<title>",
eMediaTitle = "</title>";
// event listeners for the buttons
showJSON.addEventListener("click", function() {
mrssOutput = false;
// get media data if we haven't already
if (!isDefined(videoData)) {
// check inputs to see if we use those or default values
if (
isDefined(account_id_input.value) &&
isDefined(policy_key_input.value) &&
isDefined(playlist_id_input.value)
) {
account_id = removeSpaces(account_id_input.value);
policyKey = removeSpaces(policy_key_input.value);
playlist_id = removeSpaces(playlist_id_input.value);
} else {
account_id = account_id_default;
policyKey = policyKey_default;
playlist_id = playlist_id_default;
}
getMediaData(function() {
feed.textContent = JSON.stringify(videoData, null, " ");
});
} else {
// JSON data to the textarea
feed.textContent = JSON.stringify(videoData, null, " ");
}
});
showMRSS.addEventListener("click", function() {
mrssOutput = true;
// get media data if we haven't already
if (!isDefined(videoData)) {
// check inputs to see if we use those or default values
if (
isDefined(account_id_input.value) && isDefined(policy_key_input.value) && isDefined(playlist_id_input.value)
) {
account_id = removeSpaces(account_id_input.value);
policyKey = removeSpaces(policy_key_input.value);
playlist_id = removeSpaces(playlist_id_input.value);
} else {
account_id = account_id_default;
policyKey = policyKey_default;
playlist_id = playlist_id_default;
}
getMediaData(function() {
processMRSS();
});
} else {
processMRSS();
}
});
function processMRSS() {
var i, iMax, sources;
iMax = videoData.length;
for (i = 0; i < iMax; i++) {
sources = videoData[i].sources;
if (sources.length > 0) {
// get the best MP4 rendition
var source = processSources(sources);
videoData[i].source = source;
} else {
// video has no sources
videoData[i].source = null;
}
}
// remove videos with no sources
i = videoData.length;
while (i > 0) {
i--;
if (!isDefined(videoData[i].source)) {
videoData.splice(i, 1);
}
}
// generate and display the MRSS data
addItems();
}
/**
* tests for all the ways a variable might be undefined or not have a value
* @param {String|Number} x the variable to test
* @return {Boolean} true if variable is defined and has a value
*/
function isDefined(x) {
if (x === "" || x === null || x === undefined) {
return false;
}
return true;
}
/**
* remove spaces from a string
* @param {String} str string to process
* @return {String} trimmed string
*/
function removeSpaces(str) {
str = str.replace(/\s/g, "");
return str;
}
/**
* sort an array of objects based on an object property
* @param {array} targetArray - array to be sorted
* @param {string|number} objProperty - object property to sort on
* @return sorted array
*/
function sortArray(targetArray, objProperty) {
targetArray.sort(function(b, a) {
var propA = a[objProperty],
propB = b[objProperty];
// sort ascending; reverse propA and propB to sort descending
if (propA < propB) {
return -1;
} else if (propA > propB) {
return 1;
} else {
return 0;
}
});
return targetArray;
}
/**
* [processSources gets the highest bitrate source for the MRSS feed
* @param {Array} sources array of video sources
* @return {Object} the highest bitrate MP4 source
*/
function processSources(sources) {
var i = sources.length;
// remove non-MP4 sources
while (i > 0) {
i--;
if (sources[i].container !== "MP4") {
sources.splice(i, 1);
} else if (sources[i].hasOwnProperty("stream_name")) {
sources.splice(i, 1);
}
}
// sort sources by encoding rate
sortArray(sources, "encoding_rate");
// return the first item (highest bitrate)
return sources[0];
}
/**
* add video items to the MRSS feed
*/
function addItems() {
var i,
iMax,
video,
pubdate,
videoURL,
thumbnailURL,
doThumbnail = true;
if (videoData.length > 0) {
mrssStr += sChannel;
mrssStr += '<atom:link href="' + feedURL.value.replace(/&/g, '&') + '" rel="self" type="application/rss+xml" />';
mrssStr += sTitle + feedname + eTitle;
mrssStr += sDescription + sCdata + feedDescription.value + eCdata + eDescription;
mrssStr += sLink + siteURL.value.replace(/&/g, "&") + eLink;
iMax = videoData.length;
for (i = 0; i < iMax; i += 1) {
doThumbnail = true;
video = videoData[i];
// video may not have a valid source
if (isDefined(video.source) && isDefined(video.source.src)) {
videoURL = video.source.src.replace(/&/g, "&");
} else {
// no source; skip this videos
continue;
}
// depending on when/how the video was created, it may have different thumbnail properties or none at all
if (isDefined(video.thumbnail)) {
thumbnailURL = encodeURI(video.thumbnail.replace(/&/g, "&"));
} else {
doThumbnail = false;
}
pubdate = new Date(video.created_at).toGMTString();
mrssStr += sItem;
mrssStr +=
sLink +
"https://players.brightcove.net/" +
account_id +
"/default_default/index.html?videoId=" +
video.id +
eLink;
mrssStr += sPubDate + pubdate + ePubDate;
mrssStr += sGuid + video.id + eGuid;
mrssStr +=
sMediaContent +
' url="' +
videoURL +
'" fileSize="' +
video.source.size +
'" type="video/quicktime" medium="video" duration="' +
video.duration / 1000 +
'" isDefault="true" height="' +
video.source.height +
'" width="' +
video.source.width +
'"' + eMediaContent;
mrssStr +=
sMediaPlayer +
' url="' +
"https://players.brightcove.net/" +
account_id +
"/default_default/index.html?videoId=" +
video.id +
'"' +
eMediaPlayer;
mrssStr += sMediaTitle + video.name + eMediaTitle;
mrssStr += sMediaDescription + sCdata + video.description + eCdata + eMediaDescription;
if (doThumbnail) {
mrssStr += sMediaThumbnail + ' url="' + thumbnailURL + '"';
if (isDefined(video.images)) {
mrssStr +=
' height="' +
video.images.thumbnail.sources[0].height +
'" width="' +
video.images.thumbnail.sources[0].width +
'"' +
eMediaThumbnail;
} else {
mrssStr += eMediaThumbnail;
}
}
mrssStr += eItem;
}
mrssStr += eChannel + "</rss>";
feed.textContent = vkbeautify.xml(mrssStr);
}
}
feed.addEventListener("click", function() {
feed.select();
});
/**
* makes the request to the Playback API
*/
function getMediaData(callback) {
var httpRequest = new XMLHttpRequest(),
responseData,
parsedData,
requestURL =
"https://edge.api.brightcove.com/playback/v1/accounts/" +
account_id +
"/playlists/" +
playlist_id +
"?limit=100";
// response handler
getResponse = function() {
try {
if (httpRequest.readyState === 4) {
if (httpRequest.status >= 200 && httpRequest.status < 300) {
responseData = httpRequest.responseText;
parsedData = JSON.parse(responseData);
videoData = parsedData.videos;
feedname = parsedData.name;
if (mrssOutput) {
callback();
} else {
callback();
}
} else {
alert(
"There was a problem with the request. Request returned " +
httpRequest.status
);
}
}
} catch (e) {
alert("Caught Exception: " + e);
}
};
// set response handler
httpRequest.onreadystatechange = getResponse;
// open the request
httpRequest.open("GET", requestURL);
// set headers
httpRequest.setRequestHeader("Accept", "application/json;pk=" + policyKey);
// open and send request
httpRequest.send();
}
})(window, document);
Also see: Tab Triggers