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        $this->options['type']['data'][] = 'link';
34    }
35
36    public function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); }
37    public function getPType() { return 'normal'; }
38
39    public function render_lexer_enter(Doku_Renderer $renderer, $data) {
40        $classes = $this->buildClass($data, array('size', 'block', 'active', 'disabled', 'nowrap'));
41        $styles = $this->buildStyle(array('width' => $data['width']), TRUE);
42
43        // $url = ($data['url'] != '' ? $this->buildLink($data['url']) : '#');
44        $url = $data['url'];
45        $target = $data['target'];
46        $collapse = $data['collapse-id'];
47
48        $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']) . '>';
49    }
50
51
52    public function render_lexer_exit(Doku_Renderer $renderer, $data) {
53        $renderer->doc .= '</a>';
54    }
55}
56?>