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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<section class="bcls-section">
<h2 id="video_data">Replace Videos App</h2>
<p>This script expects a data set as a JSON array of objects like this:</p>
<p>Video data:</p>
<textarea id="videoData" class="bcls-code">[
{
"name": "Woodpecker",
"id": "3931368189001",
"url": "http://learning-services-media.brightcove.com/videos/mp4/Bird_Woodpecker.mp4"
},
{
"name": "Chickadee",
"id": "3931294493001",
"url": "http://learning-services-media.brightcove.com/videos/mp4/Bird_Chickadee.mp4"
},
{
"name": "Great Blue Heron",
"id": "3931294494001",
"url": "http://learning-services-media.brightcove.com/videos/mp4/greatblueheron.mp4"
},
{
"name": "Great Horned Owl",
"id": "3931368155001",
"url": "http://learning-services-media.brightcove.com/videos/mp4/greathornedowl.mp4"
}
]</textarea>
<p>This is the actual data used in this sample. You could include other metadata fields, but you would need to modify the script a little to send those with the first API call. You'll also notice that these are risky values to use for reference ids, especially
for a sample like this that will be run multiple times - but I am getting around the duplication issue by appending the current epoch time in milliseconds to whatever is in the data.</p>
<div class="form-wrapper">
<fieldset class="bcls-fieldset">
<legend>Inputs for Dynamic Ingest</legend>
<p>Account: (defaults to Brightcove sample account) <input id="account_id" type="text" value="" name="account_id" /></p>
<p>Client id: (defaults to Brightcove sample account) <input id="client_id" type="text" value="" name="client_id" /></p>
<p>Client secret: (defaults to Brightcove sample account) <input id="client_secret" type="text" value="" name="client_secret" /></p>
<p>Ingest profile: <select id="ingest_profile_display"></select><br /> or Custom Profile: <input id="custom_profile_display" type="text" value="" name="custom_profile_display" /> (you must use the name exactly as it appears in the Video Cloud system,
or the request will fail)</p>
<p><button class="bcls-button" id="di_Submit">Start Replacing Videos</button></p>
<p>Full request URL for the API call:<br />
<textarea class="bcls-code" name="url" id="di_url"></textarea> (automatically generated - for information only)</p>
</fieldset>
</div>
</section>
<section class="bcls-section">
<h2 id="logger">Results Log</h2>
<pre class="line-numbers">
<code id="response" class="language-json">Response will appear here...</code></pre>
</section>
/* * 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 account_id_display = document.getElementById('account_id'),
account_id,
client_id_display = document.getElementById('client_id'),
client_id,
client_secret_display = document.getElementById('client_secret'),
client_secret,
ingest_profile_display = document.getElementById('ingest_profile_display'),
ingest_profile,
custom_profile_display = document.getElementById('custom_profile_display'),
videoDataDisplay = document.getElementById('videoData'),
// Dynamic Ingest API stuff
profilesArray = ['multi-platform-standard-static', 'multi-platform-standard-static-with-mp4', 'multi-platform-extended-static', 'multi-platform-extended-static-with-mp4', 'multi-platform-standard-dynamic-with-mp4', 'multi-platform-standard-dynamic', 'low-bandwidth-dynamic-with-mp4', 'low-bandwidth-dynamic', 'multi-platform-extended-dynamic-with-mp4', 'multi-platform-extended-dynamic'],
di_url = 'https://ingest.api.brightcove.com/v1/accounts/',
di_url_display = document.getElementById('di_url'),
di_submit_display = document.getElementById('di_Submit'),
proxyURL = 'https://solutions.brightcove.com/bcls/bcls-proxy/bcls-proxy-v2.php',
response = document.getElementById('response'),
videoData = [],
totalVideos,
videoNumber = 0,
currentJobs = 0,
t1,
t2,
totalIngested = 0,
defaults = {
account_id: 57838016001
},
callbacks = ["http://solutions.brightcove.com/bcls/dynamic-delivery/di-callbacks.php"];
// is defined
function isDefined(x) {
if (x === '' || x === null || x === undefined) {
return false;
}
return true;
}
// set options for the Dynamic Ingest API request
function setDIOptions() {
var options = {},
reqBody = {};
custom_profile_display_value = custom_profile_display.value;
di_url_display.value = di_url + account_id + '/videos/' + videoData[videoNumber].id + '/ingest-requests';
// get the ingest profile
if (isDefined(custom_profile_display_value)) {
ingest_profile = custom_profile_display_value;
} else {
ingest_profile = ingest_profile_display.options[ingest_profile_display.selectedIndex].value;
}
if (isDefined(client_id) && isDefined(client_secret)) {
options.client_id = client_id;
options.client_secret = client_secret;
}
options.account_id = account_id;
options.proxyURL = proxyURL;
reqBody.master = {};
reqBody.master.url = videoData[videoNumber].url;
reqBody.profile = ingest_profile;
reqBody.callbacks = callbacks;
options.requestBody = JSON.stringify(reqBody);
options.requestType = 'POST';
options.url = di_url_display.value;
// now submit the request
makeRequest(options, function(response) {
response = JSON.parse(response);
totalIngested++;
logResponse('totalIngested', totalIngested);
if (videoNumber < totalVideos - 1) {
videoNumber++;
currentJobs++;
logResponse('Processing video number', videoNumber);
logResponse('Current jobs: ', currentJobs);
// if currentJobs is > 99, need to pause
if (currentJobs > 99) {
// reset currentJobs
currentJobs = 0;
// wait 30 sec before resuming
t2 = setTimeout(setDIOptions, 180000);
} else {
// pause to avoid DI API timeouts
t2 = setTimeout(setDIOptions, 1000);
}
}
});
}
// function to set the request
function logResponse(type, data) {
response.textContent += type + ': ' + data + ',\n';
}
/**
* send API request to the proxy
* @param {Object} options for the request
* @param {String} options.url the full API request URL
* @param {String="GET","POST","PATCH","PUT","DELETE"} requestData [options.requestType="GET"] HTTP type for the request
* @param {String} options.proxyURL proxyURL to send the request to
* @param {String} options.client_id client id for the account (default is in the proxy)
* @param {String} options.client_secret client secret for the account (default is in the proxy)
* @param {JSON} [options.requestBody] Data to be sent in the request body in the form of a JSON string
* @param {Function} [callback] callback function that will process the response
*/
function makeRequest(options, callback) {
var httpRequest = new XMLHttpRequest(),
response,
proxyURL = options.proxyURL,
// response handler
getResponse = function() {
try {
if (httpRequest.readyState === 4) {
if (httpRequest.status >= 200 && httpRequest.status < 300) {
response = httpRequest.responseText;
// some API requests return '{null}' for empty responses - breaks JSON.parse
if (response === '{null}') {
response = null;
}
// return the response
callback(response);
} else {
alert('There was a problem with the request. Request returned ' + httpRequest.status);
}
}
} catch (e) {
alert('Caught Exception: ' + e);
}
};
/**
* set up request data
* the proxy used here takes the following request body:
* JSON.stringify(options)
*/
// set response handler
httpRequest.onreadystatechange = getResponse;
// open the request
httpRequest.open('POST', proxyURL);
// set headers if there is a set header line, remove it
// open and send request
httpRequest.send(JSON.stringify(options));
}
di_submit_display.addEventListener('click', function() {
var i, now = new Date().valueOf();
videoData = JSON.parse(videoDataDisplay.value);
totalVideos = videoData.length;
// to insure uniqueness,
for (i = 0; i < totalVideos; i++) {
videoData[i].reference_id += '_' + now.toString();
}
// in case of stop/start, reset videoNumber to 0
videoNumber = 0;
// get account inputs
account_id = isDefined(account_id_display.value) ? account_id_display.value : defaults.account_id;
client_id = isDefined(client_id_display.value) ? client_id_display.value : null;
client_secret = isDefined(client_secret_display.value) ? client_secret_display.value : null;
// set DI API options for first video
setDIOptions();
});
// initialize
function init() {
var i,
iMax = profilesArray.length,
newOpt;
// add options for standard ingest profiles
for (i = 0; i < iMax; i++) {
newOpt = new Option(profilesArray[i]);
ingest_profile_display.add(newOpt);
}
}
// call init to set things up
init();
})(window, document);
Also see: Tab Triggers