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 URL's added here will be added as <link>
s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.
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.
If the stylesheet 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 CSS 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.
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.
<h1>Create Player</h1>
<section class="bcls-section">
<h2 id="infoinput">Player info input</h2>
<p>Account ID: <input class="checkForValue" id="account_id_input" type="text" size="40" name="account_id" /></p>
<p>Client ID: <input class="checkForValue" id="client_id_input" type="text" size="100" name="client_id_input" /></p>
<p>Client Secret: <input class="checkForValue" id="client_secrect_input" type="password" size="100" name="client_secrect_input" /></p>
<p>Player Name: <input class="checkForValue" id="player_name_input" type="text" size="100" name="player_name_input" /></p>
<p>Media URL OR Video Cloud video id: <input class="checkForValue" id="media_url_input" type="text" size="200" value="https://learning-services-media.brightcove.com/videos/mp4/oystercatcher.mp4" name="media_url_input" /></p>
<p>Media Type: <select id="media_type_input"><option value="video/mp4" selected="selected">video/mp4</option><option value="application/x-mpegURL">HLS (application/x-mpegURL)</option></select></p>
<p><button id="create_player" class="bcls-button">Create Player</span></p>
</section>
<section class="bcls-section">
<h2 id="jsonText">JSON response</h2>
<p>Below is the JSON data returned by the player creation:</p>
<pre><code id="create_response">Response will appear here...</code></pre>
<p>Below is the JSON data returned by the player publish:</p>
<pre><code id="publish_response">Response will appear here...</code></pre>
</section>
<section class="bcls-section">
<h2 id="embedded_player">Processed response</h2>
<p>
<button class="bcls-button" id="preview_player">Preview the Player</button>
</p>
<p>Note publishing is asynchrounous; if the player doesn't immediately appear, wait a few seconds and try again. </p>
<div id="player_embedded"></div>
</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) {
// account id calue is the default
var account_id = '57838016001',
account_password = '',
account_username = '',
player_name = '',
player_id,
account_id_input = document.getElementById('account_id_input'),
client_id_input = document.getElementById('client_id_input'),
client_secrect_input = document.getElementById('client_secrect_input'),
player_name_input = document.getElementById('player_name_input'),
media_url_input = document.getElementById('media_url_input'),
media_type_input = document.getElementById('media_type_input'),
create_response = document.getElementById('create_response'),
publish_response = document.getElementById('publish_response'),
player_embedded = document.getElementById('player_embedded'),
create_player = document.getElementById('create_player'),
preview_player = document.getElementById('preview_player'),
player_code,
now = new Date();
// initial value for player name (make unique)
player_name_input.value = 'Test Player ' + now.toISOString();
// event handlers
create_player.addEventListener('click', function() {
createRequest('createPlayer');
});
preview_player.addEventListener('click', function() {
// inject the player - clear the div first to allow repeated clicks
player_embedded.innerHTML = '';
player_embedded.insertAdjacentHTML('afterbegin', player_code);
});
/**
* get selected value for single select element
* @param {htmlElement} e the select element
* @return {String} the selected value
*/
function getSelectedValue(e) {
var selected = e.options[e.selectedIndex],
val = selected.value;
return val;
}
/**
* createRequest sets up requests, send them to makeRequest(), and handles responses
* @param {string} type the request type
*/
function createRequest(type) {
var options = {},
requestBody = {},
proxyURL = 'https://solutions.brightcove.com/bcls/bcls-proxy/bcls-proxy-v2.php',
baseURL = 'https://players.api.brightcove.com/v1/accounts/',
endpoint,
responseDecoded;
if (client_id_input.value.length > 0 && client_secrect_input.value.length > 0) {
options.client_id = client_id_input.value;
options.client_secret = client_secrect_input.value;
}
options.account_id = (account_id_input.value.length > 0) ? account_id_input.value : account_id;
options.proxyURL = proxyURL;
switch (type) {
case 'createPlayer':
endpoint = '/' + options.account_id + '/players';
options.url = baseURL + endpoint;
options.requestType = 'POST';
requestBody.name = player_name_input.value;
requestBody.configuration = {};
if (media_url_input.value.indexOf('//') > -1) {
requestBody.configuration.media = {};
requestBody.configuration.media.sources = [];
requestBody.configuration.media.sources[0] = {};
requestBody.configuration.media.sources[0].src = media_url_input.value;
requestBody.configuration.media.sources[0].type = getSelectedValue(media_type_input);
} else {
// assume video id
requestBody.configuration.video_cloud = {};
requestBody.configuration.video_cloud.video = media_url_input.value;
}
options.requestBody = JSON.stringify(requestBody);
makeRequest(options, function(response) {
responseDecoded = JSON.parse(response);
player_id = responseDecoded.id;
create_response.textContent = JSON.stringify(responseDecoded, null, 2);
if (player_id) {
createRequest('publishPlayer');
}
});
break;
case 'publishPlayer':
endpoint = '/' + options.account_id + '/players/' + player_id + '/publish';
options.url = baseURL + endpoint;
options.requestType = 'POST';
makeRequest(options, function(response) {
responseDecoded = JSON.parse(response);
player_code = responseDecoded.embed_code;
publish_response.textContent = JSON.stringify(responseDecoded, null, 2);
});
break;
// additional cases
default:
console.log('Should not be getting to the default case - bad request type sent');
break;
}
}
/**
* 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,
requestParams,
dataString,
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.strinify(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));
}
})(window, document);
Also see: Tab Triggers