From 0cca95c684afd77124d9ff19d3c6c92ba764f676 Mon Sep 17 00:00:00 2001 From: anazaryan Date: Thu, 28 Nov 2024 19:18:51 +0400 Subject: [PATCH] keep selected tab after page refresh --- resources/views/info_company_new.blade.php | 40 +++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/resources/views/info_company_new.blade.php b/resources/views/info_company_new.blade.php index 3ac9375..07d84cd 100644 --- a/resources/views/info_company_new.blade.php +++ b/resources/views/info_company_new.blade.php @@ -58,10 +58,8 @@ }); $("#list_button").on('click', function () { - $('#flot').removeClass('active'); - $('#flot_list').removeClass('showed'); - $('#vacancy').addClass('active'); - $('#vacancy_list').addClass('showed'); + activateTab('vacancy'); + history.pushState({}, '', '#vacancy'); }) $(document).on('click', '#send_message_to_employer', function() { @@ -72,6 +70,40 @@ $('#worker_to_user_id').val(this_.attr('data-tuid')); $('#worker_vacancy').val(this_.attr('data-vacancy')); }); + + function activateTab(tab) { + if (tab === 'vacancy') { + document.getElementById('flot').classList.remove('active'); + document.getElementById('flot_list').classList.remove('showed'); + document.getElementById('vacancy').classList.add('active'); + document.getElementById('vacancy_list').classList.add('showed'); + } else { + document.getElementById('vacancy').classList.remove('active'); + document.getElementById('vacancy_list').classList.remove('showed'); + document.getElementById('flot').classList.add('active'); + document.getElementById('flot_list').classList.add('showed'); + } + } + + document.addEventListener('DOMContentLoaded', function () { + const hash = window.location.hash; + if (hash === '#vacancy') { + activateTab('vacancy'); + } else { + activateTab('flot'); + } + + document.getElementById('flot').addEventListener('click', function () { + activateTab('flot'); + history.pushState({}, '', '#flot'); + }); + + document.getElementById('vacancy').addEventListener('click', function () { + activateTab('vacancy'); + history.pushState({}, '', '#vacancy'); + }); + + }); @include('js.favorite-vacancy-45') -- 1.7.10.4