تقدم الآن
الهيئة الملكية للجبيل وينبع
- الجهة
- الهيئة الملكية للجبيل وينبع
- نوع التوظيف
- دوام كامل
- آخر موعد
- 2026-12-09 1448/06/29
التقديم على الوظيفة
الرابط يفتح صفحة هذه الوظيفة على بوّابة الجهة نفسها.
تفاصيل الوظيفة
').insertAfter(tabsContainer)
: $('#noResultsMsg');
filterMenu.addClass('hide');
// ---------------------- Dropdown toggle ----------------------
filterBtn.on('click', function(e) {
e.stopPropagation();
filterMenu.toggleClass('hide');
});
$(document).on('click', function(e) {
if (!$(e.target).closest('#filterMenu, #filterDropdown').length) {
filterMenu.addClass('hide');
}
});
// ---------------------- Tabs click (Store state explicitly) ----------------------
$('#faq-tabs-list li').on('click', function(e) {
e.preventDefault();
if ($(this).is(':visible')) {
// ACTION: Store the clicked tab's ID as the active state
tabsContainer.data('active-tab-id', $(this).attr('id'));
applyFilters();
}
});
// ---------------------- Apply filters (Dropdown Button) ----------------------
$('.apply-filters').on('click', function() {
var selectedDropdownValue = tabSelect.val();
// **CRITICAL FIX:** When the user clicks Apply Filters,
// if they haven't explicitly chosen a category from the dropdown,
// we DO NOT overwrite the active-tab-id. We only overwrite it
// if they select a specific category or "All."
if (selectedDropdownValue && selectedDropdownValue !== 'select_one' && selectedDropdownValue !== 'all') {
// Case 1: Specific category chosen from dropdown. Override the active tab.
tabsContainer.data('active-tab-id', selectedDropdownValue);
} else if (selectedDropdownValue === 'all') {
// Case 2: 'All' chosen from dropdown. Reset to the default tab.
tabsContainer.data('active-tab-id', 'tab_rcjy_00');
}
// Case 3 (Sorting): If selectedDropdownValue is 'select_one' (default/no change),
// we leave the existing active-tab-id, which is what preserves the current tab!
applyFilters();
filterMenu.addClass('hide');
});
// ---------------------- Clear filters ----------------------
$('.clear-filters').on('click', function() {
orderSelect.val('select_one');
tabSelect.val('select_one');
searchInput.val('');
clearBtn.hide();
tabsContainer.data('active-tab-id', 'tab_rcjy_00');
applyFilters();
filterMenu.addClass('hide');
});
// ---------------------- Live search ----------------------
searchInput.on('input', function() {
clearBtn.toggle($(this).val().trim().length > 0);
clearTimeout($.data(this, 'timer'));
$(this).data('timer', setTimeout(function() {
applyFilters();
}, 300));
});
clearBtn.on('click', function() {
searchInput.val('');
clearBtn.hide();
applyFilters();
});
// ---------------------- Main dynamic filter function ----------------------
function applyFilters() {
var searchTerm = searchInput.val().toLowerCase().trim();
var selectedTab = tabSelect.val();
var order = orderSelect.val();
var totalVisibleQuestions = 0;
var dropdownTabFilterActive = selectedTab && selectedTab !== 'select_one' && selectedTab !== 'all';
// SOURCE OF TRUTH: Get the stored active tab ID. THIS IS THE KEY TO PRESERVATION.
var activeTabId = tabsContainer.data('active-tab-id') || 'tab_rcjy_00';
// Reset and prepare
$('.faq-box').show();
$('#faq-tabs-list li').removeClass('on');
// ------------------ Step 1: Filter and Sort Questions ------------------
// Iterate through all content sections (tabs)
$('#faq-tabs-list li').each(function() {
var tabId = $(this).attr('id');
var contentId = tabId.replace('tab', 'content');
var contentDiv = $('#' + contentId);
var items = contentDiv.find('.faq-box');
var tabHasVisibleQuestion = false;
items.each(function() {
var itemTabId = $(this).closest('.tab-content').attr('id').replace('content', 'tab');
var q = $(this).find('h2').text().toLowerCase();
var a = $(this).find('p.question-content').text().toLowerCase();
var match = true;
// 1. Apply Dropdown category filter
if (dropdownTabFilterActive && itemTabId !== selectedTab) {
match = false;
}
// 2. Apply search filter
if (searchTerm !== '') {
match = match && (q.includes(searchTerm) || a.includes(searchTerm));
}
$(this).toggle(match);
if (match) {
tabHasVisibleQuestion = true;
totalVisibleQuestions++;
}
});
// Update tab visibility
$(this).toggle(tabHasVisibleQuestion);
// 3. Apply sorting inside content
if (order === 'asc' || order === 'desc') {
var itemsToSort = contentDiv.find('.faq-box:visible');
itemsToSort.sort(function(a, b) {
var A = $(a).find('h2').text().trim().toLowerCase();
var B = $(b).find('h2').text().trim().toLowerCase();
return (order === 'desc') ? B.localeCompare(A) : A.localeCompare(B);
});
contentDiv.append(itemsToSort);
} else {
// Restore original HTML order if no sorting is selected
contentDiv.append(items);
}
});
// ------------------ Step 2: Display Logic ------------------
if (totalVisibleQuestions > 0) {
noResultsMsg.hide();
tabsContainer.show();
$('.fancy-tabs').removeClass('border-reset');
var targetTabElement = $('#' + activeTabId);
var fallbackTab = $('#faq-tabs-list li:visible').first();
// Determine final active tab: Priority is the stored activeTabId, IF it's visible.
var finalActiveTab = (targetTabElement.length && targetTabElement.is(':visible')) ? targetTabElement : fallbackTab;
if (finalActiveTab.length) {
// CRITICAL: Force the correct tab to be active and visible.
finalActiveTab.addClass('on');
var activeContentId = finalActiveTab.attr('id').replace('tab', 'content');
// Hide ALL content sections, then show only the selected one
$('.tab-content').removeClass('display-b').addClass('hide');
$('#' + activeContentId).removeClass('hide').addClass('display-b');
// Update stored state (in case of fallback to the first visible tab)
tabsContainer.data('active-tab-id', finalActiveTab.attr('id'));
}
} else {
// No results
tabsContainer.hide();
$('.tab-content').removeClass('display-b').addClass('hide');
noResultsMsg.show();
$('.fancy-tabs').addClass('border-reset');
}
}
// ---------------------- Initial Load ----------------------
// Set 'All' tab as the default active state
tabsContainer.data('active-tab-id', 'tab_rcjy_00');
// Run filters to apply initial display
applyFilters();
});
}
هل تناسبك هذه الوظيفة فعلاً؟
أنشئ حساباً ونقارن سيرتك بهذه الوظيفة: درجة المطابقة، الكلمات الناقصة، وسبب مكتوب لكلّ ترشيح — ثم نرشّح لك الوظائف المشابهة تلقائياً.