1<?php
2/**
3 * Mikio Syntax Plugin: Button
4  *
5 * @link        http://github.com/nomadjimbob/mikioplugin
6 * @license     GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author      James Collins <james.collins@outlook.com.au>
8 */
9if (!defined('DOKU_INC')) die();
10if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
11require_once(dirname(__FILE__).'/core.php');
12
13class syntax_plugin_mikioplugin_button extends syntax_plugin_mikioplugin_core {
14    public $tag                 = 'button';
15    public $hasEndTag           = true;
16    public $options             = array(
17        'size'          => array('type'     => 'choice',
18                                 'data'     => array('large'=> array('large', 'lg'), 'small' => array('small', 'sm')),
19                                 'default'  => ''),
20        'block'         => array('type'     => 'boolean',   'default'   => 'false'),
21        'active'        => array('type'     => 'boolean',   'default'   => 'false'),
22        'disabled'      => array('type'     => 'boolean',   'default'   => 'false'),    // also supports prefix => ''
23        'url'           => array('type'     => 'url',       'default'   => ''),
24        'target'        => array('type'     => 'text',      'default'   => ''),
25        'newtab'        => array('type'     => 'set',       'option'    => 'target',    'data'  => '_blank'),
26        'collapse-id'   => array('type'     => 'text',      'default'   => ''),
27        'nowrap'        => array('type'     => 'boolean',   'default'   => 'false'),
28    );
29
30    public function __construct() {
31        $this->addCommonOptions('type shadow width align text-align tooltip');
32        $this->options['type']['default'] = 'primary';
33    }
34
35    public function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); }
36    public function getPType() { return 'normal'; }
37
38    public function render_lexer_enter(Doku_Renderer $renderer, $data) {
39        $classes = $this->buildClass($data, array('size', 'block', 'active', 'disabled', 'nowrap'));
40        $styles = $this->buildStyle(array('width' => $data['width']), TRUE);
41
42        // $url = ($data['url'] != '' ? $this->buildLink($data['url']) : '#');
43        $url = $data['url'];
44        $target = $data['target'];
45        $collapse = $data['collapse-id'];
46
47        $renderer->doc .= '<a href="' . $url . '"' . ($target != '' ? ' target="'.$target.'"' : '') . ' class="' . $this->elemClass . ' ' . $this->classPrefix . 'button ' . $classes . '" role="button"' . ($collapse != '' ? ' data-toggle="collapse" data-target="#' . $data['collapse-id'] . '"' : '') . ' ' . ($data['disabled'] ? 'disabled' : '') . $styles . $this->buildTooltip($data['tooltip']) . '>';
48    }
49
50
51    public function render_lexer_exit(Doku_Renderer $renderer, $data) {
52        $renderer->doc .= '</a>';
53    }
54}
55?>