( function( mw, $ ) {"use strict";

// Class defined in resources/class/class.js
mw.KBasePlugin = Class.extend({
	asyncInit: false,
	init: function( embedPlayer, callback, pluginName ){

		// Save to local scope
		this.embedPlayer = embedPlayer;
		this.initCompleteCallback = callback;
		this.pluginName = pluginName;

		this.bindPostFix = '.' + pluginName;

		this.setDefaults();

		var safeEnviornment = this.isSafeEnviornment();
		var _this = this;
		//if( pluginName === 'playbackRateSelector' ) debugger;
		// Check if jQuery Deferrer
		if( typeof safeEnviornment == 'object' && safeEnviornment.promise ){
			safeEnviornment.done(function(isSafe){
				if( !isSafe ){
					_this.destroy();
				}
			});
		} else if( typeof safeEnviornment == 'boolean' && ! safeEnviornment ) {
			this.initCompleteCallback();
			return false;
		}

		// Add onConfigChange binding
		this.bindConfigChangeEvent();
		
		// Call plugin setup method
		this.setup();

		// Run initCompleteCallback
		if( this.asyncInit === false ) {
			this.initCompleteCallback();
		}

		return this;
	},
	setDefaults: function( obj ){
		obj = obj || this.defaultConfig;
		var _this = this;
		// Set default configuration for the plugin
		if( $.isPlainObject(obj) ) {
			$.each( obj, function( key, value ) {
				if( _this.getConfig( key ) === undefined ) {
					_this.setConfig( key, value, true );	
				}
			});
		}
	},
	isSafeEnviornment: function(){
		return true;
	},
	setup: function() {},
	getPlayer: function() {
		return this.embedPlayer;
	},
	getConfig: function( attr, raw ) {
		if( raw ){
			return this.embedPlayer.getRawKalturaConfig( this.pluginName, attr );
		}
		return this.embedPlayer.getKalturaConfig( this.pluginName, attr );
	},
	setConfig: function( attr, value, quiet ) {
		this.embedPlayer.setKalturaConfig( this.pluginName, attr, value, quiet );
	},
	getTemplateHTML: function( data ){
		// Setup empty object
		data = data || {};
		// Add out plugin instance
		data.self = this;
		data.player = this.embedPlayer;

		// First get template from 'template' config
		var rawHTML = this.getConfig( 'template', true );
		if( !rawHTML ){
			var templatePath = this.getConfig( 'templatePath' );
			if( !templatePath || !window.JST[ templatePath ]) {
				this.log('getTemplateHTML:: Template not found');
				return '';
			}
			rawHTML = window.JST[ templatePath ];
		}
		var transformedHTML = mw.util.tmpl( rawHTML, data );
		return this.embedPlayer.evaluate( transformedHTML );
	},
	bind: function( eventName, callback ){
		var bindEventsString = '',
			events = eventName.split(" "),
			totalEvents = events.length,
			i = 0,
			space = ' ';

		for( i; i<totalEvents; i++ ){
			if( i == (totalEvents-1) ){
				space = '';
			}
			bindEventsString += events[ i ] + this.bindPostFix + space;
		}
		return this.embedPlayer.bindHelper( bindEventsString, callback);
	},
	unbind: function( eventName ){
		eventName += this.bindPostFix;
		return this.embedPlayer.unbindHelper( eventName );
	},
	log: function( msg ){
		mw.log( this.pluginName + '::' + msg );
	},
	bindConfigChangeEvent: function(){
		var _this = this;
		if( typeof this.onConfigChange !== 'function' ){
			return ;
		}
		this.bind('Kaltura_ConfigChanged', function(event, pluginName, property, value){
			if( pluginName === _this.pluginName ){
				_this.onConfigChange( property, value );
			}
		});
	},
	getKalturaClient: function() {
		if( ! this.kClient ) {
			this.kClient = mw.kApiGetPartnerClient( this.embedPlayer.kwidgetid );
		}
		return this.kClient;
	},
	destroy: function(){
		this.unbind();
	}
});

} )( window.mw, window.jQuery );
@@ -449,65 +449,8 @@
 is;%0A
-%09%09//if( pluginName === 'playbackRateSelector' ) debugger;
 %0A%09%09/
@@ -1813,16 +1813,36 @@
 data )%7B%0A
+%09%09var _this = this;%0A
 %09%09// Set
@@ -1857,16 +1857,16 @@
  object%0A
-
 %09%09data =
@@ -2362,30 +2362,51 @@
 , data );%0A%09%09
-return
+var evaluatedHTML = $.trim(
  this.embedP
@@ -2438,21 +2438,597 @@
 edHTML )
-;%0A%09%7D,
+ );%0A%09%09var $templateHtml = $( '%3Cspan%3E' + evaluatedHTML + '%3C/span%3E' );%0A%0A%09%09$templateHtml%0A%09%09%09.find('%5Bdata-click%5D,%5Bdata-notification%5D')%0A%09%09%09.click(function(e)%7B%0A%09%09%09%09var data = $(this).data();%0A%09%09%09%09return _this.handleClick( e, data );%0A%09%09%09%7D);%0A%0A%09%09return $templateHtml;%0A%09%7D,%0A%09handleClick: function( e, data )%7B%0A%0A%09%09e.preventDefault();%0A%0A%09%09// Trigger local callback for data-click property%0A%09%09if( data.click && $.isFunction(this%5Bdata.click%5D) )%7B%0A%09%09%09this%5Bdata.click%5D( e, data );%0A%09%09%7D%0A%0A%09%09if( data.notification )%7B%0A%09%09%09this.getPlayer().sendNotification( data.notification, data );%0A%09%09%7D%0A%0A%09%09return false;%0A%09%7D,%09
 %0A%09bind: 

Support for data-notification and data-click attributes in templates