Prevent leaving in case of vote started or comment written but not submitted
This commit is contained in:
parent
80336b431e
commit
d819327c61
@ -21,6 +21,8 @@ var form;
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
// Flag for onbeforeunload event
|
||||
var isSubmittingVote = false;
|
||||
|
||||
/**
|
||||
* Save a list of polls inside LocalStorage
|
||||
@ -88,6 +90,8 @@ $(document).ready(function () {
|
||||
$('html, body').animate({
|
||||
scrollTop: messageContainer.offset().top
|
||||
}, 750);
|
||||
} else {
|
||||
isSubmittingVote = true;
|
||||
}
|
||||
});
|
||||
|
||||
@ -172,6 +176,7 @@ $(document).ready(function () {
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Disable view public results option when there's a password and the poll is not hidden
|
||||
*/
|
||||
@ -182,6 +187,17 @@ $(document).ready(function () {
|
||||
$('#resultsPubliclyVisible').attr('disabled','disabled');
|
||||
}
|
||||
});
|
||||
|
||||
$(window).on('beforeunload', function(e) {
|
||||
var name = $('#name').val().trim();
|
||||
var comment = $('#comment').val().trim();
|
||||
|
||||
if ((!isSubmittingVote && name.length > 0) || comment.length > 0) {
|
||||
var confirmationMessage = $('#preventLeaving').text();
|
||||
e.returnValue = confirmationMessage;
|
||||
return confirmationMessage;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
@ -133,6 +133,7 @@
|
||||
"Failed to save poll": "Failed to save poll",
|
||||
"Forbidden!": "Forbidden!",
|
||||
"Identifier is already used": "Identifier is already used",
|
||||
"If you quit now, your changes will be lost.": "If you quit now, your changes will be lost.",
|
||||
"JavaScript is disabled on your browser. It is required to create a poll.": "JavaScript is disabled on your browser. It is required to create a poll.",
|
||||
"Missing values": "Missing values",
|
||||
"No polls found": "No polls found",
|
||||
|
@ -133,6 +133,7 @@
|
||||
"Failed to save poll": "Échec de la sauvegarde du sondage",
|
||||
"Forbidden!": "Interdit !",
|
||||
"Identifier is already used": "L'identifiant est déjà utilisé",
|
||||
"If you quit now, your changes will be lost.": "Si vous quittez maintenant, vos modifications seront perdues.",
|
||||
"JavaScript is disabled on your browser. It is required to create a poll.": "JavaScript est désactivé sur votre navigateur. Son activation est requise pour la création d'un sondage.",
|
||||
"Missing values": "Il manque des valeurs",
|
||||
"No polls found": "Aucun sondage n'a été trouvé",
|
||||
|
@ -23,3 +23,4 @@
|
||||
<div id="nameErrorMessage" class="hidden alert alert-dismissible alert-danger hidden-print" role="alert">{__('Error', 'The name is invalid.')}<button type="button" class="close" data-dismiss="alert" aria-label="{__('Generic', 'Close')}"><span aria-hidden="true">×</span></button></div>
|
||||
<div id="genericErrorTemplate" class="hidden alert alert-dismissible alert-danger hidden-print" role="alert"><span class="contents"></span><button type="button" class="close" data-dismiss="alert" aria-label="{__('Generic', 'Close')}"><span aria-hidden="true">×</span></button></div>
|
||||
<div id="genericUnclosableSuccessTemplate" class="hidden alert alert-success hidden-print" role="alert"><span class="contents"></span></div>
|
||||
<div id="preventLeaving" class="hidden hidden-print" aria-hidden="true">{__('Error', 'If you quit now, your changes will be lost.')}</div>
|
Loading…
Reference in New Issue
Block a user