Merge pull request #112 from ThommyH/stopInterventionCounterOnLostFocus

stop intervention timer if user lost focus to the code ocean tab
This commit is contained in:
rteusner
2017-04-06 16:42:49 +02:00
committed by GitHub

View File

@ -579,7 +579,13 @@ configureEditors: function () {
* interventions * interventions
* */ * */
initializeInterventionTimer: function() { initializeInterventionTimer: function() {
if ($('#editor').data('rfc-interventions') == true || $('#editor').data('break-interventions') == true) { // split in break or rfc intervention if ($('#editor').data('rfc-interventions') == true || $('#editor').data('break-interventions') == true) { // split in break or rfc intervention
window.onblur = function() { window.blurred = true; };
window.onfocus = function() { window.blurred = false; };
var delta = 100; // time in ms to wait for window event before time gets stopped
var tid;
$.ajax({ $.ajax({
data: { data: {
exercise_id: $('#editor').data('exercise-id'), exercise_id: $('#editor').data('exercise-id'),
@ -603,36 +609,41 @@ configureEditors: function () {
// ensure we give user at least minTimeIntervention before we bother the user // ensure we give user at least minTimeIntervention before we bother the user
var timeUntilIntervention = Math.max(percentile75 - accumulatedWorkTimeUser, minTimeIntervention); var timeUntilIntervention = Math.max(percentile75 - accumulatedWorkTimeUser, minTimeIntervention);
} }
if ($('#editor').data('break-interventions')){
setTimeout(function () { tid = setInterval(function() {
$('#break-intervention-modal').modal('show'); if ( window.blurred ) { return; }
$.ajax({ timeUntilIntervention -= delta;
data: { if ( timeUntilIntervention <= 0 ) {
intervention_type: 'BreakIntervention' clearInterval(tid);
}, // timeUntilIntervention passed
dataType: 'json', if ($('#editor').data('break-interventions')) {
type: 'POST', $('#break-intervention-modal').modal('show');
url: $('#editor').data('intervention-save-url')
});
}, timeUntilIntervention);
} else if ($('#editor').data('rfc-interventions')) {
setTimeout(function () {
var button = $('#requestComments');
// only show intervention if user did not requested for a comment already
if (!button.prop('disabled')) {
$('#rfc_intervention_text').show();
$('#comment-modal').modal('show');
$.ajax({ $.ajax({
data: { data: {
intervention_type: 'QuestionIntervention' intervention_type: 'BreakIntervention'
}, },
dataType: 'json', dataType: 'json',
type: 'POST', type: 'POST',
url: $('#editor').data('intervention-save-url') url: $('#editor').data('intervention-save-url')
}); });
}; } else if ($('#editor').data('rfc-interventions')){
}, timeUntilIntervention); var button = $('#requestComments');
} // only show intervention if user did not requested for a comment already
if (!button.prop('disabled')) {
$('#rfc_intervention_text').show();
$('#comment-modal').modal('show');
$.ajax({
data: {
intervention_type: 'QuestionIntervention'
},
dataType: 'json',
type: 'POST',
url: $('#editor').data('intervention-save-url')
});
};
}
}
}, delta);
} }
}); });
} }