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.
<section class="bcls-section">
<h2 id="app">Create Client Credentials</h2>
<fieldset>
<legend>Inputs</legend>
<p>Name for the credentials (no special characters): <input id="credentialsName" type="text" size="50" /></p>
<p>BC_TOKEN: <input id="bcToken" type="text" size="50" /></p>
<p>Account(s) to create credentials for (comma-delimited list): <input id="accountIds" type="text" size="50" placeholder="57838016001,1752604059001,921483702001" /></p>
<p>Account(s) type: <select name="accountTypeSelector" id="accountTypeSelector"><option value="video-cloud-account">Video Cloud</option><option value="video-cloud-account">Brightcove Player</option> </select></p>
<p>API operations to enable (see <a href="https://support.brightcove.com/api-operations-client-credentials-requests" target="_blank">API Operations for Client Credentials</a> for more information):</p>
<div id="operationsList"> </div>
<p><button id="submitButton" class="bcls-button">Get Client Credentials</button></p>
<p>Full API request body:</p>
<textarea name="apiRequest" id="apiRequest" class="bcls-code"></textarea></fieldset>
<fieldset>
<legend>Output</legend>
<h3>Client ID</h3>
<textarea name="clientId" id="clientId" class="bcls-code">Client ID will appear here...</textarea>
<h3>Client Secret</h3>
<textarea name="clientSecret" id="clientSecret" class="bcls-code">Client Secret will appear here...</textarea>
<h3>Full response</h3>
<pre class="line-numbers">
<code id="apiResponse" class="language-json">Full API response will appear here...</code></pre>
</fieldset>
</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: 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: monospace;
}
a {
color: #CF773F;
}
var BCLS = (function(window, document) {
var bcToken = document.getElementById("bcToken"),
credentialsName = document.getElementById("credentialsName"),
accountIds = document.getElementById("accountIds"),
operationsList = document.getElementById("operationsList"),
submitButton = document.getElementById("submitButton"),
apiRequest = document.getElementById("apiRequest"),
clientId = document.getElementById("clientId"),
clientSecret = document.getElementById("clientSecret"),
apiResponse = document.getElementById("apiResponse"),
defaultName = "Credentials from Learning Services App",
options = {},
requestBody = {},
accountsStr,
accounts = [],
operations = [
"video-cloud/analytics/read",
"video-cloud/audience/read",
"video-cloud/audience/write",
"video-cloud/cloud-playout/read",
"video-cloud/cloud-playout/all",
"video-cloud/experience/read",
"video-cloud/experience/all",
"video-cloud/image-token-management/read",
"video-cloud/image-token-management/write",
"video-cloud/player/read",
"video-cloud/player/all",
"video-cloud/playback-auth/key/read",
"video-cloud/playback-auth/key/write",
"video-cloud/playback-auth/playback-rights/read",
"video-cloud/playback-auth/playback-rights/write",
"video-cloud/playback-auth/devices/read",
"video-cloud/playback-auth/devices/write",
"video-cloud/playback-auth/blacklist",
"video-cloud/playback-auth/audit",
"video-cloud/ingest-profiles/profile/read",
"video-cloud/ingest-profiles/profile/write",
"video-cloud/ingest-profiles/account/read",
"video-cloud/ingest-profiles/account/write",
"video-cloud/upload-urls/read",
"video-cloud/video/all",
"video-cloud/video/read",
"video-cloud/video/clear-sources",
"video-cloud/video/create",
"video-cloud/video/update",
"video-cloud/video/delete",
"video-cloud/asset/delete",
"video-cloud/playlist/all",
"video-cloud/playlist/read",
"video-cloud/playlist/create",
"video-cloud/playlist/update",
"video-cloud/playlist/delete",
"video-cloud/sharing-relationships/read",
"video-cloud/sharing-relationships/create",
"video-cloud/sharing-relationships/update",
"video-cloud/sharing-relationships/delete",
"video-cloud/sharing-relationships/all",
"video-cloud/social/status/read",
"video-cloud/social/mrss/read",
"video-cloud/social/mrss/write",
"video-cloud/notifications/all",
"video-cloud/ssai/read",
"video-cloud/ssai/all",
"video-cloud/xdr/read"
],
selectedOperations = [],
operationsSelectAll,
operationsCollection,
proxyURL =
"https://solutions.brightcove.com/bcls/bcls-proxy/client-credentials-proxy.php",
client_id,
client_secret,
input,
space,
br,
label,
fragment = document.createDocumentFragment(),
i,
iMax;
// set initial requestBody properties
requestBody.type = "credential";
requestBody.maximum_scope = [];
// generate operations options
input = document.createElement("input");
space = document.createTextNode(" ");
label = document.createElement("label");
input.setAttribute("name", "operationsChkAll");
input.setAttribute("id", "operationsChkAll");
input.setAttribute("type", "checkbox");
input.setAttribute("value", "all");
label.setAttribute("for", "operationsChkAll");
label.setAttribute("style", "color:#F3951D;");
text = document.createTextNode("Select All");
label.appendChild(text);
br = document.createElement("br");
fragment.appendChild(input);
fragment.appendChild(space);
fragment.appendChild(label);
fragment.appendChild(br);
iMax = operations.length;
for (i = 0; i < iMax; i++) {
input = document.createElement("input");
space = document.createTextNode(" ");
label = document.createElement("label");
input.setAttribute("name", "operationsChk");
input.setAttribute("id", operations[i]);
input.setAttribute("type", "checkbox");
input.setAttribute("value", operations[i]);
label.setAttribute("for", operations[i]);
text = document.createTextNode(operations[i]);
label.appendChild(text);
br = document.createElement("br");
fragment.appendChild(input);
fragment.appendChild(space);
fragment.appendChild(label);
fragment.appendChild(br);
}
operationsList.appendChild(fragment);
// get references to checkboxes
operationsCollection = document.getElementsByName("operationsChk");
operationsSelectAll = document.getElementById("operationsChkAll");
// add event listener for select allows
operationsSelectAll.addEventListener("change", function() {
if (this.checked) {
selectAllCheckboxes(operationsCollection);
} else {
deselectAllCheckboxes(operationsCollection);
}
});
// event handlers
submitButton.addEventListener("click", function() {
var responseParsed;
if (isDefined(bcToken.value) && isDefined(accountIds.value)) {
requestBody.name = isDefined(credentialsName.value)
? credentialsName.value
: defaultName;
selectedOperations = getCheckedBoxValues(operationsCollection);
if (selectedOperations.length === 0) {
alert("You must select at least one API operation to enable");
return;
}
accountsStr = removeSpaces(accountIds.value);
accounts = accountsStr.split(",");
if (accounts.length === 0) {
alert("You must enter at least one account id");
return;
} else {
iMax = accounts.length;
for (i = 0; i < iMax; i++) {
var maximum_scope_template = {};
maximum_scope_template.identity = {};
maximum_scope_template.identity.type = getSelectedValue(
accountTypeSelector
).value;
maximum_scope_template.identity["account-id"] = parseInt(
accounts[i],
10
);
maximum_scope_template.operations = selectedOperations;
requestBody.maximum_scope.push(maximum_scope_template);
}
}
options.url = "https://oauth.brightcove.com/v4/client_credentials";
options.requestType = "POST";
options.requestBody = JSON.stringify(requestBody);
apiRequest.textContent = JSON.stringify(requestBody, null, " ");
options.bc_token = bcToken.value;
makeRequest(options, function(response) {
if (isJson(response)) {
responseParsed = JSON.parse(response);
client_id = responseParsed.client_id;
client_secret = responseParsed.client_secret;
apiResponse.textContent = JSON.stringify(responseParsed, null, " ");
clientId.textContent = client_id;
clientSecret.textContent = client_secret;
} else {
// didn't get JSON back, just dump responseRaw
apiResponse.textContent = response;
}
});
} else {
alert("A BC_TOKEN and at least one account id are required.");
}
});
clientId.addEventListener("click", function() {
this.select();
});
clientSecret.addEventListener("click", function() {
this.select();
});
/**
* tests for all the ways a variable might be undefined or not have a value
* @param {*} 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;
}
/*
* tests to see if a string is json
* @param {String} str string to test
* @return {Boolean}
*/
function isJson(str) {
try {
JSON.parse(str);
} catch (e) {
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;
}
/**
* get array of values for checked boxes in a collection
* @param {htmlElementCollection} checkBoxCollection collection of checkbox elements
* @return {Array} array of the values of the checked boxes
*/
function getCheckedBoxValues(checkBoxCollection) {
var checkedValues = [],
i,
iMax;
if (checkBoxCollection) {
iMax = checkBoxCollection.length;
for (i = 0; i < iMax; i++) {
if (checkBoxCollection[i].checked === true) {
checkedValues.push(checkBoxCollection[i].value);
}
}
return checkedValues;
} else {
console.log("Error: no input received");
return null;
}
}
/**
* selects all checkboxes in a collection
* @param {htmlElementCollection} checkboxCollection a collection of the checkbox elements, usually gotten by document.getElementsByName()
*/
function selectAllCheckboxes(checkboxCollection) {
var i,
iMax = checkboxCollection.length;
for (i = 0; i < iMax; i += 1) {
checkboxCollection[i].setAttribute("checked", "checked");
}
}
/**
* deselects all checkboxes in a collection
* @param {htmlElementCollection} checkboxCollection a collection of the checkbox elements, usually gotten by document.getElementsByName()
*/
function deselectAllCheckboxes(checkboxCollection) {
var i,
iMax = checkboxCollection.length;
for (i = 0; i < iMax; i += 1) {
checkboxCollection[i].removeAttribute("checked");
}
}
/**
* get selected value for single select element
* @param {htmlElement} e the select element
* @return {Object} object containing the `value`, text, and selected `index`
*/
function getSelectedValue(e) {
var selected = e.options[e.selectedIndex],
val = selected.value,
txt = selected.textContent,
idx = e.selectedIndex;
return {
value: val,
text: txt,
index: idx
};
}
/**
* send API request to the proxy
* @param {Object} options options for the request
* @param {String} requestID the type of request = id of the button
* @param {Function} [callback] callback function
*/
function makeRequest(options, callback) {
var httpRequest = new XMLHttpRequest(),
responseRaw,
requestParams,
// response handler
getResponse = function() {
try {
if (httpRequest.readyState === 4) {
if (httpRequest.status >= 200 && httpRequest.status < 300) {
// check for completion
responseRaw = httpRequest.responseText;
callback(responseRaw);
}
}
} catch (e) {
alert("Caught Exception: " + e);
}
};
// set up request data
requestParams =
"url=" +
encodeURIComponent(options.url) +
"&bc_token=" +
options.bc_token +
"&requestType=" +
options.requestType +
"&requestBody=" +
options.requestBody;
// set response handler
httpRequest.onreadystatechange = getResponse;
// open the request
httpRequest.open("POST", proxyURL);
// set headers
httpRequest.setRequestHeader(
"Content-Type",
"application/x-www-form-urlencoded"
);
// open and send request
httpRequest.send(requestParams);
}
})(window, document);
Also see: Tab Triggers