<commit_before>/**
* Supports the parsing of ads
*/
( function( mw, $ ) { "use strict"; 
//Global mw.addKAd manager
mw.addKalturaAds = function( embedPlayer, callback ) {
	embedPlayer.kAds = new mw.KAds( embedPlayer, callback );
};

mw.sendBeaconUrl = function( beaconUrl ){
	$('body').append( 
		$( '<img />' ).attr({
			'src' : beaconUrl,
			'width' : 0,
			'height' : 0
		})
	);
};

mw.KAds = function( embedPlayer, callback) {
	// Create a Player Manager
	return this.init( embedPlayer, callback );
};

mw.KAds.prototype = {
	// The ad types 
	namedAdTimelineTypes : [ 'preroll', 'postroll', 'midroll', 'overlay' ],
	// Ad attribute map 
	adAttributeMap: {
		"Interval": 'frequency',
		"StartAt": 'start'
	},
	displayedCuePoints: [],

	bindPostfix: '.KAds',
	
	init: function( embedPlayer, callback ){
		var _this = this; 
		// Inherit BaseAdPlugin
		mw.inherit( this, new mw.BaseAdPlugin( embedPlayer, callback ) );
		
		_this.embedPlayer = embedPlayer;
		
		// Setup the ad player: 
		_this.adPlayer = new mw.KAdPlayer( embedPlayer );
		
		$( embedPlayer ).bind( 'onChangeMedia' + _this.bindPostfix, function(){
			_this.destroy();
		});
		// Clear any existing bindings: 
		_this.destroy();
		
		// Setup local pointer: 
		var $uiConf = embedPlayer.$uiConf;
		this.$notice = $uiConf.find( 'label#noticeMessage' );
		this.$skipBtn = $uiConf.find( 'button#skipBtn' );

		// Load the Ads from uiConf
		_this.loadAds( function(){
			mw.log( "KAds::All ads have been loaded" );
			callback();
		});
		
		// We can add this binding here, because we will always have vast in the uiConf when having cue points
		// Catch Ads from adOpportunity event
		if( embedPlayer.getKalturaConfig('vast', 'trackCuePoints') === true ) {
			$( embedPlayer ).bind('KalturaSupport_AdOpportunity' + _this.bindPostfix, function( event, cuePointWrapper ) {
				// Check for  protocolType == 1 ( type = vast )
				if( cuePointWrapper.cuePoint.protocolType == 1 ){
					_this.loadAndDisplayAd( cuePointWrapper );
				}
			});

			$( embedPlayer ).bind('midSequenceComplete' + _this.bindPostfix, function() {
				embedPlayer.play();
			});
		}
	},
	
	/**
	 * Get ad config
	 * @param name
	 * @return
	 */
	getConfig: function( name ){
		var _this = this;
		if( ! this.config ){
			// Build out the selection of kAds
			var configSet = [ 'preSequence', 'postSequence', 'htmlCompanions' , 'flashCompanions', 'timeout' ];
			$.each( this.namedAdTimelineTypes, function( inx, adType ){
				$.each( _this.adAttributeMap, function( adAttributeName,  displayConfName ){
					// Add all the ad types to the config set: 
					configSet.push( adType + adAttributeName);
				});
				// Add the ad type Url
				configSet.push( adType + 'Url');
			});
			
			this.config = this.embedPlayer.getKalturaConfig( 'vast', configSet );
		}
		return this.config[ name ];
	},
	/**
	 * load and display an ad
	 * cuePointWrapper
	 */
	loadAndDisplayAd: function( cuePointWrapper ) {
		var _this = this;
		var embedPlayer = this.embedPlayer;
		var cuePoint = cuePointWrapper.cuePoint;
		var adType = this.embedPlayer.kCuePoints.getAdSlotType( cuePointWrapper );
		var adDuration = Math.round( cuePoint.duration / 1000);
		
		// Check if cue point already displayed
		if( $.inArray( cuePoint.id, _this.displayedCuePoints) >= 0 ) {
			return ;
		}
		// Add cuePoint Id to displayed cuePoints array
		_this.displayedCuePoints.push( cuePoint.id );

		// Trigger midSequenceStart event (TODO: should moved to AdTimeline)
		$( embedPlayer ).trigger('midSequenceStart');
		
		mw.log('kAds::loadAndDisplayAd:: load ' + adType + ', duration: ' + adDuration, cuePoint);

		// Load adTimeline
		if (!_this.embedPlayer.adTimeline) {
			_this.embedPlayer.adTimeline = new mw.AdTimeline( _this.embedPlayer );
		}

		// Check for empty ad:
		if( !cuePoint.sourceUrl || $.trim( cuePoint.sourceUrl ) === '' ) {
			return ;
		}
		
		// If ad type is midroll pause the video
		if( cuePoint.adType == 1 ) {
			_this.embedPlayer.pauseLoading();
		}
		
		mw.AdLoader.load( cuePoint.sourceUrl, function( adConf ){
			if( ! adConf ){
				// Resume content playback
				setTimeout( function() { 
					_this.embedPlayer.play();
				}, 1);
				return ;
			}
<commit_msg>disable play controls while loading the vast ad xml <commit_after>/**
* Supports the parsing of ads
*/
( function( mw, $ ) { "use strict"; 
//Global mw.addKAd manager
mw.addKalturaAds = function( embedPlayer, callback ) {
	embedPlayer.kAds = new mw.KAds( embedPlayer, callback );
};

mw.sendBeaconUrl = function( beaconUrl ){
	$('body').append( 
		$( '<img />' ).attr({
			'src' : beaconUrl,
			'width' : 0,
			'height' : 0
		})
	);
};

mw.KAds = function( embedPlayer, callback) {
	// Create a Player Manager
	return this.init( embedPlayer, callback );
};

mw.KAds.prototype = {
	// The ad types 
	namedAdTimelineTypes : [ 'preroll', 'postroll', 'midroll', 'overlay' ],
	// Ad attribute map 
	adAttributeMap: {
		"Interval": 'frequency',
		"StartAt": 'start'
	},
	displayedCuePoints: [],

	bindPostfix: '.KAds',
	
	init: function( embedPlayer, callback ){
		var _this = this; 
		// Inherit BaseAdPlugin
		mw.inherit( this, new mw.BaseAdPlugin( embedPlayer, callback ) );
		
		_this.embedPlayer = embedPlayer;
		
		// Setup the ad player: 
		_this.adPlayer = new mw.KAdPlayer( embedPlayer );
		
		$( embedPlayer ).bind( 'onChangeMedia' + _this.bindPostfix, function(){
			_this.destroy();
		});
		// Clear any existing bindings: 
		_this.destroy();
		
		// Setup local pointer: 
		var $uiConf = embedPlayer.$uiConf;
		this.$notice = $uiConf.find( 'label#noticeMessage' );
		this.$skipBtn = $uiConf.find( 'button#skipBtn' );

		// Load the Ads from uiConf
		_this.loadAds( function(){
			mw.log( "KAds::All ads have been loaded" );
			callback();
		});
		
		// We can add this binding here, because we will always have vast in the uiConf when having cue points
		// Catch Ads from adOpportunity event
		if( embedPlayer.getKalturaConfig('vast', 'trackCuePoints') === true ) {
			$( embedPlayer ).bind('KalturaSupport_AdOpportunity' + _this.bindPostfix, function( event, cuePointWrapper ) {
				// Check for  protocolType == 1 ( type = vast )
				if( cuePointWrapper.cuePoint.protocolType == 1 ){
					_this.loadAndDisplayAd( cuePointWrapper );
				}
			});

			$( embedPlayer ).bind('midSequenceComplete' + _this.bindPostfix, function() {
				embedPlayer.play();
			});
		}
	},
	
	/**
	 * Get ad config
	 * @param name
	 * @return
	 */
	getConfig: function( name ){
		var _this = this;
		if( ! this.config ){
			// Build out the selection of kAds
			var configSet = [ 'preSequence', 'postSequence', 'htmlCompanions' , 'flashCompanions', 'timeout' ];
			$.each( this.namedAdTimelineTypes, function( inx, adType ){
				$.each( _this.adAttributeMap, function( adAttributeName,  displayConfName ){
					// Add all the ad types to the config set: 
					configSet.push( adType + adAttributeName);
				});
				// Add the ad type Url
				configSet.push( adType + 'Url');
			});
			
			this.config = this.embedPlayer.getKalturaConfig( 'vast', configSet );
		}
		return this.config[ name ];
	},
	/**
	 * load and display an ad
	 * cuePointWrapper
	 */
	loadAndDisplayAd: function( cuePointWrapper ) {
		var _this = this;
		var embedPlayer = this.embedPlayer;
		var cuePoint = cuePointWrapper.cuePoint;
		var adType = this.embedPlayer.kCuePoints.getAdSlotType( cuePointWrapper );
		var adDuration = Math.round( cuePoint.duration / 1000);
		
		// Check if cue point already displayed
		if( $.inArray( cuePoint.id, _this.displayedCuePoints) >= 0 ) {
			return ;
		}
		// Add cuePoint Id to displayed cuePoints array
		_this.displayedCuePoints.push( cuePoint.id );

		// Trigger midSequenceStart event (TODO: should moved to AdTimeline)
		$( embedPlayer ).trigger('midSequenceStart');
		
		mw.log('kAds::loadAndDisplayAd:: load ' + adType + ', duration: ' + adDuration, cuePoint);

		// Load adTimeline
		if (!_this.embedPlayer.adTimeline) {
			_this.embedPlayer.adTimeline = new mw.AdTimeline( _this.embedPlayer );
		}

		// Check for empty ad:
		if( !cuePoint.sourceUrl || $.trim( cuePoint.sourceUrl ) === '' ) {
			return ;
		}
		
		// If ad type is midroll pause the video
		if( cuePoint.adType == 1 ) {
			_this.embedPlayer.pauseLoading();
		}
		
		// Disable play controls while loading the ad: 
		_this.embedPlayer.disablePlayControls();
		
		mw.AdLoader.load( cuePoint.sourceUrl, function( adConf ){
			if( ! adConf ){
				// Ad skip re-enable play controls: 
				_this.embedPlayer.enablePlayControls();
				
				// Resume content playback
				setTimeout( function() { 
					_this.embedPlayer.play();
				}, 1);
				return ;
			}

{'fraction_non_alphanumeric': 0.13980740225084118, 'fraction_numerical': 0.002552500290056851, 'mean_word_length': 3.3078460769615194, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, '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': '3497599', 'n_tokens_mistral': 3320, 'n_tokens_neox': 2787, 'n_words': 721}