1<?php
2
3use dokuwiki\Extension\ActionPlugin;
4use dokuwiki\Extension\EventHandler;
5use dokuwiki\Extension\Event;
6
7/**
8 * DokuWiki Plugin secedit2head (Action Component)
9 *
10 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
11 * @author Jef Shilt <github@fortytwo-it.com>
12 */
13class action_plugin_secedit2head extends ActionPlugin
14{
15    /** @inheritDoc */
16    public function register(EventHandler $controller)
17    {
18        $controller->register_hook('TPL_ACT_RENDER', 'AFTER', $this, 'handleTplActRender');
19    }
20
21    /**
22     * Event handler for TPL_ACT_RENDER
23     *
24     * @see https://www.dokuwiki.org/devel:events:TPL_ACT_RENDER
25     * @param Event $event Event object
26     * @param mixed $param optional parameter passed when event was registered
27     * @return void
28     */
29    public function handleTplActRender(Event $event, $param)
30    {
31?>
32<script>
33    // first, make sure jQuery has loaded
34    var secedit2head_jQueryLoaded = setInterval(function(){
35        if (typeof jQuery !== "undefined") {
36            clearInterval(secedit2head_jQueryLoaded);
37            var secedit2head_sections = jQuery(".editbutton_section").length;
38            // second, wait for page.js to have setup section wrappers
39            var secedit2head_PageJSLoaded = setInterval(function(){
40                var secedit2head_wrappers = jQuery(".section_highlight_wrapper").length;
41                if (secedit2head_wrappers == secedit2head_sections) {
42                    clearInterval(secedit2head_PageJSLoaded);
43                    jQuery(".editbutton_section").each(function() {
44                        var se2h_matched = jQuery(this).prop("class").match(/editbutton_(\d+)/);
45                        if (se2h_matched[1]) {
46                            var secedit2head_btn = jQuery(this).remove();
47                            // find section header and append btn node
48                            jQuery(".sectionedit" + se2h_matched[1]).prepend(secedit2head_btn);
49                            secedit2head_btn.on("mouseover", function(){jQuery(this).parents(".section_highlight_wrapper").addClass("section_highlight");}
50                            ).on("mouseout", function(){jQuery(this).parents(".section_highlight_wrapper").removeClass("section_highlight");});
51                        }
52                    });
53                }
54            },10);
55        }
56    },10);
57</script>
58<?php
59    }
60}
61