-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix params error, fix slidesToShow * refactored styles * update arrow color * caption width * fix test
- Loading branch information
1 parent
c07e5be
commit 8eb978e
Showing
3 changed files
with
71 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* | ||
* @license GPL-2.0-or-later | ||
* | ||
* @author thomas-topway-it <[email protected]> | ||
* @author thomas-topway-it for KM-A | ||
*/ | ||
namespace SRF; | ||
|
||
|
@@ -261,10 +261,12 @@ public function getParamDefinitions( array $definitions ) { | |
'default' => "window", | ||
]; | ||
|
||
$params['slick-responsive'] = [ | ||
'message' => 'srf-paramdesc-carousel-slick-option', | ||
'default' => null, | ||
]; | ||
// @see https://github.com/kenwheeler/slick/#responsive-option-example | ||
// $params['slick-responsive'] = [ | ||
// 'type' => 'string', | ||
// 'message' => 'srf-paramdesc-carousel-slick-option', | ||
// 'default' => null, | ||
// ]; | ||
|
||
$params['slick-rows'] = [ | ||
'type' => 'integer', | ||
|
@@ -398,16 +400,12 @@ protected function getResultText( SMWQueryResult $results, $outputmode ) { | |
|
||
$this->isHTML = true; | ||
|
||
// SMWOutputs::requireResource( 'ext.srf.carousel' ); | ||
$resourceFormatter->registerResources( [ | ||
'ext.srf.carousel', | ||
'ext.srf.carousel.module' | ||
] ); | ||
|
||
// or ... | ||
// SMWOutputs::requireResource( 'ext.srf.carousel' ); | ||
|
||
// print_r($data); | ||
|
||
/* | ||
* first retrieve explicitly set properties: | ||
* titleproperty, captionproperty, imageproperty, linkproperty | ||
|
@@ -422,25 +420,7 @@ protected function getResultText( SMWQueryResult $results, $outputmode ) { | |
$printReqLabels[ $value['label'] ] = $value['typeid']; | ||
} | ||
|
||
$styleAttr = [ 'width', 'height' ]; | ||
$style = []; | ||
foreach( $styleAttr as $attr ) { | ||
if ( !empty( $this->params[$attr] ) ) { | ||
$style[ $attr ] = "$attr: " . $this->params[$attr]; | ||
} | ||
} | ||
|
||
if ( !array_key_exists( 'width', $style ) ) { | ||
$style[ 'width' ] = 'width: 100%'; | ||
} | ||
|
||
$styleImg = array_map( static function ( $value ) { | ||
// return 'max-' . $value; | ||
return $value; | ||
}, $style ); | ||
|
||
$styleImg[] = 'object-fit: cover'; | ||
$styleImg = implode( '; ', $styleImg ); | ||
$inlineStyles = $this->getInlineStyles(); | ||
|
||
$parser = MediaWikiServices::getInstance()->getParser(); | ||
$items = []; | ||
|
@@ -526,12 +506,17 @@ protected function getResultText( SMWQueryResult $results, $outputmode ) { | |
$captionValue = $parser->recursiveTagParse( $captionValue ); | ||
} | ||
|
||
$innerContent = Html::rawElement( 'img', [ | ||
'src' => $imageValue, | ||
'alt' => ( $titleValue ?? $captionValue ? strip_tags( $captionValue ) : $title_->getText() ), | ||
'style' => $styleImg, | ||
'class' => "slick-slide-content img" | ||
] ); | ||
$imgAttr = [ | ||
'src' => $imageValue, | ||
'alt' => ( $titleValue ?? $captionValue ? strip_tags( $captionValue ) : $title_->getText() ), | ||
'class' => "slick-slide-content img" | ||
]; | ||
|
||
if ( !empty( $inlineStyles['img'] ) ) { | ||
$imgAttr['style'] = $inlineStyles['img']; | ||
} | ||
|
||
$innerContent = Html::rawElement( 'img', $imgAttr ); | ||
|
||
if ( $titleValue || $captionValue ) { | ||
$innerContent .= Html::rawElement( 'div', [ 'class' => 'slick-slide-content caption' ], | ||
|
@@ -552,9 +537,9 @@ protected function getResultText( SMWQueryResult $results, $outputmode ) { | |
} // loop through pages | ||
|
||
$attr = [ 'class' => 'slick-slider' . ( empty( $this->params['class'] ) ? '' : ' ' . $this->params['class'] ) ]; | ||
|
||
if ( count( $style ) ) { | ||
$attr['style'] = implode( '; ', $style ); | ||
if ( !empty( $inlineStyles['div'] ) ) { | ||
$attr['style'] = $inlineStyles['div']; | ||
} | ||
|
||
$slick_attr = []; | ||
|
@@ -572,7 +557,47 @@ protected function getResultText( SMWQueryResult $results, $outputmode ) { | |
implode( $items ) | ||
); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
private function getInlineStyles() { | ||
if ( empty( $this->params['width'] ) ) { | ||
$this->params['width'] = '100%'; | ||
} | ||
|
||
preg_match( '/^(\d+)(.+)?$/', $this->params['width'], $match ); | ||
$styleImg = [ 'object-fit: cover' ]; | ||
|
||
$absoluteUnits = [ 'cm', 'mm', 'in', 'px', 'pt', 'pc' ]; | ||
$slidestoshow = $this->params['slick-slidestoshow']; | ||
|
||
// @see https://github.com/SemanticMediaWiki/SemanticResultFormats/issues/784 | ||
if ( !empty( $slidestoshow ) && is_int( $slidestoshow ) && !empty( $match[1] ) ) { | ||
if ( empty( $match[2] ) ) { | ||
$match[2] = 'px'; | ||
} | ||
$styleImg[] = 'max-width:' . ( in_array( $match[2], $absoluteUnits ) ? | ||
( $match[1] / $slidestoshow ) . $match[2] | ||
: '100%' ); | ||
} | ||
|
||
$styleAttr = [ 'width', 'height' ]; | ||
$style = []; | ||
foreach( $styleAttr as $attr ) { | ||
if ( !empty( $this->params[$attr] ) ) { | ||
$style[ $attr ] = "$attr: " . $this->params[$attr]; | ||
} | ||
} | ||
|
||
return [ 'div' => implode( '; ', $style ), | ||
'img' => implode( '; ', $styleImg ) ]; | ||
} | ||
|
||
/** | ||
* @param array $array | ||
* @return string|null | ||
*/ | ||
protected function getFirstValid( $array ) { | ||
// *** or use array_filter with no arguments, then | ||
// retrieve the first entry | ||
|
@@ -584,6 +609,10 @@ protected function getFirstValid( $array ) { | |
return null; | ||
} | ||
|
||
/** | ||
* @param array $value | ||
* @return string|null | ||
*/ | ||
protected function getImage( $value ) { | ||
if ( !is_array( $value ) || !array_key_exists( 'fullurl', $value ) || $value['namespace'] !== NS_FILE ) { | ||
return null; | ||
|
@@ -601,4 +630,3 @@ protected function getImage( $value ) { | |
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters