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