protected $selectorWithVariant = '.{prefix}-{name}-{variant}';
protected $targets = [ 'desktop', 'mobile' ];
- /** @var string Position on the page to load this module at */
- protected $position = 'bottom';
-
/**
* Constructs a new module from an options array.
*
* Below is a description for the $options array:
* @par Construction options:
* @code
- * array(
+ * [
* // Base path to prepend to all local paths in $options. Defaults to $IP
* 'localBasePath' => [base path],
* // Path to JSON file that contains any of the settings below
* 'selectorWithoutVariant' => [CSS selector template, variables: {prefix} {name}],
* 'selectorWithVariant' => [CSS selector template, variables: {prefix} {name} {variant}],
* // List of variants that may be used for the image files
- * 'variants' => array(
- * [theme name] => array(
- * [variant name] => array(
+ * 'variants' => [
+ * [theme name] => [
+ * [variant name] => [
* 'color' => [color string, e.g. '#ffff00'],
* 'global' => [boolean, if true, this variant is available
* for all images of this type],
- * ),
+ * ],
* ...
- * ),
+ * ],
* ...
- * ),
+ * ],
* // List of image files and their options
- * 'images' => array(
- * [theme name] => array(
- * [icon name] => array(
+ * 'images' => [
+ * [theme name] => [
+ * [icon name] => [
* 'file' => [file path string or array whose values are file path strings
* and whose keys are 'default', 'ltr', 'rtl', a single
* language code like 'en', or a list of language codes like
* 'en,de,ar'],
* 'variants' => [array of variant name strings, variants
* available for this image],
- * ),
+ * ],
* ...
- * ),
+ * ],
* ...
- * ),
- * )
+ * ],
+ * ]
* @endcode
* @throws InvalidArgumentException
*/
$this->{$member} = $option;
break;
- case 'position':
case 'prefix':
case 'selectorWithoutVariant':
case 'selectorWithVariant':
$selectors = $this->getSelectors();
foreach ( $this->getImages( $context ) as $name => $image ) {
- $declarations = $this->getCssDeclarations(
- $image->getDataUri( $context, null, 'original' ),
- $image->getUrl( $context, $script, null, 'rasterized' )
- );
- $declarations = implode( "\n\t", $declarations );
+ $declarations = $this->getStyleDeclarations( $context, $image, $script );
$selector = strtr(
$selectors['selectorWithoutVariant'],
[
$rules[] = "$selector {\n\t$declarations\n}";
foreach ( $image->getVariants() as $variant ) {
- $declarations = $this->getCssDeclarations(
- $image->getDataUri( $context, $variant, 'original' ),
- $image->getUrl( $context, $script, $variant, 'rasterized' )
- );
- $declarations = implode( "\n\t", $declarations );
+ $declarations = $this->getStyleDeclarations( $context, $image, $script, $variant );
$selector = strtr(
$selectors['selectorWithVariant'],
[
return [ 'all' => $style ];
}
+ /**
+ * @param ResourceLoaderContext $context
+ * @param ResourceLoaderImage $image Image to get the style for
+ * @param string $script URL to load.php
+ * @param string|null $variant Variant to get the style for
+ * @return string
+ */
+ private function getStyleDeclarations(
+ ResourceLoaderContext $context,
+ ResourceLoaderImage $image,
+ $script,
+ $variant = null
+ ) {
+ $imageDataUri = $image->getDataUri( $context, $variant, 'original' );
+ $primaryUrl = $imageDataUri ?: $image->getUrl( $context, $script, $variant, 'original' );
+ $declarations = $this->getCssDeclarations(
+ $primaryUrl,
+ $image->getUrl( $context, $script, $variant, 'rasterized' )
+ );
+ return implode( "\n\t", $declarations );
+ }
+
/**
* SVG support using a transparent gradient to guarantee cross-browser
* compatibility (browsers able to understand gradient syntax support also SVG).
return $localBasePath;
}
- /**
- * @return string
- */
- public function getPosition() {
- $this->loadFromDefinition();
- return $this->position;
- }
-
/**
* @return string
*/