<commit_before>(function ( mw, $ ) {
	"use strict";
	mw.dualScreen = mw.dualScreen || {};

	mw.dualScreen.imagePlayer = mw.KBaseComponent.extend({
		defaultConfig: {
			cuePointType: [{
				"main": mw.KCuePoints.TYPE.THUMB,
				"sub": [mw.KCuePoints.THUMB_SUB_TYPE.SLIDE]
			}],
			prefetch: {
				'durationPercentageUntilNextSequence': 60,
				'minimumSequenceDuration': 2
			}
		},
		cuePointsManager : null,
		cuePoints: [],
		showFirstSlideOnLoad : false,
		forcedFirstCuePoint: false,
		syncEnabled: true,
		slidesCuePointTypes : null,
		setup: function() {
			this.addBinding();

			this.initializeSlidesCuePointTypes();
		},
		initializeSlidesCuePointTypes : function()
		{
			// This function takes the filter configuration and map it to relevent structure (backward competability issues)
			var cuePointTypes = this.getConfig("cuePointType");
			var slidesCuePointTypes = [];

			if (cuePointTypes && cuePointTypes.length > 0)
			{
				$.each(cuePointTypes, function (index, cuePointType) {
					if (cuePointType.sub && cuePointType.sub.length > 0) {
						$.each(cuePointType.sub,function(sindex, subType)
						{
							slidesCuePointTypes.push({main : cuePointType.main, sub : subType});
						});
					}
				});
			}

			if (slidesCuePointTypes.length > 0)
			{
				this.slidesCuePointTypes = slidesCuePointTypes;
			}else {
				this.slidesCuePointTypes = null;
			}
		},

		initializeCuePointsManager:function()
		{
			var _this = this;

			if ((_this.getPlayer().isLive() && mw.getConfig("EmbedPlayer.LiveCuepoints")) || _this.getPlayer().kCuePoints) {
				// handle cue points only if either live or we have cue points loaded from the server
				setTimeout(function()
				{
					if (!_this.cuePointsManager) {
						_this.cuePointsManager = new mw.webcast.CuePointsManager(_this.getPlayer(), function () {
						}, "imagePlayer_CuePointsManager");

						_this.cuePointsManager.onCuePointsReached = function (args) {
							_this.cuePointsReached(args);
						};
					}
				},1000);
			}
		},
		destroyCuePointsManager:function()
		{
			if (this.cuePointsManager) {
				mw.log("imagePlayer.destroyCuePointsManager(): removing existing instance of cue points manager");
				this.cuePointsManager.destroy();
				this.cuePointsManager = null;
			}
		},
		cuePointsReached : function(context) {
			var cuePoints = context.filter({tags: ['remove-selected-thumb']});
			cuePoints = cuePoints.concat(context.filter({types: this.slidesCuePointTypes}));

			cuePoints.sort(function (a, b) {
				return (b.startTime - a.startTime);
			});

			var mostUpdatedCuePointToHandle = cuePoints.length > 0 ? cuePoints[0] : null; // since we ordered the relevant cue points descending - the first cue point is the most updated

			if (mostUpdatedCuePointToHandle) {
				this.sync(mostUpdatedCuePointToHandle)
			} else if (context.reason === 'reconstructState') {
				this.sync(null);
			}
		},
		canRender: function () {
			var cuePoints = this.getCuePoints();
			var cuePointsExist = (cuePoints.length > 0);
			return (!this.getPlayer().useNativePlayerControls() &&
				(
					( this.getPlayer().isLive() && this.getPlayer().isDvrSupported() && mw.getConfig("EmbedPlayer.LiveCuepoints") ) ||
					( !this.getPlayer().isLive() && cuePointsExist )
				)
			);
		},
		addBinding: function(){
			var _this = this;

			this.bind('KalturaSupport_ThumbCuePointsReady' , function(){
				if (_this.getPlayer().isLive()){
					//Forcing 1st slide is only on VOD entry
					return;
				}
				// on non-autoplayed player - check if required to force-show the 1st CP
				var chaptersRawData = _this.getCuePoints();
				//Since imagePlayer doesn't have a uiconf element - copy the value from dualScreen which has representation in the uiconf;
				if (_this.embedPlayer.getKalturaConfig("chapters","showFirstSlideOnLoad")){
					_this.showFirstSlideOnLoad = _this.embedPlayer.getKalturaConfig("chapters","showFirstSlideOnLoad");
				}

				if(chaptersRawData && chaptersRawData.length
					&& _this.showFirstSlideOnLoad && !_this.embedPlayer.getFlashvars().autoPlay ){
					var firstSlide = chaptersRawData[0];
					_this.sync(firstSlide);
					_this.forcedFirstCuePoint = true;
				}
			})


			if (this.getPlayer().playerReadyFlag) {
				this.initializeCuePointsManager();
			} else {
				this.bind('playerReady', function () {
					_this.initializeCuePointsManager();
				});
			}
<commit_msg>add a safety check that chapters plugin exists<commit_after>(function ( mw, $ ) {
	"use strict";
	mw.dualScreen = mw.dualScreen || {};

	mw.dualScreen.imagePlayer = mw.KBaseComponent.extend({
		defaultConfig: {
			cuePointType: [{
				"main": mw.KCuePoints.TYPE.THUMB,
				"sub": [mw.KCuePoints.THUMB_SUB_TYPE.SLIDE]
			}],
			prefetch: {
				'durationPercentageUntilNextSequence': 60,
				'minimumSequenceDuration': 2
			}
		},
		cuePointsManager : null,
		cuePoints: [],
		showFirstSlideOnLoad : false,
		forcedFirstCuePoint: false,
		syncEnabled: true,
		slidesCuePointTypes : null,
		setup: function() {
			this.addBinding();

			this.initializeSlidesCuePointTypes();
		},
		initializeSlidesCuePointTypes : function()
		{
			// This function takes the filter configuration and map it to relevent structure (backward competability issues)
			var cuePointTypes = this.getConfig("cuePointType");
			var slidesCuePointTypes = [];

			if (cuePointTypes && cuePointTypes.length > 0)
			{
				$.each(cuePointTypes, function (index, cuePointType) {
					if (cuePointType.sub && cuePointType.sub.length > 0) {
						$.each(cuePointType.sub,function(sindex, subType)
						{
							slidesCuePointTypes.push({main : cuePointType.main, sub : subType});
						});
					}
				});
			}

			if (slidesCuePointTypes.length > 0)
			{
				this.slidesCuePointTypes = slidesCuePointTypes;
			}else {
				this.slidesCuePointTypes = null;
			}
		},

		initializeCuePointsManager:function()
		{
			var _this = this;

			if ((_this.getPlayer().isLive() && mw.getConfig("EmbedPlayer.LiveCuepoints")) || _this.getPlayer().kCuePoints) {
				// handle cue points only if either live or we have cue points loaded from the server
				setTimeout(function()
				{
					if (!_this.cuePointsManager) {
						_this.cuePointsManager = new mw.webcast.CuePointsManager(_this.getPlayer(), function () {
						}, "imagePlayer_CuePointsManager");

						_this.cuePointsManager.onCuePointsReached = function (args) {
							_this.cuePointsReached(args);
						};
					}
				},1000);
			}
		},
		destroyCuePointsManager:function()
		{
			if (this.cuePointsManager) {
				mw.log("imagePlayer.destroyCuePointsManager(): removing existing instance of cue points manager");
				this.cuePointsManager.destroy();
				this.cuePointsManager = null;
			}
		},
		cuePointsReached : function(context) {
			var cuePoints = context.filter({tags: ['remove-selected-thumb']});
			cuePoints = cuePoints.concat(context.filter({types: this.slidesCuePointTypes}));

			cuePoints.sort(function (a, b) {
				return (b.startTime - a.startTime);
			});

			var mostUpdatedCuePointToHandle = cuePoints.length > 0 ? cuePoints[0] : null; // since we ordered the relevant cue points descending - the first cue point is the most updated

			if (mostUpdatedCuePointToHandle) {
				this.sync(mostUpdatedCuePointToHandle)
			} else if (context.reason === 'reconstructState') {
				this.sync(null);
			}
		},
		canRender: function () {
			var cuePoints = this.getCuePoints();
			var cuePointsExist = (cuePoints.length > 0);
			return (!this.getPlayer().useNativePlayerControls() &&
				(
					( this.getPlayer().isLive() && this.getPlayer().isDvrSupported() && mw.getConfig("EmbedPlayer.LiveCuepoints") ) ||
					( !this.getPlayer().isLive() && cuePointsExist )
				)
			);
		},
		addBinding: function(){
			var _this = this;

			this.bind('KalturaSupport_ThumbCuePointsReady' , function(){
				if (_this.getPlayer().isLive()){
					//Forcing 1st slide is only on VOD entry
					return;
				}
				// on non-autoplayed player - check if required to force-show the 1st CP
				var chaptersRawData = _this.getCuePoints();
				//Since imagePlayer doesn't have a uiconf element - copy the value from dualScreen which has representation in the uiconf;
				if (_this.embedPlayer.plugins.hasOwnProperty("chapters")
					&& _this.embedPlayer.getKalturaConfig("chapters","showFirstSlideOnLoad")){
					_this.showFirstSlideOnLoad = _this.embedPlayer.getKalturaConfig("chapters","showFirstSlideOnLoad");
				}

				if(chaptersRawData && chaptersRawData.length
					&& _this.showFirstSlideOnLoad && !_this.embedPlayer.getFlashvars().autoPlay ){
					var firstSlide = chaptersRawData[0];
					_this.sync(firstSlide);
					_this.forcedFirstCuePoint = true;
				}
			})


			if (this.getPlayer().playerReadyFlag) {
				this.initializeCuePointsManager();
			} else {
				this.bind('playerReady', function () {
					_this.initializeCuePointsManager();
				});
			}

{'fraction_non_alphanumeric': 0.1272871018748588, 'fraction_numerical': 0.0036141856787892477, 'mean_word_length': 3.650735294117647, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 13, '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': '5829453', 'n_tokens_mistral': 3559, 'n_tokens_neox': 2805, 'n_words': 538}