css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

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.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

<h2 id="sample_app">Add Cue Points</h2>

<fieldset class="bcls-fieldset"><legend>Account Information</legend>

<p>By default, you will get results from Brightcove sample account.</p>

<p><button class="bcls-button" id="useMyAccount">Use My Account Instead</button></p>

<div id="basicInfo" style="display:none;">
<table class="bcls-table">
	<tbody class="bcls-table__body">
			<td>Video Cloud Account (Publisher ID):</td>
			<td><input id="account" type="text" size="55" /></td>
			<td class="align-top no-wrap">Client id:</td>
			<td><input id="cid" type="text" size="100" value="" /> (must include permissions for <code>video-cloud/video/update</code> and <code>video-cloud/video/read</code> or <code>video-cloud/video/all</code>)</td>
			<td class="align-top no-wrap">Client secret:</td>
			<td><input id="secret" type="text" size="100" value="" /> (must include permissions for <code>video-cloud/video/update</code> and <code>video-cloud/video/read</code> or <code>video-cloud/video/all</code>)</td>

<p><button id="get_videos" class="bcls-button">Refresh Video List New Account Information</button></p>

<fieldset class="bcls-fieldset"><legend>Inputs</legend>

<p>Video to update: <select id="video" style="display:inline-block;width:40%;"></select></p>

<h4>Cue point information</h4>

<p>Name: <input id="name" type="text" style="display:inline-block;width:40%;" /></p>

<p>Type: <select id="type" style="display:inline-block;width:40%;"><option value="AD">AD</option><option value="CODE" selected="selected">CODE</option></select></p>

<p>Time: <input id="time" type="text" placeholder="2.45" style="display:inline-block;width:40%;" /></p>

<p>Metadata: <input id="metadata" type="text" style="display:inline-block;width:40%;" /></p>

<p>Force stop: <input type="checkbox" id="force_stop" value="true" /></p>

<p><button id="addCue" class="bcls-button">Add Cue Point</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button id="setRequest" class="bcls-button">Submit Video Update Request</button></p>

<h2 id="outputLog">Results</h2>

<fieldset class="bcls-fieldset"><legend>Outputs</legend>

<p>API request:<textarea id="apiRequest" class="bcls-code"></textarea></p>

<p>API request body:<textarea id="requestData" class="bcls-code"></textarea></p>

<pre class="line-numbers">
<code class="language-json" id="results">Response will appear here...</code></pre>

              /* * 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 info
  var useMyAccount = document.getElementById('useMyAccount'),
    basicInfo          = document.getElementById('basicInfo'),
    account            = document.getElementById('account'),
    cid                = document.getElementById('cid'),
    secret             = document.getElementById('secret'),
    get_videos         = document.getElementById('get_videos'),
    // value below is for BrightcoveLearning
    // default client id and secret should be stored in the proxy
    default_account_id = '57838016001',
    // cuepoint fields
    name               = document.getElementById('name'),
    type               = document.getElementById('type'),
    time               = document.getElementById('time'),
    metadata           = document.getElementById('metadata'),
    force_stop         = document.getElementById('force_stop'),
    // update info
    video              = document.getElementById('video'),
    addCue             = document.getElementById('addCue'),
    setRequest         = document.getElementById('setRequest'),
    // request / response display fields
    apiRequest         = document.getElementById('apiRequest'),
    requestData        = document.getElementById('requestData'),
    results            = document.getElementById('results'),
    // data objects
    updateData         = {},

  // set event listeners
  useMyAccount.addEventListener('click', function() {
    if (basicInfo.getAttribute('style') === 'display:none;') {
      basicInfo.setAttribute('style', 'display:block;');
      useMyAccount.textContent = 'Use Sample Account';
    } else {
      basicInfo.setAttribute('style', 'display:none;');
      useMyAccount.textContent = 'Use My Account Instead';

  addCue.addEventListener('click', function() {
    var cue = {};
    cue.name                = name.value;
    cue.type                = getSelectedValue(type).value;
    cue.time                = parseFloat(time.value);
    cue.metadata            = metadata.value;
    cue.force_stop          = isChecked(force_stop);
    name.value              = '';
    time.value              = '';
    metadata.value          = '';
    addCue.textContent      = 'Add Another Cue Point';
    requestData.textContent = JSON.stringify(updateData, null, '  ');

  setRequest.addEventListener('click', function() {
    // get or set values for the request
    if (account.value) {
      account_id = account.value;
    } else {
      account_id = default_account_id;
    if (cid.value) {
      client_id = cid.value;
    if (secret.value) {
      client_secret = secret.value;
    video_id = getSelectedValue(video).value;

  get_videos.addEventListener('click', function() {
    if (account.value && cid.value && secret.value) {
      account_id    = account.value;
      client_id     = cid.value;
      client_secret = secret.value;
    } else {
      alert('The account id, client id, and client secret are required if you wish to use your own account');

   * 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

   * determines if checkbox is checked
   * @param  {htmlElement}  e the checkbox to check
   * @return {Boolean}  true if box is checked
  function isChecked(e) {
    if (e.checked) {
      return true;
    return false;

   * createRequest sets up requests, send them to makeRequest(), and handles responses
   * @param  {string} type the request type
  function createRequest(type) {
    var options  = {},
      cmsBaseURL = 'https://cms.api.brightcove.com/v1/accounts/' + account_id,
    // set credentials and proxy url
    // if no client id and secret entered, let the proxy use defaults
    if (cid.value.length > 0 && secret.value.length > 0) {
      options.client_id     = cid.value;
      options.client_secret = secret.value;
    options.proxyURL      = 'https://solutions.brightcove.com/bcls/bcls-proxy/bcls-proxy-v2.php';

    switch (type) {
      case 'getVideos':
        endpoint = '/videos?q=playable:true&limit=20';
        options.url = cmsBaseURL + endpoint;
        options.requestType = 'GET';
        makeRequest(options, function(response) {
          responseDecoded = JSON.parse(response);
          // add options to the video selector
          if (Array.isArray(responseDecoded)) {
            // remove existing options
            iMax = video.length;
            for (i = 0; i < iMax; i++) {
            // add new options
            iMax = responseDecoded.length;
            for (i = 0; i < iMax; i++) {
              el = document.createElement('option');
              el.setAttribute('value', responseDecoded[i].id);
              if (i === 0) {
                el.setAttribute('selected', 'selected');
              txt = document.createTextNode(responseDecoded[i].name);
      case 'updateVideo':
        endpoint = '/videos/' + video_id;
        options.url = cmsBaseURL + endpoint;
        options.requestType = 'PATCH';
        options.requestBody = JSON.stringify(updateData);
        apiRequest.textContent = options.url;
        requestData.textContent = JSON.stringify(updateData, null, '  ');
        makeRequest(options, function(response) {
          responseDecoded = JSON.parse(response);
          results.textContent = JSON.stringify(responseDecoded, null, '  ');
        // additional cases
        console.log('Should not be getting to the default case - bad request type sent');

   * 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(),
      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
            } 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

  function init() {
    // array for cue point data
    updateData.cue_points = [];
    // initially get videos from BrightcoveLearning account
    account_id = default_account_id;


})(window, document);

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................