UI - Sometimes the DOM wasnt ready when tab selection triggered via CSS, which displayed empty tabs on some browsers

pull/2973/head
dgtlmoon 2025-02-17 22:15:01 +01:00 zatwierdzone przez GitHub
rodzic ad08219d03
commit 4d5535d72c
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
3 zmienionych plików z 60 dodań i 53 usunięć

Wyświetl plik

@ -1,48 +1,66 @@
// Rewrite this is a plugin.. is all this JS really 'worth it?' (function ($) {
$.fn.hashTabs = function (options) {
var settings = $.extend({
tabContainer: ".tabs ul",
tabSelector: "li a",
tabContent: ".tab-pane-inner",
activeClass: "active",
errorClass: ".messages .error",
bodyClassToggle: "full-width"
}, options);
window.addEventListener('hashchange', function () { var $tabs = $(settings.tabContainer).find(settings.tabSelector);
var tabs = document.getElementsByClassName('active');
while (tabs[0]) {
tabs[0].classList.remove('active');
document.body.classList.remove('full-width');
}
set_active_tab();
}, false);
var has_errors = document.querySelectorAll(".messages .error"); function setActiveTab() {
if (!has_errors.length) { var hash = window.location.hash;
if (document.location.hash == "") { var $activeTab = $tabs.filter("[href='" + hash + "']");
location.replace(document.querySelector(".tabs ul li:first-child a").hash);
} else {
set_active_tab();
}
} else {
focus_error_tab();
}
function set_active_tab() { // Remove active class from all tabs
document.body.classList.remove('full-width'); $(settings.tabContainer).find("li").removeClass(settings.activeClass);
var tab = document.querySelectorAll("a[href='" + location.hash + "']");
if (tab.length) {
tab[0].parentElement.className = "active";
}
} // Add active class to selected tab
if ($activeTab.length) {
$activeTab.parent().addClass(settings.activeClass);
}
function focus_error_tab() { // Show the correct content
// time to use jquery or vuejs really, $(settings.tabContent).hide();
// activate the tab with the error if (hash) {
var tabs = document.querySelectorAll('.tabs li a'), i; $(hash).show();
for (i = 0; i < tabs.length; ++i) { }
var tab_name = tabs[i].hash.replace('#', '');
var pane_errors = document.querySelectorAll('#' + tab_name + ' .error')
if (pane_errors.length) {
document.location.hash = '#' + tab_name;
return true;
} }
}
return false; function focusErrorTab() {
} $tabs.each(function () {
var tabName = this.hash.replace("#", "");
if ($("#" + tabName).find(settings.errorClass).length) {
window.location.hash = "#" + tabName;
return false; // Stop loop on first error tab
}
});
}
function initializeTabs() {
if ($(settings.errorClass).length) {
focusErrorTab();
} else if (!window.location.hash) {
window.location.replace($tabs.first().attr("href"));
} else {
setActiveTab();
}
}
// Listen for hash changes
$(window).on("hashchange", setActiveTab);
// Initialize on page load
initializeTabs();
return this; // Enable jQuery chaining
};
})(jQuery);
$(document).ready(function () {
$(".tabs").hashTabs();
});

Wyświetl plik

@ -945,15 +945,7 @@ $form-edge-padding: 20px;
} }
.tab-pane-inner { .tab-pane-inner {
display: none;
&:not(:target) {
display: none;
}
&:target {
display: block;
}
// doesnt need padding because theres another row of buttons/activity // doesnt need padding because theres another row of buttons/activity
padding: 0px; padding: 0px;
} }

Wyświetl plik

@ -1159,11 +1159,8 @@ textarea::placeholder {
border-radius: 5px; } border-radius: 5px; }
.tab-pane-inner { .tab-pane-inner {
display: none;
padding: 0px; } padding: 0px; }
.tab-pane-inner:not(:target) {
display: none; }
.tab-pane-inner:target {
display: block; }
.beta-logo { .beta-logo {
height: 50px; height: 50px;