1<?php
2/**
3 * Tooltip Plugin: Create tooltips for sections of wikitext.
4 *
5 *   syntax: {!tooltipee:tooltiped}}
6 *
7 * @file       tooltip/syntax/short.php
8 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
9 * @author     Luis Machuca B. <luis [dot] machuca [at] gulix [dot] cl>
10 * @brief      CSS-based one-word toltips
11 * @version    1.8
12 *
13 *   This plugin allows to insert "tooltips" in DokuWiki text, so that
14 *  hovering the mouse over the mrked text will reveal the tooltip.
15 *  The wikitext that composes the tooltip is parsed for basic
16 *  formatting only (underlines, italics and bolds). Otherwise,
17 *  the plugin is perfectly usable.
18 *   This plugin uses CSS only; no JavaScript or server side help
19 *  (beyond the actual tag parsing) is used to harm any animal,
20 *  in any way.
21 *
22 *   For a live demo check instructions in the lugin page.
23 *
24 *  Greetings.
25 *        - Luis Machuca Bezzaza ('ryan.chappelle' at the Wiki)
26 */
27
28if(!defined('DW_LF')) define('DW_LF',"\n");
29
30if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
31if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
32require_once(DOKU_PLUGIN.'syntax.php');
33
34
35class syntax_plugin_tooltip_short extends DokuWiki_Syntax_Plugin
36{
37  function getInfo()
38  {
39    return array (
40           'author' => 'Luis Machuca Bezzaza',
41           'email'  => 'luis.machuca [at] gulix.cl',
42           'date'   => @file_get_contents(DOKU_PLUGIN . 'tooltip/VERSION'),
43           'name'   => 'Tooltip Plugin ('. $this->getLang('comp.short'). ')',
44           'desc'   => $this->getLang('descr.short').
45                       ': {!word:description}}.',
46           'url'    => 'http://www.dokuwiki.org/plugin:tooltip',
47           );
48  }
49
50  function getType()  {
51    return 'formatting';
52  }
53
54  function getAllowedTypes()  {
55    return array('substition','disabled','formatting');
56  }
57
58  function getPType()  {
59    return 'normal';
60  }
61
62  function getSort() {
63    return 400;
64  } // get by exp
65
66  function connectTo($mode)  {
67    $this->Lexer->addEntryPattern(
68                  '\{\![^:]+:(?=.*?\}\})',
69                  $mode,
70                  'plugin_tooltip_short' );
71  }
72
73  function postConnect() {
74    $this->Lexer->addExitPattern(
75                  '\}\}',
76                  'plugin_tooltip_short');
77  }
78
79  function handle($match, $state, $pos, &$handler) {
80
81    $data= array();
82    $data['state']= $state;
83
84    switch ($state)  {
85      case DOKU_LEXER_ENTER: {
86         $match= substr($match, 2, -1);
87        $data['mark']= $match;
88        break;
89      }
90      case DOKU_LEXER_UNMATCHED: {
91        $data['content']= $match;
92        break;
93      }
94    } // end switch ($state)
95    return $data;
96  } // end function
97
98  function render($mode, &$renderer, $data) {
99    static $counter= 0;
100    $state= $data['state'];
101    $style= "tooltip_inline";
102    $mark= $data['mark'];
103    $content= $data['content'];
104
105    if($mode == 'xhtml') {
106      /* let's do the jon thingie, that is,
107         create the HTML code that reveals the tooltip
108       */
109      switch ($state) {
110        case DOKU_LEXER_ENTER: {
111          $renderer->doc.= '<span class="'. $style. '"><span>';
112          $renderer->doc.= $renderer->_xmlEntities($mark);
113          $renderer->doc.= '<span class="tip">';
114          break;
115        }
116        case DOKU_LEXER_UNMATCHED: {
117          $renderer->doc.= $renderer->_xmlEntities($content);
118          break;
119        }
120        case DOKU_LEXER_EXIT: {
121          $renderer->doc.= '</span> </span>';
122          $renderer->doc.= '</span><!-- end tooltip -->'. DW_LF;
123          break;
124        }
125      } // end switch
126      return true;
127    } // end if (xhtml)
128
129    else if ($mode == 'text') {
130      // simple for the plaintext renderer (for things like search)
131      switch ($state) {
132        case DOKU_LEXER_ENTER: {
133          $renderer->doc.= $mark. ' ';
134          break;
135        }
136        case DOKU_LEXER_UNMATCHED: {
137          $renderer->doc.= '[Tooltip: '. $content. '] ';
138          break;
139        }
140        case DOKU_LEXER_EXIT: {
141          break;
142        }
143      } // end switch
144      return true;
145
146    } // end if (text)
147
148    // no more renderers
149    return false;
150  }
151
152
153}
154