HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
/**
* Consrtructor for the strategy. This is what gets passed to the SDK via:
* window['_cbv_strategies'].push(DMStrategy);
* @param {Object} player A pointer to the player being tracked. The player
* is where all the video data is derived from
*/
function DMStrategy(player) {
this._player = player;
this._videoId = undefined;
this._videoTitle = undefined;
this._videoUrl = undefined;
this._videoDuration = undefined;
this._thumbnailUrl = undefined;
this._currentTime = undefined;
this._currentTimeInterval = undefined;
this._autostart = undefined
this._apiReady = false;
this._contentType = DMStrategy.ContentType.CONTENT;
this._videoState = DMStrategy.VideoState.UNPLAYED;
this._viewStartTime = new Date().getTime();
this._AdPosition = undefined;
this._subscribeEvents();
}
/**
* Subscribes to message bus events.
* @private
*/
DMStrategy.prototype._subscribeEvents = function() {
// api is already ready when state is available for NPE
this._player.getState().then(function(state){
this._fetchDataVideo(state);
this._autostart = this._player.getSettings().autostart === "off" ? false : true;
this._apiReady = true;
}.bind(this));
/**
* Ad events
*/
this._player.on(dailymotion.events.AD_START, (function(){
this._contentType = DMStrategy.ContentType.AD;
}).bind(this));
this._player.on(dailymotion.events.AD_PLAY, (function(){
this._contentType = DMStrategy.ContentType.AD;
this._videoState = DMStrategy.VideoState.PLAYED;
}).bind(this));
this._player.on(dailymotion.events.AD_TIMECHANGE, (function(){
this._contentType = DMStrategy.ContentType.AD;
this._videoState = state.playerIsPlaying ? DMStrategy.VideoState.PLAYED : DMStrategy.VideoState.STOPPED;
}).bind(this));
this._player.on(dailymotion.events.AD_PAUSE, (function(){
this._contentType = DMStrategy.ContentType.AD;
this._videoState = DMStrategy.VideoState.STOPPED;
}).bind(this));
this._player.on(dailymotion.events.AD_END, (function(){
this._contentType = DMStrategy.ContentType.AD;
this._videoState = DMStrategy.VideoState.COMPLETED;
}).bind(this));
/**
* Video events
*/
this._player.on(dailymotion.events.VIDEO_START, (function(){
this._contentType = DMStrategy.ContentType.CONTENT;
}).bind(this));
this._player.on(dailymotion.events.VIDEO_PLAY, (function(){
this._contentType = DMStrategy.ContentType.CONTENT;
this._videoState = DMStrategy.VideoState.PLAYED;
}).bind(this));
this._player.on(dailymotion.events.VIDEO_PAUSE, (function(){
this._contentType = DMStrategy.ContentType.CONTENT;
this._videoState = DMStrategy.VideoState.STOPPED;
}).bind(this));
this._player.on(dailymotion.events.VIDEO_END, (function(){
this._contentType = DMStrategy.ContentType.CONTENT;
this._videoState = DMStrategy.VideoState.COMPLETED;
}).bind(this));
/**
* Player events
*/
this._player.on(dailymotion.events.PLAYER_VIDEOCHANGE, (function(state){
this._videoState = DMStrategy.VideoState.UNPLAYED;
this._fetchDataVideo(state);
}).bind(this));
};
/**
* fill Metadata of the video
* @param {Object} state An Object containing video information
* @private
*/
DMStrategy.prototype._fetchDataVideo = function(state) {
this._videoId = state.videoId;
this._saveFirstVideoId(state.id);
// if this the first video so checking if private video id present
if(this._firstVideoMap & this._firstVideoMap[this._videoId]){
this._videoId = this._firstVideoMap[this._videoId];
}
this._videoTitle = state.videoTitle;
this._videoDuration = state.videoDuration;
this._thumbnailUrl = 'https://www.dailymotion.com/thumbnail/video/' + this._videoId;
this._videoUrl = 'https://www.dailymotion.com/video/' + this._videoId;
clearInterval(this._currentTimeInterval);
this._currentTimeInterval = setInterval(function(){
this._player.getState().then(function(state){
this._currentTime = state.videoTime || 0;
}.bind(this));
}.bind(this),500);
};
/**
* Save first time video id
* in order to capture kid if first time video is private one
* @param {string} player_dom_id html id
* @private
*/
DMStrategy.prototype._saveFirstVideoId = function(player_dom_id) {
// only first time excute
if(!this._callThiis){
let videoId =
(
new URL(
document.getElementById(player_dom_id).querySelector("iframe").src
)
).searchParams.get("video");
if( videoId ){
this._firstVideoMap = {
[this._videoId] : videoId
}
}
}
this._callThiis = true;
}
/**
* This represents an abbreviated name for your custom player strategy.
*/
DMStrategy.prototype.getStrategyName = function() {
return 'DMS';
};
/**
* Enum for the content type. One of these values should be returned from
* the "getContentType" function.
* @enum {string}
*/
DMStrategy.ContentType = {
AD: 'ad',
CONTENT: 'ct'
};
/**
* Enum for the ad position. One of these values should be returned from
* the "getAdPosition" function.
* @enum {string}
*/
DMStrategy.AdPosition = {
PREROLL: 'a1',
MIDROLL: 'a2',
POSTROLL: 'a3',
OVERLAY: 'a4',
SPECIAL: 'a5'
};
/**
* Enum for the video state. One of these values should be returned from
* the "getState" function.
* @enum {string}
*/
DMStrategy.VideoState = {
UNPLAYED: 's1',
PLAYED: 's2',
STOPPED: 's3',
COMPLETED: 's4'
};
/**
* Enum for the video play type. One of these values should be returned from
* the "getAutoplayType" function.
* @enum {string}
*/
DMStrategy.AutoplayType = {
UNKNOWN: 'unkn',
MANUAL: 'man',
AUTOPLAY: 'auto',
CONTINUOUS: 'cont'
};
/**
* Indicates if the video strategy is ready for pinging.
* Typically this is called when all path and title metadata
* is available
* Note: Pings should only be sent after this reads true.
* @return {boolean} The ready state of the strategy.
*/
DMStrategy.prototype.isReady = function() {
return this._apiReady;
};
/**
* Gets the human readable video title.
* This is returned in the i key of the ping.
* @return {string} The video title.
*/
DMStrategy.prototype.getTitle = function() {
return this._videoTitle || '';
};
/**
* Gets the video path.
* This is returned in the p key of the ping.
* Note: this should be the playable video path if available.
* @return {string} The video path.
*/
DMStrategy.prototype.getVideoPath = function() {
return this._videoUrl || '';
};
/**
* Gets the total duration of the video.
* This is returned in the _vd key of the ping.
* @return {number} The total duration time in milliseconds.
*/
DMStrategy.prototype.getTotalDuration = function() {
return parseInt(this._videoDuration * 1000) || 0;
};
/**
* Gets the current state of the video. Returns value from the VideoState enum.
* This is returned in the _vs key of the ping.
* @return {string} The current video state. {@link DMStrategy.VideoState}
*/
DMStrategy.prototype.getState = function() {
return this._videoState;
};
/**
* Gets the current play time of the video (where the playhead is).
* This is returned in the _vpt key of the ping.
* @return {number} The current play time in milliseconds.
*/
DMStrategy.prototype.getCurrentPlayTime = function() {
return parseInt(this._currentTime * 1000) || 0;
};
/**
* Gets the thumbnail of the video.
* This is returned in the _vtn key of the ping.
* @return {string} The [absolute] path to the thumbnail.
*/
DMStrategy.prototype.getThumbnailPath = function() {
return this._thumbnailUrl || '';
};
/**
* Gets the Autoplay type of the video.
*
* @return {DMStrategy.AutoplayType} The type of
*/
DMStrategy.prototype.getAutoplayType = function() {
return this._autostart ?
DMStrategy.AutoplayType.AUTOPLAY :
DMStrategy.AutoplayType.MANUAL;
};
/**
* Gets the time since start of viewing.
* This is returned in the _vvs key of the ping.
* @return {number} The time since viewing started in milliseconds.
*/
DMStrategy.prototype.getViewStartTime = function() {
return (new Date().getTime() - this._viewStartTime) || 0;
};
/**
* Gets the type of video playing. Returns value from the ContentType enum.
* This is returned in the _vt key of the ping.
* @return {DMStrategy.ContentType} The type of content (ad or ct).
*/
DMStrategy.prototype.getContentType = function() {
return this._contentType;
};
/**
* Gets the ad position.
* @return {StrategyInterface.AdPosition|string} The ad position
* from a1 (pre-roll), a2 (mid-roll), a3 (post-roll),
* a4 (overlay), or a5 (special).
*/
DMStrategy.prototype.getAdPosition = function() {
return '';
};
/**
* Verifies that the given player belongs to this strategy. Used for a
* greedy search of the matching strategy for a given element or object.
* @param {Object} player A pointer to the player being tracked.
* @return {boolean} If the strategy can handle this type of object.
*/
DMStrategy.verify = function(player) {
return typeof player['play'] == 'function';
};
Also see: Tab Triggers