1<?php 2/** 3 * Bootstrap Wrapper Plugin: Tooltip 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Jos Roossien <mail@jroossien.com> 7 * @author Giuseppe Di Terlizzi <giuseppe.diterlizzi@gmail.com> 8 * @copyright (C) 2015-2020, Giuseppe Di Terlizzi 9 */ 10 11class syntax_plugin_bootswrapper_popover extends syntax_plugin_bootswrapper_bootstrap 12{ 13 14 public $p_type = 'normal'; 15 public $pattern_start = '<popover.*?>(?=.*?</popover>)'; 16 public $pattern_end = '</popover>'; 17 public $tag_name = 'popover'; 18 public $tag_attributes = array( 19 20 'placement' => array( 21 'type' => 'string', 22 'values' => array('top', 'bottom', 'left', 'right', 'auto', 'auto top', 'auto bottom', 'auto left', 'auto right'), 23 'required' => true, 24 'default' => 'right'), 25 26 'title' => array( 27 'type' => 'string', 28 'values' => null, 29 'required' => false, 30 'default' => null), 31 32 'content' => array( 33 'type' => 'string', 34 'values' => null, 35 'required' => true, 36 'default' => null), 37 38 'trigger' => array( 39 'type' => 'multiple', 40 'values' => array('click', 'hover', 'focus'), 41 'required' => true, 42 'default' => 'click'), 43 44 'html' => array( 45 'type' => 'boolean', 46 'values' => array(0, 1), 47 'required' => false, 48 'default' => false), 49 50 'animation' => array( 51 'type' => 'boolean', 52 'values' => array(0, 1), 53 'required' => false, 54 'default' => true), 55 56 'delay' => array( 57 'type' => 'integer', 58 'values' => null, 59 'required' => false, 60 'default' => 0), 61 62 'delay-show' => array( 63 'type' => 'integer', 64 'values' => null, 65 'required' => false, 66 'default' => 0), 67 68 'delay-hide' => array( 69 'type' => 'integer', 70 'values' => null, 71 'required' => false, 72 'default' => 0), 73 74 ); 75 76 public function render($mode, Doku_Renderer $renderer, $data) 77 { 78 79 if (empty($data)) { 80 return false; 81 } 82 83 if ($mode !== 'xhtml') { 84 return false; 85 } 86 87 /** @var Doku_Renderer_xhtml $renderer */ 88 list($state, $match, $pos, $attributes) = $data; 89 90 if ($state == DOKU_LEXER_ENTER) { 91 $html5_data = array(); 92 93 extract($attributes); 94 95 if ($html) { 96 $title = hsc(p_render('xhtml', p_get_instructions($title), $info)); 97 $content = hsc(p_render('xhtml', p_get_instructions($content), $info)); 98 } 99 100 if ($trigger) { 101 $html5_data[] = 'data-trigger="' . $trigger . '"'; 102 } 103 104 if ($animation) { 105 $html5_data[] = 'data-animation="' . $animation . '"'; 106 } 107 108 if ($html) { 109 $html5_data[] = 'data-html="' . $html . '"'; 110 } 111 112 if ($placement) { 113 $html5_data[] = 'data-placement="' . $placement . '"'; 114 } 115 116 if ($content) { 117 $html5_data[] = 'data-content="' . $content . '"'; 118 } 119 120 if ($delay) { 121 $html5_data[] = 'data-delay="' . $delay . '"'; 122 } 123 124 if (!$delay && ($attributes['delay-hide'] || $attributes['delay-show'])) { 125 $delays = array(); 126 $show = $attributes['delay-show']; 127 $hide = $attributes['delay-hide']; 128 129 if ($hide) { 130 $delays['hide'] = $hide; 131 } 132 133 if ($show) { 134 $delays['show'] = $show; 135 } 136 137 $html5_data[] = "data-delay='" . json_encode($delays) . "'"; 138 } 139 140 $markup = '<span class="bs-wrap bs-wrap-popover" data-toggle="popover" title="' . $title . '" ' . implode(' ', $html5_data) . '>'; 141 142 $renderer->doc .= $markup; 143 144 return true; 145 } 146 147 if ($state == DOKU_LEXER_EXIT) { 148 $renderer->doc .= '</span>'; 149 return true; 150 } 151 152 return true; 153 } 154} 155