<commit_before>( function( mw, $ ) {"use strict";

mw.PluginManager.add( 'related', mw.KBaseComponent.extend({

	defaultConfig: {
		parent: "topBarContainer",
		order: 4,
		align: "right",
		//visible: false,
		itemsLimit: 12,
		displayOnPlaybackDone: true,
		autoContinueTime: null,
		templatePath: 'components/related/related.tmpl.html',
		playlistId: null,
        userSkipAutoPlay : false
	},
	$screen: null,
	setup: function(){
		var _this = this;

		this.bind('playerReady', function(){
			// Stop timer
			_this.stopTimer();

			// Reset our items data
			_this.templateData = null;

			// Load items data
			_this.getItemsData(function(){
				if( _this.$screen ){
					_this.$screen.remove();
					_this.$screen = null;
				}
			});
		});

		this.bind('onplay', function(){
			_this.hide();
		});

		if( this.getConfig('displayOnPlaybackDone') ){
			this.bind('onEndedDone', function(){
				_this.show();
 				if( _this.getConfig('autoContinueTime') &&  !_this.getConfig('userSkipAutoPlay') ){
					_this.startTimer();
				}
			});
		}

		this.bind('replayEvent', function(){
			_this.stopTimer();
		});
	},
	startTimer: function(){
		var _this = this;
		var updateTimeRemaining = function(){
			var ct = _this.getConfig('timeRemaining');
			if( ct > 0 ){
				_this.setConfig('timeRemaining', --ct);
				_this.timeRemainingMonitor = setTimeout(updateTimeRemaining, 1000);
			} else {
				_this.stopTimer();
				// Make sure we change media only if related is visible and we have next item
				if( _this.$screen && _this.getScreen().is(':visible')
					&& _this.templateData && _this.templateData.nextItem ){
					_this.changeMedia( null, {entryId: _this.templateData.nextItem.id} );
				}
			}
		};
		setTimeout(updateTimeRemaining, 1000);
	},
	pauseTimer: function(){
		// Clear our interval
		clearTimeout(this.timeRemainingMonitor);
		this.timeRemainingMonitor = null;
	},
    continueTimer: function(){
        this.startTimer();
    },
    disableByUser: function() {
        this.setConfig('userSkipAutoPlay', true);
        this.pauseTimer();
    },
    enableByUser: function(){
        this.setConfig('userSkipAutoPlay', false);
        this.continueTimer();
    },
    toggleUserAutoPlay : function(){
        if (this.getConfig('userSkipAutoPlay')){
            this.enableByUser();
        }else{
            this.disableByUser();
        }
    },
	stopTimer: function(){
		this.pauseTimer();
		// Set remaining time to auto continue time
		this.setConfig('timeRemaining', this.getConfig('autoContinueTime'));
	},
	getItemsData: function( callback ){
		if( !this.templateData ){
			var _this = this;

			// Allow other plugins to inject data
			this.getPlayer().triggerQueueCallback( 'relatedData', function( args ){
				// Get data from event
				if( args ){
					_this.templateData = args[0];
					callback();
					return ;
				}
				_this.getDataFromApi( callback );
			});					
			return;
		}
		callback();
		return;
	},
	getDataFromApi: function( callback ){
		var _this = this;
		this.getKalturaClient().doRequest( {
			'service' : 'playlist',
			'action' : 'execute',
			'id' : this.getConfig( 'playlistId' ),
			'filter:objectType': 'KalturaMediaEntryFilterForPlaylist',
			'filter:idNotIn': this.getPlayer().kentryid,
			'filter:limit': this.getConfig('itemsLimit')
		}, function( data ){
			// Check if we got error
			if( data.code && data.message ){
				_this.log('Error getting related items: ' + data.message);
				_this.getBtn().hide();
			}
			var nextItem = data.splice(0,1);
			_this.templateData = {
				nextItem: nextItem[0],
				moreItems: data
			};
			callback();
		});
	},
	changeMedia: function( e, data ){
		this.stopTimer();
		var _this = this;
		this.getPlayer().sendNotification('relatedVideoSelect', data);
		this.getPlayer().sendNotification('changeMedia', data);
		this.bind('onChangeMediaDone', function(){
			_this.getPlayer().play();
			_this.unbind('onChangeMediaDone');
		})
		this.hide();
	},
	hide: function(){
		this.opened = false;
		this.getScreen().hide();
		if( this.wasPlaying ){
			this.getPlayer().play();
			this.wasPlaying = false;
		}
		this.getPlayer().restoreComponentsHover();
	},
	show: function(){
		this.opened = true;
		this.wasPlaying = this.getPlayer().isPlaying();
		if( this.wasPlaying ) {
			this.getPlayer().pause();
		}
		this.getPlayer().disableComponentsHover();
		this.getScreen().show();
	},
	toggle: function(){
		if( this.opened ){
			this.hide();
		} else {
			this.show();
		}
	},
	onConfigChange: function( property, value ){
		if( property == 'timeRemaining' ){
			var timeFormat = mw.KDPMapping.prototype.formatFunctions.timeFormat;
			this.getScreen().find('.remaining').html(timeFormat(value));
		}
		this._super( property, value );
	},
	getScreen: function(){
		if( ! this.$screen ){
			this.$screen = $('<div />')
								.addClass( 'screen ' + this.pluginName )
								.append( 
									$('<div class="screen-content" /> ').append(
										this.getTemplateHTML( this.templateData )
									)
								)
								.hide();

			this.getPlayer().getVideoHolder().append( this.$screen );
		}
		return this.$screen;
	},
	getComponent: function() {
		if( !this.$el ) {	
			var _this = this;
			this.$el = $( '<button />' )
						.attr( 'title', 'Related' )
						.addClass( "btn icon-related" + this.getCssClass() )
						.click( function(){
							_this.toggle();
						});
			
		}
		return this.$el;
	}
}));

} )( window.mw, window.jQuery );<commit_msg>refactor - remove a function that just calls to another function<commit_after>( function( mw, $ ) {"use strict";

mw.PluginManager.add( 'related', mw.KBaseComponent.extend({

	defaultConfig: {
		parent: "topBarContainer",
		order: 4,
		align: "right",
		//visible: false,
		itemsLimit: 12,
		displayOnPlaybackDone: true,
		autoContinueTime: null,
		templatePath: 'components/related/related.tmpl.html',
		playlistId: null,
        userSkipAutoPlay : false
	},
	$screen: null,
	setup: function(){
		var _this = this;

		this.bind('playerReady', function(){
			// Stop timer
			_this.stopTimer();

			// Reset our items data
			_this.templateData = null;

			// Load items data
			_this.getItemsData(function(){
				if( _this.$screen ){
					_this.$screen.remove();
					_this.$screen = null;
				}
			});
		});

		this.bind('onplay', function(){
			_this.hide();
		});

		if( this.getConfig('displayOnPlaybackDone') ){
			this.bind('onEndedDone', function(){
				_this.show();
 				if( _this.getConfig('autoContinueTime') &&  !_this.getConfig('userSkipAutoPlay') ){
					_this.startTimer();
				}
			});
		}

		this.bind('replayEvent', function(){
			_this.stopTimer();
		});
	},
	startTimer: function(){
		var _this = this;
		var updateTimeRemaining = function(){
			var ct = _this.getConfig('timeRemaining');
			if( ct > 0 ){
				_this.setConfig('timeRemaining', --ct);
				_this.timeRemainingMonitor = setTimeout(updateTimeRemaining, 1000);
			} else {
				_this.stopTimer();
				// Make sure we change media only if related is visible and we have next item
				if( _this.$screen && _this.getScreen().is(':visible')
					&& _this.templateData && _this.templateData.nextItem ){
					_this.changeMedia( null, {entryId: _this.templateData.nextItem.id} );
				}
			}
		};
		setTimeout(updateTimeRemaining, 1000);
	},
	pauseTimer: function(){
		// Clear our interval
		clearTimeout(this.timeRemainingMonitor);
		this.timeRemainingMonitor = null;
	},
    disableByUser: function() {
        this.setConfig('userSkipAutoPlay', true);
        this.pauseTimer();
    },
    enableByUser: function(){
        this.setConfig('userSkipAutoPlay', false);
        this.startTimer();
    },
    toggleUserAutoPlay : function(){
        if (this.getConfig('userSkipAutoPlay')){
            this.enableByUser();
        }else{
            this.disableByUser();
        }
    },
	stopTimer: function(){
		this.pauseTimer();
		// Set remaining time to auto continue time
		this.setConfig('timeRemaining', this.getConfig('autoContinueTime'));
	},
	getItemsData: function( callback ){
		if( !this.templateData ){
			var _this = this;

			// Allow other plugins to inject data
			this.getPlayer().triggerQueueCallback( 'relatedData', function( args ){
				// Get data from event
				if( args ){
					_this.templateData = args[0];
					callback();
					return ;
				}
				_this.getDataFromApi( callback );
			});					
			return;
		}
		callback();
		return;
	},
	getDataFromApi: function( callback ){
		var _this = this;
		this.getKalturaClient().doRequest( {
			'service' : 'playlist',
			'action' : 'execute',
			'id' : this.getConfig( 'playlistId' ),
			'filter:objectType': 'KalturaMediaEntryFilterForPlaylist',
			'filter:idNotIn': this.getPlayer().kentryid,
			'filter:limit': this.getConfig('itemsLimit')
		}, function( data ){
			// Check if we got error
			if( data.code && data.message ){
				_this.log('Error getting related items: ' + data.message);
				_this.getBtn().hide();
			}
			var nextItem = data.splice(0,1);
			_this.templateData = {
				nextItem: nextItem[0],
				moreItems: data
			};
			callback();
		});
	},
	changeMedia: function( e, data ){
		this.stopTimer();
		var _this = this;
		this.getPlayer().sendNotification('relatedVideoSelect', data);
		this.getPlayer().sendNotification('changeMedia', data);
		this.bind('onChangeMediaDone', function(){
			_this.getPlayer().play();
			_this.unbind('onChangeMediaDone');
		})
		this.hide();
	},
	hide: function(){
		this.opened = false;
		this.getScreen().hide();
		if( this.wasPlaying ){
			this.getPlayer().play();
			this.wasPlaying = false;
		}
		this.getPlayer().restoreComponentsHover();
	},
	show: function(){
		this.opened = true;
		this.wasPlaying = this.getPlayer().isPlaying();
		if( this.wasPlaying ) {
			this.getPlayer().pause();
		}
		this.getPlayer().disableComponentsHover();
		this.getScreen().show();
	},
	toggle: function(){
		if( this.opened ){
			this.hide();
		} else {
			this.show();
		}
	},
	onConfigChange: function( property, value ){
		if( property == 'timeRemaining' ){
			var timeFormat = mw.KDPMapping.prototype.formatFunctions.timeFormat;
			this.getScreen().find('.remaining').html(timeFormat(value));
		}
		this._super( property, value );
	},
	getScreen: function(){
		if( ! this.$screen ){
			this.$screen = $('<div />')
								.addClass( 'screen ' + this.pluginName )
								.append( 
									$('<div class="screen-content" /> ').append(
										this.getTemplateHTML( this.templateData )
									)
								)
								.hide();

			this.getPlayer().getVideoHolder().append( this.$screen );
		}
		return this.$screen;
	},
	getComponent: function() {
		if( !this.$el ) {	
			var _this = this;
			this.$el = $( '<button />' )
						.attr( 'title', 'Related' )
						.addClass( "btn icon-related" + this.getCssClass() )
						.click( function(){
							_this.toggle();
						});
			
		}
		return this.$el;
	}
}));

} )( window.mw, window.jQuery );
{'fraction_non_alphanumeric': 0.1645383555351401, 'fraction_numerical': 0.0029398254478640333, 'mean_word_length': 3.1724798773476426, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '5390727', 'n_tokens_mistral': 4249, 'n_tokens_neox': 3512, 'n_words': 684}