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 'type' => array('type' => 'choice', 18 'data' => array('primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark'), 19 'default' => 'primary'), 20 'size' => array('type' => 'choice', 21 'data' => array('large'=> array('large', 'lg'), 'small' => array('small', 'sm')), 22 'default' => ''), 23 'block' => array('type' => 'boolean', 'default' => 'false'), 24 'active' => array('type' => 'boolean', 'default' => 'false'), 25 'disabled' => array('type' => 'boolean', 'default' => 'false'), // also supports prefix => '' 26 'url' => array('type' => 'url', 'default' => ''), 27 'target' => array('type' => 'text', 'default' => ''), 28 'newtab' => array('type' => 'set', 'option' => 'target', 'data' => '_blank'), 29 'collapse-id' => array('type' => 'text', 'default' => ''), 30 'nowrap' => array('type' => 'boolean', 'default' => 'false'), 31 ); 32 33 public function __construct() { 34 $this->addCommonOptions('type shadow width align text-align'); 35 $this->options['type']['data'] = array_merge($this->options['type']['data'], array('link', 'outline-primary', 'outline-secondary', 'outline-success', 'outline-danger', 'outline-warning', 'outline-info', 'outline-light', 'outline-dark')); 36 $this->options['type']['default'] = 'primary'; 37 } 38 39 public function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); } 40 public function getPType() { return 'normal'; } 41 42 public function render_lexer_enter(Doku_Renderer $renderer, $data) { 43 $classes = $this->buildClass($data, array('size', 'block', 'active', 'disabled', 'nowrap')); 44 $styles = $this->buildStyle(array('width' => $data['width']), TRUE); 45 46 $url = ($data['url'] != '' ? $this->buildLink($data['url']) : '#'); 47 $target = $data['target']; 48 $collapse = $data['collapse-id']; 49 50 $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 . '>'; 51 } 52 53 54 public function render_lexer_exit(Doku_Renderer $renderer, $data) { 55 $renderer->doc .= '</a>'; 56 } 57} 58?>