<script type="text/javascript">
var editor = false;
var textlen = 0;
+ var formModified = false;
function initEditor(callback) {
if (editor == false) {
});
$(".jothidden").show();
$("#profile-jot-text").keyup(function(){
- var textlen = $(this).val().length;
+ textlen = $(this).val().length;
$('#character-counter').text(textlen);
+ formModified = true; // Mark the form as modified when the user types
});
editor = true;
function enableOnUser(){
initEditor();
}
+
+ // Warn user before leaving the page if the form is modified
+ window.addEventListener('beforeunload', function (e) {
+ if (formModified) {
+ var confirmationMessage = 'There are unsaved changes. Are you sure you want to leave this page?';
+ e.returnValue = confirmationMessage; // Gecko, Trident, Chrome 34+
+ return confirmationMessage; // Gecko, WebKit, Chrome <34
+ }
+ });
+
+ // Reset formModified flag after successful submission
+ function resetFormModifiedFlag() {
+ formModified = false;
+ }
+
</script>
<script type="text/javascript">
type: 'POST',
})
.then(function () {
- // Reset to form for jot reuse in the same page
+ // Reset the form for jot reuse in the same page
e.target.reset();
$('#jot-modal').modal('hide');
+ resetFormModifiedFlag(); // Reset formModified after successful submission
})
.always(function() {
// Reset the post_id_random to avoid duplicate post errors
}
NavUpdate();
- })
+ });
});
$('#wall-image-upload').on('click', function(){
reply = prompt("{{$vidurl}}");
if(reply && reply.length) {
addeditortext('[video]' + reply + '[/video]');
+ formModified = true; // Mark the form as modified
}
}
reply = prompt("{{$audurl}}");
if(reply && reply.length) {
addeditortext('[audio]' + reply + '[/audio]');
+ formModified = true; // Mark the form as modified
}
}
reply = prompt("{{$whereareu}}", $('#jot-location').val());
if(reply && reply.length) {
$('#jot-location').val(reply);
+ formModified = true; // Mark the form as modified
}
}
initEditor(function(){
addeditortext(data);
});
+ formModified = true; // Mark the form as modified
});
jotShow();
initEditor(function(){
addeditortext(data);
$('#profile-rotator').hide();
+ formModified = true; // Mark the form as modified
});
});
autosize.update($("#profile-jot-text"));
if(timer) clearTimeout(timer);
timer = setTimeout(NavUpdate,3000);
liking = 1;
+ formModified = true; // Mark the form as modified
}
}
}
liking = 1;
force_update = true;
$.colorbox.close();
+ formModified = true; // Mark the form as modified
} else {
$("#id_term").css("border-color","#FF0000");
}
function jotClearLocation() {
$('#jot-coord').val('');
$('#profile-nolocation-wrapper').hide();
+ formModified = true; // Mark the form as modified
}
function addeditortext(data) {
//insert the data as new value
textfield.value = currentText + data;
autosize.update($("#profile-jot-text"));
+ formModified = true; // Mark the form as modified
}
{{$geotag nofilter}}
toggleJotNav(elemMobile[0]);
}
</script>
+