xref: /plugin/mikioplugin/syntax/carousel.php (revision ee3901e1d02c5d23fc24c57a42a9416a330b9b54)
1<?php
2
3/**
4 * Mikio Syntax Plugin: Carousel
5 *
6 * @link        http://github.com/nomadjimbob/mikioplugin
7 * @license     GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 * @author      James Collins <james.collins@outlook.com.au>
9 */
10if (!defined('DOKU_INC')) die();
11if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
12require_once(dirname(__FILE__) . '/core.php');
13
14class syntax_plugin_mikioplugin_carousel extends syntax_plugin_mikioplugin_core
15{
16    public $tag                 = 'carousel';
17    public $hasEndTag           = true;
18    public $options             = array(
19        'transition'    => array(
20            'type'     => 'choice',
21            'data'     => array('slide', 'fade'),
22            'default'  => ''
23        ),
24        'indicators'    => array(
25            'type'     => 'choice',
26            'data'     => array('true', 'false', 'circle'),
27            'default'  => 'true'
28        ),
29        'controls'      => array('type'     => 'boolean',   'default'   => 'true'),
30        'start'         => array('type'     => 'boolean',   'default'   => 'false'),
31        'cover'         => array('type'     => 'boolean',   'default'   => 'false'),
32        'control-color' => array('type'     => 'color',     'default'   => '#fff'),
33        'control-outline-color' => array('type'     => 'color',     'default'   => ''),
34        'control-outline-width' => array('type'     => 'multisize',     'default'   => ''),
35    );
36
37    public function __construct()
38    {
39        $this->addCommonOptions('height');
40    }
41
42
43    public function render_lexer_enter(Doku_Renderer $renderer, $data)
44    {
45        $classes = $this->buildClass($data, array('transition'));
46        $styles = $this->buildStyle(array('height' => $data['height']), TRUE);
47
48        $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'carousel' . ($data['cover'] ? ' ' . $this->classPrefix . 'image-cover' : '') . $classes . '" data-auto-start="' . ($data['start'] ? 'true' : 'false') . '"' . $styles . '>';
49        $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'carousel-inner">';
50    }
51
52
53    public function render_lexer_exit(Doku_Renderer $renderer, $data)
54    {
55        $renderer->doc .= '</div>';
56
57        if ($data['controls'] === TRUE) {
58            $svg_styles = $this->buildStyle(array('fill' => $data['control-color'], 'stroke' => $data['control-outline-color'], 'stroke-width' => $data['control-outline-width']), TRUE);
59
60            $renderer->doc .= '<a href="#" class="' . $this->elemClass . ' ' . $this->classPrefix . 'carousel-control ' . $this->classPrefix . 'carousel-control-prev" role="button"><svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 8 8"' . $svg_styles . '><path d="M5.25 0l-4 4 4 4 1.5-1.5L4.25 4l2.5-2.5L5.25 0z"/></svg></a>';
61            $renderer->doc .= '<a href="#" class="' . $this->elemClass . ' ' . $this->classPrefix . 'carousel-control ' . $this->classPrefix . 'carousel-control-next" role="button"><svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 8 8"' . $svg_styles . '><path d="M2.75 0l-1.5 1.5L3.75 4l-2.5 2.5L2.75 8l4-4-4-4z"/></svg></a>';
62        }
63
64        if (strcasecmp($data['indicators'], 'false') != 0) {
65            $renderer->doc .= '<ul class="' . $this->elemClass . ' ' . $this->classPrefix . 'carousel-indicators' . (strcasecmp($data['indicators'], 'circle') == 0 ? ' ' . $this->classPrefix . 'carousel-indicators-circle' : '') . '"></ul>';
66        }
67
68        $renderer->doc .= '</div>';
69    }
70}
71