1<?php
2
3if (!defined('DOKU_INC')) {die();}
4if (!defined('DOKU_PLUGIN')) {define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');}
5require_once DOKU_PLUGIN . 'action.php';
6
7class action_plugin_revealjs extends DokuWiki_Action_Plugin {
8
9    function register(Doku_Event_Handler $controller) {
10        $controller->register_hook('RENDERER_CONTENT_POSTPROCESS', 'BEFORE', $this, '_renderer_content_postprocess');
11    }
12
13    function _renderer_content_postprocess(&$event, $param) {
14        if ($_GET['do'] !== 'export_revealjs' && $this->getConf('revealjs_active')) {
15            /* close last edit section correctly (missing </div>), because we close sections
16            only when a new one is opened - and this logic fails for the last section in the
17            document */
18            $search = '<!-- EDIT';
19            $replace = '</div><!-- EDIT';
20            $pos = strrpos($event->data[1],$search);
21            if ($pos !== false) {
22                $event->data[1] = substr_replace($event->data[1], $replace, $pos, strlen($search));
23                //dbglog('Plugin revealjs - hook RENDERER_CONTENT_POSTPROCESS - closing last edit section (missing </div>).', __FILE__.' line '.__LINE__);
24            }
25
26            // correct link for PDF export and fixing unknown slide directions in wiki page with jQuery
27            $event->data[1] .='
28<script>
29jQuery(document).ready(function(){
30    jQuery(".slide-export-link a:last").each(function(){
31        var elem = jQuery(this);
32        var count = (elem.attr("href").match(/\?/g) || []).length;
33        if (count == 0) {
34            elem.attr("href", elem.attr("href").replace("&print-pdf","?print-pdf"));
35        }
36    });'.($this->getConf('slides_with_unknown_direction')?'
37    jQuery(".fix-my-direction").each(function(){
38        var elem = jQuery(this);
39        elem.removeClass("fix-my-direction");
40        if (elem.next().find("h1'.($this->getConf('horizontal_slide_level')==2?',h2':'').'").length > 0) {
41            elem.text("→" + elem.text());
42        }
43        else {
44            elem.text("↓" + elem.text());
45        }
46    });':'').'
47});
48</script>';
49        }
50    }
51
52}
53