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.

              <h1>Display Players</h1>
<section id="accountinput" class="bcls-section">
<h2>Account input</h2>
<p>If you do not enter information, a sample Brightcove account will be used.</p>
<p>Account ID: <input id="account_id_input" type="text" size="40" name="account_id" /></p>

<p>Client ID: <input id="client_id_input" type="text" size="40" name="account_username" /></p>

<p>Client Secret: <input id="client_secret_input" type="password" size="100" name="account_password" /></p>

<p><button id="get_players" class="bcls-button">Display Players</button></p>

<section id="jsonText" class="bcls-section">
<h2>JSON response</h2>

<p>Below is the JSON data returned by the request:</p>

<textarea id="api_response" class="bcls-code">Response will appear here...</textarea>

<section id="processedResponse" class="bcls-section">
<h2>Processed response</h2>
<p>Below is simple HTML output of some of the player information. Select a player to see more details.</p>
  <button class="bcls-button" id="show_more_players">Show Next Set of Players</button>

<div id="player_list" class="inline-div"></div>
<div id="player_details" class="inline-div"></div>

              /* * 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;
.inline-div {
  display: inline-block;
              var BCLS = ( function (window, document) {
  // account id value is the default Brightcove Learning account
  var account_id = '1752604059001',
    account_id_input = document.getElementById('account_id_input'),
    client_id_input = document.getElementById('client_id_input'),
    client_secrect_input = document.getElementById('client_secrect_input'),
    api_response = document.getElementById('api_response'),
    player_embedded = document.getElementById('player_embedded'),
    get_players = document.getElementById('get_players'),
    show_more_players = document.getElementById('show_more_players'),
    radioGroup = document.getElementsByName('playerList'),
    player_list = document.getElementById('player_list'),
    player_details = document.getElementById('player_details'),
    playerCount = 0,
    nextPlayerStart = 0,
    // event handlers
    get_players.addEventListener('click', function() {

    show_more_players.addEventListener('click', function() {
      // show players in groups of 3 (the number can be whatever you like)

   * get value of a selected radio buttom
   * @param {htmlElementCollection} rgroup the collection of radio buttom elements
  function getRadioValue(rgroup) {
    var i = 0,
    iMax = rgroup.length;
    for (i; i < iMax; i++) {
        if (rgroup[i].checked) {
            return rgroup[i].value;

   * find index of an object in array of objects
   * based on some property value
   * @param {array} targetArray array to search
   * @param {string} objProperty object property to search
   * @param {string} value of the property to search for
   * @return {integer} index of first instance if found, otherwise returns -1
  function findObjectInArray(targetArray, objProperty, value) {
      var i, totalItems = targetArray.length, objFound = false;
      for (i = 0; i < totalItems; i++) {
          if (targetArray[i][objProperty] === value) {
              objFound = true;
              return i;
      if (objFound === false) {
          return -1;

   * inject a list of 3 players into the page as a radio button group
  function showNextPlayerList() {
    var radio,
      frag = document.createDocumentFragment(),
    // clear player list div
    player_list.innerHTML = '';
    // make sure count doesn't exceed number of players
    if (playerCount > 0) {
      if ((playerCount - nextPlayerStart) < 3) {
        iMax = playerCount - nextPlayerStart;
      } else {
        iMax = nextPlayerStart + 3;
    } else {
      iMax = nextPlayerStart + 3;
    for (i = nextPlayerStart; i < iMax; i++) {
      // create the elements, add to doc fragment
      radio = document.createElement('input');
      radio.setAttribute('type', 'radio');
      radio.setAttribute('name', 'playerList');
      radio.setAttribute('value', players[i].id);
      radio.setAttribute('id', players[i].id);
      label = document.createElement('label');
      label.setAttribute('for', players[i].id);
      label.textContent = ' ' + players[i].name;
      br = document.createElement('br');
    // inject fragment
    // set the next starting count
    nextPlayerStart = nextPlayerStart + 3;
    // note that because getElementsByName gets a dynamic collection,
    // the new elements are automatically added to it
    iMax = radioGroup.length;
    // set event listeners on the new set of radio buttons
    for (i = 0; i < iMax; i++) {
      radioGroup[i].addEventListener('change', function() {
        var playerId = getRadioValue(radioGroup);

   * show some details of a player
   * @param {String} playerId the player id
  function showPlayerDetails(playerId) {
    var frag = document.createDocumentFragment(),
      // find the player object in the array
      index = findObjectInArray(players, 'id', playerId),
      player = players[index],
      p = document.createElement('p'),
      iFrame = document.createElement('iframe');
    p.textContent = 'Name: ' + player.name;
    // in case the player URL is http, change to https so browser security won't block the request
    iFrame.setAttribute('src', player.url.replace('http:', 'https:'));
    // clear the current player details before adding new ones
    player_details.innerHTML = '';

   * 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/doc-samples-proxy-v2.php',
      baseURL = 'https://players.api.brightcove.com/v1/accounts/',
    // the proxy alreay has credentials for the default Brightcove Learning account
    // so no need to send them
    if (client_id_input.value.length > 0 && client_secret_input.value.length > 0) {
      options.client_id     = client_id_input.value;
      options.client_secret = client_secret_input.value;

    options.account_id = (account_id_input.value.length > 0) ? account_id_input.value : account_id;
    options.proxyURL = proxyURL;

    switch (type) {
        case 'getPlayers':
          endpoint            = '/' + options.account_id + '/players';
          options.url         = baseURL + endpoint;
          options.requestType = 'GET';
          makeRequest(options, function(response) {
              responseDecoded = JSON.parse(response);
              // save the players array
              players = responseDecoded.items;
              // save the total player count
              playerCount = responseDecoded.item_count;
              api_response.textContent = JSON.stringify(responseDecoded, null, 2);
              // show the first 3 players - note that the API request
              // returns them in ascending order by date created,
              // so if you wanted to show the newest players first
              // you would start with the last item instead of the first

        // 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) {
             // any response status code in the 200 range indicates success
             if (httpRequest.status >= 200 && httpRequest.status < 300) {
               response = httpRequest.responseText;
               // 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

})(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.