mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2026-07-12 06:32:23 +02:00
Added rudimentary logic to detect changes and notify the user before leaving the page.
Added URL redirect for normal/expert switcher
This commit is contained in:
@@ -79,11 +79,14 @@
|
||||
<a></a>
|
||||
</div>
|
||||
<script>
|
||||
$("#admin-mode-toggle input[type=radio][checked]").each(
|
||||
function() {
|
||||
$("#admin-mode-toggle input[name=mode-switch]").on('change', function(e){
|
||||
var value = $(this).val();
|
||||
|
||||
}
|
||||
);
|
||||
// little timeout to show off the animation
|
||||
setTimeout(function(){
|
||||
window.location.href = '{{ uri.route(true) }}' + ((value == 'expert') ? '/expert:1' : '');
|
||||
}, 200)
|
||||
});
|
||||
</script>
|
||||
{# {% if not uri.param('expert') %}
|
||||
<span class="button" >Normal</span>
|
||||
@@ -138,6 +141,35 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var getState = function(){
|
||||
var loadValues = [];
|
||||
$('input, select, textarea').each(function(index, element){
|
||||
var name = $(element).prop('name'),
|
||||
value = $(element).val();
|
||||
|
||||
if (name) loadValues.push(name + '|' + value);
|
||||
});
|
||||
|
||||
return loadValues.toString();
|
||||
};
|
||||
|
||||
$(function(){
|
||||
var currentValues = getState();
|
||||
|
||||
$(window).on('beforeunload', function(){
|
||||
if (currentValues != getState()){
|
||||
setTimeout(function() {
|
||||
setTimeout(function() {
|
||||
$('input[name=mode-switch][checked]').prop('checked', true);
|
||||
}, 10);
|
||||
},1);
|
||||
return "You have made changes on this page that you have not yet confirmed. If you navigate away from this page you will lose your unsaved changes";
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="remodal" data-remodal-id="modal" data-remodal-options="hashTracking: false">
|
||||
{% include 'partials/blueprints-new.html.twig' with { blueprints: admin.blueprints('page'), data: context } %}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user