Skip to content

Instantly share code, notes, and snippets.

@dmlap
Created September 25, 2014 13:58
Show Gist options
  • Save dmlap/74d0dba9e18a533ca1f9 to your computer and use it in GitHub Desktop.
Save dmlap/74d0dba9e18a533ca1f9 to your computer and use it in GitHub Desktop.
A robust Brightcove player plugin will accept all of its necessary configuration as initialization options and fall back on data attributes for defaults.
videojs.plugin('example', function(options) {
var player = this,
defaults,
settings;
// grab default configuration from data attributes
// these will be set automatically by Video Cloud but can be provided by any other video
// CMS as well
defaults = {
// player.options() is automatically populated with any data attributes declared on
// the video element
videoId: player.options()['data-video-id'],
// you can specify defaults specific to your plugin, as well
timeout: 5000
};
// mergeOptions will override parameters in the first argument with those in the second
// the properties in settings will be what was specified in the initialization options,
// if provided, and the defaults otherwise
settings = videojs.util.mergeOptions(defaults, options);
// use the final settings
doSomeStuff(settings.videoId);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment