Upload via GUI (41 Dateien)
This commit is contained in:
@@ -205,6 +205,16 @@ function statistik_manager_get_statistics() {
|
||||
// Banner an der richtigen Stelle einhängen – abhängig von der konfigurierten
|
||||
// Position. Nur wenn das Banner auch wirklich aktiviert ist.
|
||||
function statistik_manager_register_banner() {
|
||||
// Abstand oben für fixe Leisten (ShiftNav-Menüleiste usw.) wird IMMER
|
||||
// berechnet – auch ohne Banner –, sonst liegt der Seitenkopf darunter.
|
||||
add_action('wp_head', 'statistik_manager_banner_offset');
|
||||
|
||||
// Am Seitenende sofort nachrechnen – dann sind Banner und fixe Leisten
|
||||
// (z. B. ShiftNav) garantiert im DOM, auch wenn DOMContentLoaded spät kommt.
|
||||
add_action('wp_footer', function() {
|
||||
echo '<script>window.statistikManagerBannerAdjust&&window.statistikManagerBannerAdjust();</script>';
|
||||
}, 999);
|
||||
|
||||
if (!get_option('statistik_manager_banner_enabled', 1)) {
|
||||
return;
|
||||
}
|
||||
@@ -226,58 +236,47 @@ function statistik_manager_get_statistics() {
|
||||
statistik_manager_display_banner('top');
|
||||
}, 5);
|
||||
}
|
||||
|
||||
// Abstand für den Seiteninhalt, damit das fixe Banner nichts verdeckt
|
||||
add_action('wp_head', 'statistik_manager_banner_offset');
|
||||
|
||||
// Am Seitenende sofort nachrechnen – dann sind Banner und fixe Leisten
|
||||
// (z. B. ShiftNav) garantiert im DOM, auch wenn DOMContentLoaded spät kommt.
|
||||
add_action('wp_footer', function() {
|
||||
echo '<script>window.statistikManagerBannerAdjust&&window.statistikManagerBannerAdjust();</script>';
|
||||
}, 999);
|
||||
}
|
||||
add_action('wp', 'statistik_manager_register_banner');
|
||||
|
||||
// Fügt NUR bei aktivem Banner den passenden Abstand hinzu – auf der richtigen
|
||||
// Seite (oben/unten) und mit Rücksicht auf die WordPress-Admin-Leiste.
|
||||
// Sorgt dafür, dass fixe Leisten oben (ShiftNav-Menüleiste) und – falls aktiv –
|
||||
// das Banner keinen Inhalt verdecken. Die WordPress-Admin-Leiste ist per
|
||||
// html-margin bereits berücksichtigt und wird nicht doppelt gezählt.
|
||||
function statistik_manager_banner_offset() {
|
||||
if (!get_option('statistik_manager_banner_enabled', 1)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$enabled = (bool) get_option('statistik_manager_banner_enabled', 1);
|
||||
$pos = get_option('statistik_manager_banner_position', 'top');
|
||||
$h = 56; // ungefähre Bannerhöhe – nur für den No-JS-Fallback
|
||||
|
||||
// Fallback ohne JavaScript (WordPress verschiebt die Seite für die
|
||||
// Admin-Leiste bereits selbst per html-margin, daher hier nicht addieren).
|
||||
echo '<noscript><style>';
|
||||
if ($pos === 'bottom') {
|
||||
echo 'body { padding-bottom: ' . $h . 'px !important; }';
|
||||
} else {
|
||||
echo 'body { padding-top: ' . $h . 'px !important; }';
|
||||
if (is_admin_bar_showing()) {
|
||||
echo '#statistik-manager-banner { top: 32px !important; }';
|
||||
echo '@media screen and (max-width: 782px) { #statistik-manager-banner { top: 46px !important; } }';
|
||||
if ($enabled) {
|
||||
$h = 56; // ungefähre Bannerhöhe – nur für den No-JS-Fallback
|
||||
echo '<noscript><style>';
|
||||
if ($pos === 'bottom') {
|
||||
echo 'body { padding-bottom: ' . $h . 'px !important; }';
|
||||
} else {
|
||||
echo 'body { padding-top: ' . $h . 'px !important; }';
|
||||
if (is_admin_bar_showing()) {
|
||||
echo '#statistik-manager-banner { top: 32px !important; }';
|
||||
echo '@media screen and (max-width: 782px) { #statistik-manager-banner { top: 46px !important; } }';
|
||||
}
|
||||
}
|
||||
echo '</style></noscript>';
|
||||
}
|
||||
echo '</style></noscript>';
|
||||
|
||||
// Mit JavaScript: Banner exakt unter fixe Leisten oben setzen (WP-Admin-Leiste,
|
||||
// ShiftNav-Menüleiste), sonst verdecken diese es. Der Inhalt wird nur um die
|
||||
// tatsächliche Bannerhöhe verschoben – zusätzlich zum vorhandenen Abstand
|
||||
// des Themes, damit das Layout ansonsten unverändert bleibt.
|
||||
// Mit JavaScript: Unterkante der fixen Leisten oben messen, ein Top-Banner
|
||||
// direkt darunter setzen und den Inhalt um Leisten + Banner nach unten
|
||||
// schieben (zusätzlich zum vorhandenen Abstand des Themes).
|
||||
$is_bottom = ($pos === 'bottom') ? 'true' : 'false';
|
||||
echo '<script>(function(){'
|
||||
. 'var isBottom=' . $is_bottom . ';'
|
||||
. 'var bars=["wpadminbar","shiftnav-toggle-main"];'
|
||||
. 'var setTop=false,setBottom=false;'
|
||||
. 'function adjust(){'
|
||||
. 'if(!document.body){return;}'
|
||||
. 'var b=document.getElementById("statistik-manager-banner");'
|
||||
. 'if(!b){return;}'
|
||||
. 'var s=document.body.style,prop=isBottom?"padding-bottom":"padding-top";'
|
||||
. 's.removeProperty(prop);'
|
||||
. 'var base=parseFloat(getComputedStyle(document.body)[isBottom?"paddingBottom":"paddingTop"])||0;'
|
||||
. 'var extra=0;'
|
||||
. 'if(!isBottom){'
|
||||
. 'var s=document.body.style;'
|
||||
. 'if(setTop){s.removeProperty("padding-top");setTop=false;}'
|
||||
. 'if(setBottom){s.removeProperty("padding-bottom");setBottom=false;}'
|
||||
. 'var cs=getComputedStyle(document.body);'
|
||||
. 'var baseTop=parseFloat(cs.paddingTop)||0,baseBottom=parseFloat(cs.paddingBottom)||0;'
|
||||
. 'var off=0;'
|
||||
. 'bars.forEach(function(id){'
|
||||
. 'var e=document.getElementById(id);if(!e){return;}'
|
||||
@@ -286,13 +285,11 @@ function statistik_manager_get_statistics() {
|
||||
. 'var r=e.getBoundingClientRect();'
|
||||
. 'if(r.height>0&&r.bottom>off){off=r.bottom;}'
|
||||
. '});'
|
||||
. 'b.style.setProperty("top",off+"px","important");'
|
||||
// Inhalt komplett unter Leisten + Banner beginnen lassen; die Admin-Leiste
|
||||
// hat WordPress per html-margin bereits berücksichtigt.
|
||||
. 'var hm=parseFloat(getComputedStyle(document.documentElement).marginTop)||0;'
|
||||
. 'extra=Math.max(0,off-hm);'
|
||||
. '}'
|
||||
. 's.setProperty(prop,(base+extra+b.offsetHeight)+"px","important");'
|
||||
. 'var top=Math.max(0,off-hm);'
|
||||
. 'if(b&&!isBottom){b.style.setProperty("top",off+"px","important");top+=b.offsetHeight;}'
|
||||
. 'if(top>0){s.setProperty("padding-top",(baseTop+top)+"px","important");setTop=true;}'
|
||||
. 'if(b&&isBottom){s.setProperty("padding-bottom",(baseBottom+b.offsetHeight)+"px","important");setBottom=true;}'
|
||||
. '}'
|
||||
. 'window.statistikManagerBannerAdjust=adjust;'
|
||||
. 'function watch(){'
|
||||
|
||||
Reference in New Issue
Block a user