feat(mobile,pwa): implement responsive viewport, mobile drawer and pwa support
Deploy Development / deploy (push) Successful in 20s
Deploy Development / deploy (push) Successful in 20s
This commit is contained in:
1 parent
83177f31f8
commit
5c99ce6f22
11 files changed
+367
-12
No files matched your search
@@ -133,8 +133,83 @@ class KarateMediaHooks {
|
||||
public static function onBeforePageDisplay( $out, $skin ): void {
|
||||
$out->addModules( [ 'ext.karateMedia' ] );
|
||||
|
||||
// Wichtig fuer moderne Smartphone- & Tablet-Darstellung
|
||||
$out->addMeta( 'viewport', 'width=device-width, initial-scale=1.0' );
|
||||
// 1. Skin als responsive kennzeichnen, damit MediaWiki den Standard-Viewport (width=device-width)
|
||||
// akzeptiert und das veraltete Desktop-width=1120 unterlaesst:
|
||||
try {
|
||||
$skinRefl = new \ReflectionClass( $skin );
|
||||
if ( $skinRefl->hasProperty( 'options' ) ) {
|
||||
$optProp = $skinRefl->getProperty( 'options' );
|
||||
$optProp->setAccessible( true );
|
||||
$opts = $optProp->getValue( $skin ) ?: [];
|
||||
$opts['responsive'] = true;
|
||||
$optProp->setValue( $skin, $opts );
|
||||
}
|
||||
} catch ( \Throwable $e ) {
|
||||
$bindSkin = \Closure::bind( function () {
|
||||
$this->options['responsive'] = true;
|
||||
}, $skin, $skin );
|
||||
if ( $bindSkin ) {
|
||||
$bindSkin();
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Etwaige alte oder doppelte Viewport-Tags (insbesondere width=1120) aus mMetatags entfernen
|
||||
try {
|
||||
$outRefl = new \ReflectionClass( $out );
|
||||
if ( $outRefl->hasProperty( 'mMetatags' ) ) {
|
||||
$metaProp = $outRefl->getProperty( 'mMetatags' );
|
||||
$metaProp->setAccessible( true );
|
||||
$tags = $metaProp->getValue( $out ) ?: [];
|
||||
$cleaned = [];
|
||||
foreach ( $tags as $t ) {
|
||||
if ( isset( $t[0] ) && strtolower( $t[0] ) === 'viewport' ) {
|
||||
continue;
|
||||
}
|
||||
$cleaned[] = $t;
|
||||
}
|
||||
$metaProp->setValue( $out, $cleaned );
|
||||
}
|
||||
} catch ( \Throwable $e ) {
|
||||
$bindOut = \Closure::bind( function () {
|
||||
$this->mMetatags = array_values( array_filter(
|
||||
$this->mMetatags,
|
||||
static fn( $t ) => !( isset( $t[0] ) && strtolower( $t[0] ) === 'viewport' )
|
||||
) );
|
||||
}, $out, $out );
|
||||
if ( $bindOut ) {
|
||||
$bindOut();
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Garantierter, fluessiger mobiler Viewport fuer alle Smartphones & Tablets
|
||||
$out->addMeta( 'viewport', 'width=device-width, initial-scale=1.0, maximum-scale=5.0' );
|
||||
|
||||
// 4. PWA Web App Manifest, App-Icons & Mobile-Fullscreen-Metatags
|
||||
$pwaHead = implode( "\n", [
|
||||
'<link rel="manifest" href="/manifest.webmanifest">',
|
||||
'<link rel="icon" type="image/svg+xml" href="/resources/assets/icon.svg">',
|
||||
'<link rel="apple-touch-icon" href="/resources/assets/icon.svg">',
|
||||
'<meta name="theme-color" content="#1a1a1a">',
|
||||
'<meta name="apple-mobile-web-app-capable" content="yes">',
|
||||
'<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">',
|
||||
'<meta name="apple-mobile-web-app-title" content="Karate-Wiki">',
|
||||
'<meta name="mobile-web-app-capable" content="yes">'
|
||||
] );
|
||||
$out->addHeadItem( 'karate-pwa-meta', $pwaHead );
|
||||
|
||||
// 5. Client-seitige Absicherung: Falls die Skin nachtraeglich noch width=1120 einfuegt,
|
||||
// wird dies sofort beim Head-Parsing entfernt, bevor der Browser skaliert:
|
||||
$inlineGuard = '<script>(function(){' .
|
||||
'var metas=document.querySelectorAll(\'meta[name="viewport"]\');' .
|
||||
'if(metas.length>1){' .
|
||||
'for(var i=0;i<metas.length;i++){' .
|
||||
'if((metas[i].getAttribute(\'content\')||\'\').indexOf(\'1120\')!==-1){' .
|
||||
'metas[i].remove();' .
|
||||
'}' .
|
||||
'}' .
|
||||
'}' .
|
||||
'})();</script>';
|
||||
$out->addHeadItem( 'karate-viewport-guard', $inlineGuard );
|
||||
|
||||
$title = $out->getTitle();
|
||||
$user = $out->getUser();
|
||||
|
||||
Reference in new issue
Block a user