diff --git a/PicoUICard.php b/PicoUICard.php index 4cab1d7..d702902 100644 --- a/PicoUICard.php +++ b/PicoUICard.php @@ -49,6 +49,7 @@ final class PicoUICard extends AbstractPicoPlugin public function onConfigLoaded(array &$config) { $this->config['loadBootstrap'] = false; + $this->config['cardRatio'] = '16:9'; $this->config['cardPosition'] = 'col-md-4 col-sm-6 col-xs-6'; $this->config['cardTitle'] = ''; $this->config['cardText'] = ''; @@ -56,6 +57,9 @@ final class PicoUICard extends AbstractPicoPlugin if (isset($config['PicoUICard.loadBootstrap'])) { $this->config['loadBootstrap'] = $config['PicoUICard.loadBootstrap']; } + if (isset($config['PicoUICard.cardRatio'])) { + $this->config['cardRatio'] = $config['PicoUICard.cardRatio']; + } if (isset($config['PicoUICard.cssClass.cardPosition'])) { $this->config['cardPosition'] = $config['PicoUICard.cssClass.cardPosition']; } @@ -65,6 +69,9 @@ final class PicoUICard extends AbstractPicoPlugin if (isset($config['PicoUICard.cssClass.cardText'])) { $this->config['cardText'] = $config['PicoUICard.cssClass.cardText']; } + // some postprocessing of config + list($cardWidth, $cardHeight) = explode(':', $this->config['cardRatio']); + $this->config['cardHeightMultiplier'] = max(0.01, min(floatval($cardHeight) / floatval($cardWidth), 10)) * 100; } /** @@ -90,7 +97,7 @@ final class PicoUICard extends AbstractPicoPlugin preg_match_all('/\s*([a-z]+)\=[\'\"]([^\'\"]*)[\'\"]/', $matches[1], $attributes); preg_match_all('/\[([a-z]+)\]([^\[]*)\[\/([a-z]+)\]\s*/', $matches[3], $subtags); // look for what we want from attributes and subtags - $uicard = array('href' => '', 'img' => '', 'title' => '', 'text' => ''); + $uicard = array('href' => '', 'img' => '', 'ratio' => '', 'title' => '', 'text' => ''); for ($i = 0; $i < count($attributes[0]); $i++) { $uicard[ $attributes[1][$i] ] = $attributes[2][$i]; } @@ -100,9 +107,15 @@ final class PicoUICard extends AbstractPicoPlugin } $uicard[ $subtags[1][$i] ] = $subtags[2][$i]; } + if (!empty($uicard['ratio'])) { + list($cardWidth, $cardHeight) = explode(':', $uicard['ratio']); + $cardRatio = ' padding-bottom: '.(max(0.01, min(floatval($cardHeight) / floatval($cardWidth), 10)) * 100).'%;'; + } else { + $cardRatio = ''; // default + } $result = '
'; $result .= ''; - $result .= '
'; + $result .= '
'; $result .= '
'; $result .= '
'; $result .= $uicard['title']; @@ -150,14 +163,17 @@ final class PicoUICard extends AbstractPicoPlugin $headers .= ' '; return $headers; diff --git a/README.md b/README.md index 5d88e1e..8547bc2 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Create a card (with a hyperlink) such as this: Using code that looks like below in your markdown file: ``` -[ui.card href="https://google.com" img="http://i.imgur.com/TkTgq3L.jpg"] +[ui.card href="https://google.com" img="http://i.imgur.com/TkTgq3L.jpg" ratio="16:9"] [title]Cute Dog[/title] [text]This page is about this cute dog.[/text] [/ui.card] @@ -58,13 +58,23 @@ If you don't, you can enable this setting to load Bootstrap from their official $config[ 'PicoUICard.loadBootstrap' ] = true; ``` +**Card size ratio**: By default, card images are 16:9, meaning that the height is 56.25% of the width. You +can change this default ratio, by assigning a value of `width:height` ratio. Default value is `16:9`. + +``` +$config[ 'PicoUICard.cardRatio' ] = '4:3'; +``` + +Note that in addition to the default ratio setting, you can also change each individual card's ratio using +the `ratio` attribute in the markdown tag. + **Card size and positioning**: Pico UI Cards are wrapped within a `row` class (Bootstrap), and so each card has a definition of column size. (See [Bootstrap: Grid System](http://getbootstrap.com/css/#grid)) Use the following config to change it. The default value is: `col-md-4 col-sm-6 col-xs-6`. ``` -$config[ 'PicoUICard.cssClass.cardPosition' ] = 'col-md-4 col-sm-6 col-xs-6'; +$config[ 'PicoUICard.cssClass.cardPosition' ] = 'col-md-6'; ``` **Title text and description text**: You can define your own CSS classes for the title text and description text.