1<?php 2/** 3 * Mikio Syntax Plugin: Button 4 * 5 * Syntax: <BUTTON [primary|secondary|success|danger|warning|info|light|dark] [url] [target] [newtab] [collapse-id] [nowrap]></BUTTON> 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_button extends syntax_plugin_mikioplugin_core { 16 public $tag = 'button'; 17 public $defaults = array('type' => 'primary'); 18 public $options = array( 19 'type' => array('primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark', 'outline-primary', 'outline-secondary', 'outline-success', 'outline-danger', 'outline-warning', 'outline-info', 'outline-light', 'outline-dark'), 20 'size' => array('lg', 'sm'), 21 'block', 22 'active', 23 'disabled', 24 'url', 25 'target', 26 'newtab', 27 'collapse-id', 28 'nowrap' 29 ); 30 31 32 public function render_lexer_enter(Doku_Renderer $renderer, $data) { 33 $classes = $this->buildClassString($data, array('type', 'size', 'block', 'active', 'disabled', 'nowrap'), array('btn-' => array('type', 'size', 'block'), 'text-' => 'nowrap')); 34 35 $url = '#'; 36 if(array_key_exists('url', $data) && $data['url'] != '') $url = $this->getLink($data['url']); 37 38 $target = ''; 39 if(array_key_exists('target', $data) && $data['target'] != '') $target = ' target="' . $data['target'] . '"'; 40 if(array_key_exists('newtab', $data) && $data['newtab'] != false) $target = ' target="_blank"'; 41 42 $collapse = ''; 43 if(array_key_exists('collapse-id', $data) && $data['collapse-id'] != '') { 44 $collapse = ' data-toggle="collapse" data-target="#' . $data['collapse-id'] . '"'; 45 } 46 47 $renderer->doc .= '<a href="' . $url . '"' . $target . ' class="btn ' . $classes . '" role="button"' . $collapse . $this->buildStyleString($data) . '>'; 48 } 49 50 51 public function render_lexer_exit(Doku_Renderer $renderer, $data) { 52 $renderer->doc .= '</a>'; 53 } 54} 55?>