Return to previous tab (Content & Settings)

- Return to previously active tab after deleting content
- Return to previously active tab after saving settings
This commit is contained in:
Guillaume 2019-01-26 23:12:31 +01:00 committed by GitHub
parent b245ac0028
commit 1e2d279e6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 17 deletions

View File

@ -71,4 +71,4 @@ try {
} }
// Title of the page // Title of the page
$layout['title'] .= ' - '.$L->g('Edit content').' - '.$page->title(); $layout['title'] .= ' - '.$L->g('Edit content').' - '.$page->title();

View File

@ -20,7 +20,7 @@ checkRole(array('admin'));
if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($_SERVER['REQUEST_METHOD'] == 'POST') {
editSettings($_POST); editSettings($_POST);
Redirect::page('settings'); Redirect::page('settings'.$_POST['hash']);
} }
// ============================================================================ // ============================================================================

View File

@ -166,7 +166,7 @@ function table($type) {
?> ?>
<!-- TABS --> <!-- TABS -->
<ul class="nav nav-tabs" role="tablist"> <ul class="nav nav-tabs" role="tablist" onclick="hash=event.target.hash">
<li class="nav-item"> <li class="nav-item">
<a class="nav-link active" id="pages-tab" data-toggle="tab" href="#pages" role="tab"><?php $L->p('Pages') ?></a> <a class="nav-link active" id="pages-tab" data-toggle="tab" href="#pages" role="tab"><?php $L->p('Pages') ?></a>
</li> </li>
@ -279,15 +279,17 @@ $(document).ready(function() {
'type': 'hidden', 'type': 'hidden',
'name': 'type', 'name': 'type',
'value': 'delete' 'value': 'delete'
})))); }).append(jQuery('<input>', {
'type': 'hidden',
'name': 'hash',
'value': hash
})))));
form.hide().appendTo("body").submit(); form.hide().appendTo("body").submit();
}); });
});
</script>
<script>
// Open the tab defined in the URL // Open the tab defined in the URL
const anchor = window.location.hash; $('a[href="'+ window.location.hash +'"]').tab('show');
$(`a[href="${anchor}"]`).tab('show'); window.scrollTo(0);
});
</script> </script>

View File

@ -12,7 +12,7 @@
<!-- TABS --> <!-- TABS -->
<nav class="mb-3"> <nav class="mb-3">
<div class="nav nav-tabs" id="nav-tab" role="tablist"> <div class="nav nav-tabs" id="nav-tab" role="tablist" onclick="document.getElementById('jshash').value=event.target.hash">
<a class="nav-item nav-link active" id="nav-general-tab" data-toggle="tab" href="#general" role="tab" aria-controls="nav-general" aria-selected="false"><?php $L->p('General') ?></a> <a class="nav-item nav-link active" id="nav-general-tab" data-toggle="tab" href="#general" role="tab" aria-controls="nav-general" aria-selected="false"><?php $L->p('General') ?></a>
<a class="nav-item nav-link" id="nav-advanced-tab" data-toggle="tab" href="#advanced" role="tab" aria-controls="nav-advanced" aria-selected="false"><?php $L->p('Advanced') ?></a> <a class="nav-item nav-link" id="nav-advanced-tab" data-toggle="tab" href="#advanced" role="tab" aria-controls="nav-advanced" aria-selected="false"><?php $L->p('Advanced') ?></a>
<a class="nav-item nav-link" id="nav-seo-tab" data-toggle="tab" href="#seo" role="tab" aria-controls="nav-seo" aria-selected="false"><?php $L->p('SEO') ?></a> <a class="nav-item nav-link" id="nav-seo-tab" data-toggle="tab" href="#seo" role="tab" aria-controls="nav-seo" aria-selected="false"><?php $L->p('SEO') ?></a>
@ -41,6 +41,12 @@
'name'=>'pageNotFound', 'name'=>'pageNotFound',
'value'=>$site->pageNotFound() 'value'=>$site->pageNotFound()
)); ));
// Current tab
echo Bootstrap::formInputHidden(array(
'name'=>'hash',
'value'=>'#general'
));
?> ?>
<!-- General tab --> <!-- General tab -->
@ -345,6 +351,9 @@
} }
}); });
// Open the tab defined in the URL
$('a[href="'+ window.location.hash +'"]').tab('show');
window.scrollTo(0);
}); });
</script> </script>
@ -536,10 +545,4 @@
</script> </script>
</div> </div>
<?php echo Bootstrap::formClose(); ?> <?php echo Bootstrap::formClose(); ?>
<script>
// Open the tab defined in the URL
const anchor = window.location.hash;
$(`a[href="${anchor}"]`).tab('show');
</script>