Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

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.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                  <video-js id="myPlayerID"
    data-video-id="5831706803001"
    data-account="1752604059001"
    data-player="default"
    data-embed="default"
    data-application-id
    controls></video-js>
  <script src="//players.brightcove.net/1752604059001/default_default/index.min.js"></script>
              
            
!

CSS

              
                /* * The body style is just for the
 * background color of the codepen.
 * Do not include in your code.
 */
body {
  background-color: #111;
  color: #fff;
  margin-top: 4em;

}
/*
 * Styles essential to the sample
 * are below
 */
.video-js {
  height: 344px;
  width: 610px;
  margin: 0 auto;
}

.wrap {
  border: 5px solid;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 10px;
  text-align: center;
}

.theFormInput {
  border-radius: 8px;
  color: #000099;
}

.theForm {
  margin-top: 15px;
  padding: 5px;
  color: #000099;
}

              
            
!

JS

              
                let myPlayer,
  passwordToMatch = "",
  myModal;

videojs.getPlayer("myPlayerID").ready(function() {
  let options = {},
    formButton,
    passwordInput,
    // Create div which will hold content for ModalDialog
    newElement = document.createElement("div"),
    // Get a ModalDialog object
    ModalDialog = videojs.getComponent("ModalDialog");
  myPlayer = this;
  myPlayer.muted(true);

  // +++ Display ModalDialog if password in video's custom field +++
  // Wait for loadstart so password can be read from custom field
  myPlayer.one("loadstart", function() {
    passwordToMatch = myPlayer.mediainfo.customFields["password"];

    // If there is no password, play video
    if (passwordToMatch === undefined) {
      myPlayer.play();
      // If there is a password, build content and display ModalDialog
    } else {
      //Create a div in which to place HTML content
      newElement.setAttribute(
        "style",
        "display:flex;justify-content:center;align-items:center;"
      );

      // Create content for ModalDialog
      newElement.innerHTML =
        '<div class="wrap"><h2 class="title">Enter password</h2><br><input class="theFormInput" type="password" id="passwordInputID"><br><input id="formButtonID" class="theForm" type="submit" value="Log In"></div>';

      // Be sure user cannot close ModalDialog, set content
      options.uncloseable = true;
      options.content = newElement;

      // Create a specific ModalDialog and display it
      myModal = new ModalDialog(myPlayer, options);
      myPlayer.addChild(myModal);
      myModal.open();

      // +++ Add event listeners to check password +++
      // Add an event listener to the button
      formButton = newElement.querySelector("#formButtonID");
      myPlayer.on(formButton, "click", closeModal);

      // Add event listener if user presses Enter key after entering password
      passwordInput = newElement.querySelector("#passwordInputID");
      myPlayer.on(passwordInput, "keydown", function(event) {
        if (event.keyCode === 13) {
          closeModal();
        }
      });
    }
  });
});

// +++ Check entered password against saved password and act accordingly +++
function closeModal() {
  let userInputPassword = document.getElementById("passwordInputID").value;
  // If passwords match close ModalDialog and play video
  if (userInputPassword == passwordToMatch) {
    myModal.close();
    myPlayer.play();
    // If passwords do not match display dialog indicating so
  } else {
    window.alert("Sorry, password is incorrect. Try again.");
  }
}

              
            
!
999px

Console