<commit_before>/**
* Supports the display of kaltura VAST ads.
*/
( function( mw, $ ) {"use strict";


mw.KAdPlayer = function( embedPlayer ) {
	// Create the KAdPlayer
	return this.init( embedPlayer );
};

mw.KAdPlayer.prototype = {

	// Ad tracking postFix:
	trackingBindPostfix: '.AdTracking',

	// The local interval for monitoring ad playback:
	adMonitorInterval: null,

	// Local interval for control bar timers
	adTimersInterval: null,

	// Ad tracking flag:
	adTrackingFlag: false,

	// The click binding:
	adClickPostFix :'.adClick',

	// General postFix binding
	displayPostFix: '.displayKAd',

	init: function( embedPlayer ){
		this.embedPlayer = embedPlayer;
	},

	/**
	 * Display a given adSlot
	 * once done issues the "displayDoneCallback"
	 *
	 * @param {Object}
	 *          adSlot AdadSlot object
	 * @param {function}
	 *          displayDoneCallback The callback function called once the display
	 *          request has been completed
	 * @param {=number}
	 * 			displayDuration optional time to display the insert useful
	 * 			ads that don't have an inherent duration.
	 */
	display: function( adSlot, displayDoneCallback, displayDuration ) {
		var _this = this;
		mw.log("KAdPlayer::display:" + adSlot.type + ' ads:' +  adSlot.ads.length );
		
		_this.embedPlayer.controlBuilder.removePlayerTouchBindings();

		// Setup some configuration for done state:
		adSlot.doneFunctions = [];

		adSlot.playbackDone = function(){
			mw.log("KAdPlayer:: display: adSlot.playbackDone" );
			// remove click binding if present
			$( _this.embedPlayer ).unbind( 'click' + _this.adClickPostFix );
			// stop any ad tracking:
			_this.stopAdTracking();
			// Remove notice if present:
			$('#' + _this.embedPlayer.id + '_ad_notice' ).remove();
			// Remove skip button if present:
			$('#' + _this.embedPlayer.id + '_ad_skipBtn' ).remove();

			adSlot.adsCount++;
			//last ad in ad sequence
			if (adSlot.adsCount == adSlot.ads.length)
			{
			    // remove the ad play button ( so that it can be updated with content play button ) 
			    if( _this.embedPlayer.isImagePlayScreen() ){
				    _this.embedPlayer.getInterface().find( '.play-btn-large' ).remove()
			    }
			
			    // if a preroll rewind to start:
			    if( adSlot.type == 'preroll' ){
				     _this.embedPlayer.setCurrentTime( .01);
			    }

			    // Restore overlay if hidden:
			    if( $( '#' + _this.getOverlayId() ).length ){
				    $( '#' + _this.getOverlayId() ).show();
			    }

			    // remove the video sibling ( used for ad playback )
			    _this.restoreEmbedPlayer();
			
			    _this.embedPlayer.controlBuilder.addPlayerTouchBindings();
			    
			    while( adSlot.doneFunctions.length ){
				    adSlot.doneFunctions.shift()();
			    }
			    adSlot.currentlyDisplayed = false;
			    // give time for the end event to clear
			    setTimeout(function(){
				    if( displayDoneCallback ){
					    displayDoneCallback();
				    }
			    }, 0);  
			}
			//display next ad in sequence
			else {
			   _this.playNextAd(adSlot);
			}
			    
		};
		
		// If the current ad type is already being displayed don't do anything
		if( adSlot.currentlyDisplayed === true ){
			adSlot.playbackDone();
			return ;
		}

		// Check that there are ads to display:
		if (!adSlot.ads || adSlot.ads.length == 0 ){
			adSlot.playbackDone();
			return;
		}
		//start ad counter to identify when we finished playing all ads in sequence
		adSlot.adsCount = 0;
		adSlot.displayDuration = displayDuration;
		this.playNextAd(adSlot);
	},
	/**
	 * Plays next ad in the adSlot, according to the adsCount position<commit_msg>vast3 ad pods: sort by sequence attribute<commit_after>/**
* Supports the display of kaltura VAST ads.
*/
( function( mw, $ ) {"use strict";


mw.KAdPlayer = function( embedPlayer ) {
	// Create the KAdPlayer
	return this.init( embedPlayer );
};

mw.KAdPlayer.prototype = {

	// Ad tracking postFix:
	trackingBindPostfix: '.AdTracking',

	// The local interval for monitoring ad playback:
	adMonitorInterval: null,

	// Local interval for control bar timers
	adTimersInterval: null,

	// Ad tracking flag:
	adTrackingFlag: false,

	// The click binding:
	adClickPostFix :'.adClick',

	// General postFix binding
	displayPostFix: '.displayKAd',

	init: function( embedPlayer ){
		this.embedPlayer = embedPlayer;
	},

	/**
	 * Display a given adSlot
	 * once done issues the "displayDoneCallback"
	 *
	 * @param {Object}
	 *          adSlot AdadSlot object
	 * @param {function}
	 *          displayDoneCallback The callback function called once the display
	 *          request has been completed
	 * @param {=number}
	 * 			displayDuration optional time to display the insert useful
	 * 			ads that don't have an inherent duration.
	 */
	display: function( adSlot, displayDoneCallback, displayDuration ) {
		var _this = this;
		mw.log("KAdPlayer::display:" + adSlot.type + ' ads:' +  adSlot.ads.length );
		
		_this.embedPlayer.controlBuilder.removePlayerTouchBindings();

		// Setup some configuration for done state:
		adSlot.doneFunctions = [];

		adSlot.playbackDone = function(){
			mw.log("KAdPlayer:: display: adSlot.playbackDone" );
			// remove click binding if present
			$( _this.embedPlayer ).unbind( 'click' + _this.adClickPostFix );
			// stop any ad tracking:
			_this.stopAdTracking();
			// Remove notice if present:
			$('#' + _this.embedPlayer.id + '_ad_notice' ).remove();
			// Remove skip button if present:
			$('#' + _this.embedPlayer.id + '_ad_skipBtn' ).remove();

			adSlot.adsCount++;
			//last ad in ad sequence
			if (adSlot.adsCount == adSlot.ads.length)
			{
			    // remove the ad play button ( so that it can be updated with content play button ) 
			    if( _this.embedPlayer.isImagePlayScreen() ){
				    _this.embedPlayer.getInterface().find( '.play-btn-large' ).remove()
			    }
			
			    // if a preroll rewind to start:
			    if( adSlot.type == 'preroll' ){
				     _this.embedPlayer.setCurrentTime( .01);
			    }

			    // Restore overlay if hidden:
			    if( $( '#' + _this.getOverlayId() ).length ){
				    $( '#' + _this.getOverlayId() ).show();
			    }

			    // remove the video sibling ( used for ad playback )
			    _this.restoreEmbedPlayer();
			
			    _this.embedPlayer.controlBuilder.addPlayerTouchBindings();
			    
			    while( adSlot.doneFunctions.length ){
				    adSlot.doneFunctions.shift()();
			    }
			    adSlot.currentlyDisplayed = false;
			    // give time for the end event to clear
			    setTimeout(function(){
				    if( displayDoneCallback ){
					    displayDoneCallback();
				    }
			    }, 0);  
			}
			//display next ad in sequence
			else {
			   _this.playNextAd(adSlot);
			}
			    
		};
		
		// If the current ad type is already being displayed don't do anything
		if( adSlot.currentlyDisplayed === true ){
			adSlot.playbackDone();
			return ;
		}

		// Check that there are ads to display:
		if (!adSlot.ads || adSlot.ads.length == 0 ){
			adSlot.playbackDone();
			return;
		}
		//sort ads by "sequence" attribute
		adSlot.ads = adSlot.ads.sort ( function (a,b){
		    if (!a.hasOwnProperty("sequence"))
			return 1;
		    if (!b.hasOwnProperty("sequence"))
			return -1;
		    return a.sequence - b.sequence;
		});
		//start ad counter to identify when we finished playing all ads in sequence
		adSlot.adsCount = 0;
		adSlot.displayDuration = displayDuration;
		this.playNextAd(adSlot);
	},
	/**
	 * Plays next ad in the adSlot, according to the adsCount position
{'fraction_non_alphanumeric': 0.12053033346725593, 'fraction_numerical': 0.0017409937056381412, 'mean_word_length': 2.771717171717172, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3624499', 'n_tokens_mistral': 2644, 'n_tokens_neox': 2209, 'n_words': 637}