1<?php 2/** 3 * Bootstrap Wrapper Plugin: Collapse 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com> 7 * @copyright (C) 2015-2020, Giuseppe Di Terlizzi 8 */ 9 10class syntax_plugin_bootswrapper_collapse extends syntax_plugin_bootswrapper_bootstrap 11{ 12 13 public $p_type = 'block'; 14 public $pattern_start = '<collapse.*?>(?=.*?</collapse>)'; 15 public $pattern_end = '</collapse>'; 16 public $tag_name = 'collapse'; 17 public $tag_attributes = array( 18 19 'id' => array( 20 'type' => 'string', 21 'values' => null, 22 'required' => true, 23 'default' => null), 24 25 'collapsed' => array( 26 'type' => 'boolean', 27 'values' => array(0, 1), 28 'required' => false, 29 'default' => false), 30 31 ); 32 33 public function render($mode, Doku_Renderer $renderer, $data) 34 { 35 36 if (empty($data)) { 37 return false; 38 } 39 40 if ($mode !== 'xhtml') { 41 return false; 42 } 43 44 /** @var Doku_Renderer_xhtml $renderer */ 45 list($state, $match, $pos, $attributes) = $data; 46 47 if ($state == DOKU_LEXER_ENTER) { 48 $id = $attributes['id']; 49 $collapsed = $attributes['collapsed']; 50 $markup = '<div class="bs-wrap bs-wrap-collapse collapse ' . ($collapsed ? '' : 'in') . '" id="' . $id . '">'; 51 52 $renderer->doc .= $markup; 53 return true; 54 55 } 56 57 if ($state == DOKU_LEXER_EXIT) { 58 $renderer->doc .= '</div>'; 59 return true; 60 } 61 62 return true; 63 } 64} 65