Merge pull request #112 from ThommyH/stopInterventionCounterOnLostFocus
stop intervention timer if user lost focus to the code ocean tab
This commit is contained in:
@ -579,7 +579,13 @@ configureEditors: function () {
|
||||
* interventions
|
||||
* */
|
||||
initializeInterventionTimer: function() {
|
||||
|
||||
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({
|
||||
data: {
|
||||
exercise_id: $('#editor').data('exercise-id'),
|
||||
@ -603,8 +609,14 @@ configureEditors: function () {
|
||||
// ensure we give user at least minTimeIntervention before we bother the user
|
||||
var timeUntilIntervention = Math.max(percentile75 - accumulatedWorkTimeUser, minTimeIntervention);
|
||||
}
|
||||
if ($('#editor').data('break-interventions')){
|
||||
setTimeout(function () {
|
||||
|
||||
tid = setInterval(function() {
|
||||
if ( window.blurred ) { return; }
|
||||
timeUntilIntervention -= delta;
|
||||
if ( timeUntilIntervention <= 0 ) {
|
||||
clearInterval(tid);
|
||||
// timeUntilIntervention passed
|
||||
if ($('#editor').data('break-interventions')) {
|
||||
$('#break-intervention-modal').modal('show');
|
||||
$.ajax({
|
||||
data: {
|
||||
@ -614,9 +626,7 @@ configureEditors: function () {
|
||||
type: 'POST',
|
||||
url: $('#editor').data('intervention-save-url')
|
||||
});
|
||||
}, timeUntilIntervention);
|
||||
} else if ($('#editor').data('rfc-interventions')) {
|
||||
setTimeout(function () {
|
||||
} else if ($('#editor').data('rfc-interventions')){
|
||||
var button = $('#requestComments');
|
||||
// only show intervention if user did not requested for a comment already
|
||||
if (!button.prop('disabled')) {
|
||||
@ -631,9 +641,10 @@ configureEditors: function () {
|
||||
url: $('#editor').data('intervention-save-url')
|
||||
});
|
||||
};
|
||||
}, timeUntilIntervention);
|
||||
}
|
||||
}
|
||||
}, delta);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
Reference in New Issue
Block a user