mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-30 18:35:44 +00:00
Vector should operate in responsive mode when the mobile skin
With MobileFrontend installed applying ?useskin=vector&useformat=mobile will ensure that responsive vector mode is invoked. I'm keen to do this, as it would help to have more examples of skins that are MobileFrontend aware as part of the work I am doing in T166748 Change-Id: I81edd855a5e96400d1179fb10907fcc30ea43ef7
This commit is contained in:
parent
ef8fc08532
commit
e53b4cf522
29
Hooks.php
Normal file
29
Hooks.php
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Hooks.php
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook handlers for Vector skin.
|
||||||
|
*
|
||||||
|
* Hook handler method names should be in the form of:
|
||||||
|
* on<HookName>()
|
||||||
|
*/
|
||||||
|
|
||||||
|
class VectorHooks {
|
||||||
|
/**
|
||||||
|
* BeforePageDisplayMobile hook handler
|
||||||
|
*
|
||||||
|
* Make Vector responsive when operating in mobile mode (useformat=mobile)
|
||||||
|
*
|
||||||
|
* @see https://www.mediawiki.org/wiki/Extension:MobileFrontend/BeforePageDisplayMobile
|
||||||
|
* @param OutputPage $out
|
||||||
|
* @param SkinTemplate $sk
|
||||||
|
*/
|
||||||
|
public static function onBeforePageDisplayMobile( OutputPage $out, $sk ) {
|
||||||
|
// This makes Vector behave in responsive mode when MobileFrontend is installed
|
||||||
|
if ( $sk instanceof SkinVector ) {
|
||||||
|
$sk->enableResponsiveMode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -34,11 +34,24 @@ class SkinVector extends SkinTemplate {
|
||||||
* @var Config
|
* @var Config
|
||||||
*/
|
*/
|
||||||
private $vectorConfig;
|
private $vectorConfig;
|
||||||
|
private $responsiveMode = false;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->vectorConfig = ConfigFactory::getDefaultInstance()->makeConfig( 'vector' );
|
$this->vectorConfig = ConfigFactory::getDefaultInstance()->makeConfig( 'vector' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables the responsive mode
|
||||||
|
*/
|
||||||
|
public function enableResponsiveMode() {
|
||||||
|
if ( !$this->responsiveMode ) {
|
||||||
|
$out = $this->getOutput();
|
||||||
|
$out->addMeta( 'viewport', 'width=device-width, initial-scale=1' );
|
||||||
|
$out->addModuleStyles( 'skins.vector.styles.responsive' );
|
||||||
|
$this->responsiveMode = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes output page and sets up skin-specific parameters
|
* Initializes output page and sets up skin-specific parameters
|
||||||
* @param OutputPage $out Object to initialize
|
* @param OutputPage $out Object to initialize
|
||||||
|
@ -47,8 +60,7 @@ class SkinVector extends SkinTemplate {
|
||||||
parent::initPage( $out );
|
parent::initPage( $out );
|
||||||
|
|
||||||
if ( $this->vectorConfig->get( 'VectorResponsive' ) ) {
|
if ( $this->vectorConfig->get( 'VectorResponsive' ) ) {
|
||||||
$out->addMeta( 'viewport', 'width=device-width, initial-scale=1' );
|
$this->enableResponsiveMode();
|
||||||
$out->addModuleStyles( 'skins.vector.styles.responsive' );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$out->addModules( 'skins.vector.js' );
|
$out->addModules( 'skins.vector.js' );
|
||||||
|
|
|
@ -25,9 +25,15 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"AutoloadClasses": {
|
"AutoloadClasses": {
|
||||||
|
"VectorHooks": "Hooks.php",
|
||||||
"SkinVector": "SkinVector.php",
|
"SkinVector": "SkinVector.php",
|
||||||
"VectorTemplate": "VectorTemplate.php"
|
"VectorTemplate": "VectorTemplate.php"
|
||||||
},
|
},
|
||||||
|
"Hooks": {
|
||||||
|
"BeforePageDisplayMobile": [
|
||||||
|
"VectorHooks::onBeforePageDisplayMobile"
|
||||||
|
]
|
||||||
|
},
|
||||||
"@note": "When modifying skins.vector.styles definition, make sure the installer still works",
|
"@note": "When modifying skins.vector.styles definition, make sure the installer still works",
|
||||||
"ResourceModules": {
|
"ResourceModules": {
|
||||||
"skins.vector.styles": {
|
"skins.vector.styles": {
|
||||||
|
|
Loading…
Reference in a new issue