xref: /plugin/mikioplugin/syntax/carousel.php (revision 57ae4893b5f9053049b9e317e4704416fb882895)
1<?php
2/**
3 * Mikio Syntax Plugin: Carousel
4 *
5 * Syntax:  <CAROUSEL [slide] [fade] [controls] [indicators=]></CAROUSEL>
6 *
7 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 * @author     James Collins <james.collins@outlook.com.au>
9 */
10
11if (!defined('DOKU_INC')) die();
12if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
13require_once(dirname(__FILE__).'/core.php');
14
15class syntax_plugin_mikioplugin_carousel extends syntax_plugin_mikioplugin_core {
16    public $tag                 = 'carousel';
17    public $options             = array('slide', 'fade', 'indicators', 'indicator-active', 'controls');
18
19
20    public function render_lexer_enter(Doku_Renderer $renderer, $data) {
21        $classes = $this->buildClassString($data, array('slide', 'fade'), array('carousel-' => 'fade'));
22
23        $this->values['id'] = 'carousel_'.rand(0, 32767);
24
25        $renderer->doc .= '<div class="carousel ' . $classes . '" data-ride="carousel" id="' . $this->values['id'] . '"' . $this->buildStyleString($data) . '>';
26
27        if(array_key_exists('indicators', $data) && $data['indicators'] > 0) {
28            $indicatorActive = 0;
29            if(array_key_exists('indicator-active', $data)) $indicatorActive = intval($data['indicator-active']);
30
31            $renderer->doc .= '<ol class="carousel-indicators">';
32            for($i = 0; $i < intval($data['indicators']); $i++) {
33                $renderer->doc .= '<li data-target="#' . $this->values['id'] . '" data-slide-to="' . $i . '"' . ($i == $indicatorActive ? ' class="active"' : ''). '></li>';
34            }
35            $renderer->doc .= '</ol>';
36        }
37
38        $renderer->doc .= '<div class="carousel-inner">';
39    }
40
41
42    public function render_lexer_exit(Doku_Renderer $renderer, $data) {
43        $renderer->doc .= '</div>';
44
45        if(array_key_exists('controls', $this->values) && $this->values['controls'] != false) {
46            $id = $this->values['id'];
47
48            $renderer->doc .= '<a class="carousel-control-prev" href="#' . $id . '" role="button" data-slide="prev"><span class="carousel-control-prev-icon" aria-hidden="true"></span><span class="sr-only">Previous</span></a><a class="carousel-control-next" href="#' . $id . '" role="button" data-slide="next"><span class="carousel-control-next-icon" aria-hidden="true"></span><span class="sr-only">Next</span></a>';
49        }
50
51        $renderer->doc .= '</div>';
52    }
53}
54?>