Skip to main content

JP Controls

Standard video controls for GumGum's HTML creatives

CDN latest release:

  • //cdn.justpremium.com/Justpremium/boilerplate/js/jp-controls_0.6.2.js

CDN previous release:

  • //cdn.justpremium.com/Justpremium/boilerplate/js/jp-controls_0.6.1.js

Implementation

  • Include a script tag in the bottom of the body of your html file:
<script src="//cdn.justpremium.com/Justpremium/boilerplate/js/jp-controls_0.6.2.js"></script>
  • Wrap each video element you wish to be affected in a div with the jp-controls attribute:
<div id="video-container" jp-controls>
<video>
<source src="assets/video.mp4"></source>
</video>
</div>
note

If using jpxApi.createVideo or jp-createvideo-src, jp-controls is implemented by default.

Custom Behaviour and Appearance

  • Add values to the jp-controls attribute, for example:
<div id="video-container" jp-controls="useheight large">
<video playsinline muted poster="assets/poster.jpg">
<source src="assets/video.mp4"></source>
</video>
</div>
  • If implementing the HTML jp-createvideo-src interface, add values to jp-createvideo-controls attribute:
<div id="video-container" jp-createvideo-src="assets/video.mp4" jp-createvideo-poster="assets/poster.jpg" jp-createvideo-controls="mobileui useheight"></div>
  • If implementing jpxApi.createVideo() (the JavaScript API), the 4th argument is the jp-controls value:
var videoContainer = document.querySelector('#video-container');
var vastTag = { src: 'assets/video.mp4', poster: 'assets/poster.jpg', type: 'video/mp4' };
Premium.jpxApi.createVideo('top', videoContainer, vastTag, 'useheight large');

Here are all the values jp-controls accepts:

valueeffect
small medium largeoverrides size (see details below)
fixedset the video controls to stay fixed relative to the video
pnguse a png sprite sheet instead of the embedded svgs
useheightmake the controls adjust to the video height as its main reference, instead of the width
nofadestop the controls fading out/sliding off (so they are always visible)
noautounmutestop the video unmuting when the user clicks play
inithiddenmake the controls initiate hidden
forcefitforce the video element to fit exactly to the edge of the controls div - by default it rounds to nearest pixel
videoratio:[RATIO]override the video ratio from the video metadata with this value. This is useful for fixing issues with initial loading with useheight. The video ratio is the width/height of the video.
nopixelcentringprevent pixel positioning of the video and the controls. This can improve smoothness of resizing but means everything is centred without taking into account viewport offsets.
showfullscreenshow the full screen button in the UI (note this just shows the button, you need to use PremiumJpControls.callOnClickFullScreen(func) to implement the usual expandable overlay)
showvolumeshow a functioning volume slider in the UI
mobileuisets controls to the default 'light' version, suitable for mobile
showplayshows the play/pause button (only relevant in conjunction with mobileui)
target:'[CSS_SELECTOR]'change the target to control a video somewhere else in the DOM. Useful when displaying a canvas video within the jp-controls div
coversets video to behave like css background-size:cover, the jp-controls div must have its width and height set *

Example using videoratio:

<div id="video-container" jp-controls="videoratio:1.777">
<video playsinline muted poster="assets/poster.jpg"></video>
</div>

Example using target:

<div id="video-container" jp-controls="target:'.other-container video'">
<img class="jp-controls-poster" src="assets/poster.jpg" alt="">
<canvas width="853" height="480"></canvas>
</div>

Custom Styling

Use the following classes:

classtarget element
jp-controls-holderthe controls holder (background is the gradient)
jp-controls-playthe play button
jp-controls-pausethe pause button
jp-controls-mutethe mute button
jp-controls-unmutethe unmute button
jp-controls-replaythe replay button
jp-controls-progressbarthe inner moving progress bar
jp-controls-progressbarholderthe progress bar holder
jp-controls-spaceis used to space UI elements out. Use this instead of padding/margin
jp-controls-bigplaythe larger play button in the centre (only shown on first-play of videos large enough to display it)
jp-controls-posteradd an element with this class name to act as a poster image

API

There are 5 functions exposed in namespace PremiumJpControls:

PremiumJpControls.resizeAll()

Resizes all jp-controls videos to fit their video element. This is useful if the video is resized or animated with Javascript

PremiumJpControls.getLastAction(elementOrId)

Takes required parameter elementOrId which can be a jp-controls div or the id of a jp-controls div. It returns object {playPause:string, muteUnmute:string} to reflect the user’s last action on this jp-controls element. For example, if the user has clicked to play the video then the object will be {playPause:"play", muteUnmute:undefined} . This is useful to know if a user has initiated play or not.

PremiumJpControls.create()

Re-runs the creation of jp-controls elements. Useful for dynamically adding videos to the document.

PremiumJpControls.callOnComplete(func)

Takes required parameter func which must be a function. This function will be called when the controls are ready with the target jp-controls div as the only argument.

PremiumJpControls.callOnClickFullScreen(func)

Takes required parameter func which must be a function. This function will be called when the full screen button is clicked.

PremiumJpControls.callVideoEndedHandler(elementOrId)

Takes required parameter elementOrId which can be a jp-controls div or the id of a jp-controls div. It forces the controls to behave as if the video has just ended (showing the big replay/play button)

* only available in latest version

Sizes

To get small buttons (14x14px) add the jp-controls-small attribute to the div. To get medium buttons (18x18px) add the jp-controls-medium attribute to the div. To get large buttons (22x22px) add the jp-controls-large attribute to the div. By default, if the device is mobile or the video is over 300px wide then the large-sized buttons will be used, otherwise medium-sized buttons will be used.

Tips

  • Where possible, any styling for the video element should be applied only to the jp-controls div, not the video element directly. For best results, adjust the video size using the width and height properties, not using the transform property. After making any change to the size of the video element, call PremiumJpControls.resizeAll() to resize the jp-controls elements to fit the new video dimensions.

  • The controls will horizontally and vertically centre-align the video element within the jp-controls div. To override this, use css to set the marginTop and marginLeft of the video element, like this:

#video-container video{
margin-top:0 !important;
margin-left:0 !important;
}
  • Default styling for controls holder for your reference:
.jp-controls-holder {
position: absolute;
bottom: 0;
opacity: 0;
transform: scale(50%);
transition: opacity 0.5s;
width: 100%;
padding: 8px 8px;
background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.5));
}
  • For Internet Explorer’s wonderful quirks, please use extra-specific selectors (not just a class) for styling the jp-controls div, for example:

Tag name and class:

div.my-vid {
position: absolute;
top: 0;
right: 0;
width: 450px;
}

ID:

#my-vid {
position: absolute;
top: 0;
right: 0;
width: 450px;
}