jquery.courseplayer.js
;(function ($, window, document, undefined) {
'use strict';
function DECoursePlayer (element,options) {
var settings = $.extend({
userID: '',
refID: '',
courseID: '',
schoolID: '',
moduleID:'',
isReviewMode:'False',
toRootURL: '',
activityTime:0,
dashboardpath: '',
isAllowToContinueChecking: 'False',
isAllowToContinueCheckingTime:0,
CourseSessionTrackInterval:15
}, options);
var $elt = null;
var $thisPlugin = this;
var SessionCD = '';
var _CourseSessionTrackTimer = null;
var _IsAllowToContinueTimer = null;
var CourseSessionTrackPing = function(dfd){
$.ajax({
type: "GET",
url:settings.toRootURL+"wsrest/player.svc/"+settings.userID+"/"+settings.refID+"/course/"+settings.schoolID+"/"+settings.courseID+"/session-track/ping/"+SessionCD,
contentType: "application/json",
dataType: "json",
cache: false,
success: function (result){
_CourseSessionTrackTimer = setTimeout(function () { CourseSessionTrackPing(); }, settings.CourseSessionTrackInterval*1000);
return true;
},
complete: function(){
if (dfd)
dfd.resolve();
}
});
}
var CourseSessionTrackingStart = function(dfd){
SessionCD = (settings.isReviewMode=='True')?'REVIEW':'COURSE';
$.ajax({
type: "GET",
url:settings.toRootURL+"wsrest/player.svc/"+settings.userID+"/"+settings.refID+"/course/"+settings.schoolID+"/"+settings.courseID+"/session-track/start/"+SessionCD,
contentType: "application/json",
dataType: "json",
cache: false,
success: function (result){
_CourseSessionTrackTimer = setTimeout(function () { CourseSessionTrackPing(); }, settings.CourseSessionTrackInterval*1000);
return true;
},
complete: function(){
if (dfd)
dfd.resolve();
}
});
}
var CourseSessionTrackingEnd = function(dfd){
$.ajax({
type: "GET",
url:settings.toRootURL+"wsrest/player.svc/"+settings.userID+"/"+settings.refID+"/course/"+settings.schoolID+"/"+settings.courseID+"/session-track/end/"+SessionCD,
contentType: "application/json",
dataType: "json",
cache: false,
success: function (result){
clearTimeout(_CourseSessionTrackTimer);
clearTimeout(_IsAllowToContinueTimer);
return true;
},
complete: function(){
if (dfd)
dfd.resolve();
}
});
}
//Y.K. check state machine && kicked him out to Dashboard if it is locked
var GetAllowToContinue = function (dfd) {
$.ajax({
type: "GET",
url: settings.toRootURL + "wsrest/player.svc/" + settings.userID + "/" + settings.refID + "/course/" + settings.schoolID + "/" + settings.courseID + "/isallowtocontinue",
contentType: "application/json",
dataType: "json",
cache: false,
success: function (result) {
if (resul*****mmands && resul*****mmands[0].__type == 'ExitPlayerCmd') {
$('.courseplayer').block({ message: $("<img src='/forum/" + settings.toRootURL + "img/icons/loading.gif' alt='' height='32' width='32' />") });
$.when($.Deferred(function (dfd) { $('.courseplayer').DECoursePlayer('on-player-exit', dfd); }))
.then(function () {
window.location.replace(settings.dashboardpath + '?refID=' + settings.refID);
});
return false;
} else
_IsAllowToContinueTimer = setTimeout(function () { GetAllowToContinue(); }, settings.isAllowToContinueCheckingTime * 60000);
return true;
},
complete: function () {
if (dfd)
dfd.resolve();
}
});
}
this.OnPlayerExit = function(dfd){
CourseSessionTrackingEnd(dfd);
};
var ActivityTimerStart = function(){
if(settings.activityTime>0) //setup activity time on whole CoursePlayer
{
$(document).bind("idle.idleTimer", function(){
$.when($.Deferred(function(dfd){$('.courseplayer') .DECoursePlayer('on-player-exit',dfd);}))
.then(function(){
window.location.replace(settings.dashboardpath+'?r efID='+settings.refID);
});
});
$(document).bind("active.idleTimer", function(e){
//don't do nothing
});
var timemillisecond=settings.activityTime*60000;
$.idleTimer(timemillisecond);
}
}
this.OnTimerActivityStop = function(dfd){
$.idleTimer('destroy');
};
this.OnTimerActivityStart = function(dfd){
ActivityTimerStart();
};
var init = function ($e)
{
$elt = $e;
CourseSessionTrackingStart();
ActivityTimerStart();
if (settings.isAllowToContinueChecking == 'True')
_IsAllowToContinueTimer = setTimeout(function () { GetAllowToContinue(); }, settings.isAllowToContinueCheckingTime*60000);
}
//initialize plugin.
init($(element));
};
var _pluginName = 'DECoursePlayer';
$.fn[_pluginName] = function(options,args){
if (options && typeof(options) == 'string') {
switch(options){
case 'on-player-exit':
return $(this).data('pl_'+_pluginName).OnPlayerExit(args) ;
case 'on-activitytimer-stop':
return $(this).data('pl_'+_pluginName).OnTimerActivitySto p(args);
case 'on-activitytimer-start':
return $(this).data('pl_'+_pluginName).OnTimerActivitySta rt(args);
}
}
return this.each(function(){
if (! $(this).data('pl_'+_pluginName)){
$(this).data('pl_'+_pluginName, new DECoursePlayer(this,options,args));
}
});
}
//special external function fore process CoursePlayer FeedBack ajax calls with all parametrs
$.fn.SubmitFeedBack = function ($context) {
var UserMessage = '';
var ItemID = '';
var SlideID = '';
var $primaryFeedbackDropdown = $context.primaryFeedbackDropdown;
var _primaryFeedbackDropdownValue = $primaryFeedbackDropdown.find('option:selected').v al();
ItemID+=_primaryFeedbackDropdownValue;
var $secondaryFeedbackDropdown = $context.secondaryFeedbackDropdown;
var _secondaryFeedbackDropdownValue = $secondaryFeedbackDropdown.find('option:selected') .val();
ItemID+='-'+_secondaryFeedbackDropdownValue;
var $formData = $context.formData;
for (var key in $formData) {
UserMessage=$formData[key];
}
var $ItemCollections = $("#ItemsCollection");
var $numrelated=$('#ItemsCollection > li:visible');
if($numrelated.length>0) SlideID=$numrelated.data("slideid");
var eqDocData = {};
eqDocData.ID=$context.options.docID;
eqDocData.SchoolID = $context.options.schoolID;
eqDocDat*****urseID = $context.options.courseID;
eqDocData.ModuleID = $context.options.moduleID;
eqDocData.TopicID = $context.options.topicID;
eqDocDat*****urseMode = $context.options.courseMode;
eqDocData.UserMessage = UserMessage;
if(SlideID!=undefined&&SlideID!='')
{
eqDocData.SlideID=SlideID;
eqDocData.SlideSequence=$('#currslideTitle').text( );
}
eqDocData.ItemID=ItemID;
eqDocData.UserAgent = 'PLATFORM:'+navigator.platform +' OSCPU:'+navigator.oscpu+' USERAGENT:'+navigator.userAgent;
$.ajax({
type: "POST",
url: $context.options.toRootURL + 'wsrest/player.svc/' + $context.options.userID + '/' + $context.options.refID + '/feedback/submit',
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify(eqDocData),
cache: false,
success: function (result) {},
error: function () { }
});
};
})(jQuery, window, document);