Skip to content

Commit

Permalink
replaced inline javascript with addInitEvent call
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreone committed Sep 3, 2011
1 parent de757f2 commit 73d753d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
15 changes: 8 additions & 7 deletions action.php
Expand Up @@ -21,22 +21,22 @@ function register(&$controller) {
$controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handle_tpl_metaheader_output', array());
}



/**
* Replace our placeholder with the toc content
* Replace our placeholder with the actual toc content
*/
function handle_renderer_content_postprocess(&$event, $param) {
global $TOC;
if ($TOC) {
$js = '<script type="text/javascript">hideDokuwikiToc();</script>';
$html = '<div id="inlinetoc2" class="inlinetoc2">' . html_buildlist($TOC, 'inlinetoc2', 'html_list_inlinetoc2') . '</div>';
$event->data[1] = str_replace('<!-- INLINETOCPLACEHOLDER -->',
$html . $js,
$html,
$event->data[1]);
}
}

/**
* Include javascript
*/
function handle_tpl_metaheader_output(&$event, $param) {
$event->data["script"][] = array (
"type" => "text/javascript",
Expand All @@ -47,8 +47,9 @@ function handle_tpl_metaheader_output(&$event, $param) {
}

/**
* Callback for html_buildlist
*/
* Callback for html_buildlist.
* Builds list items with inlinetoc2 printable class instead of dokuwiki's toc class which isn't printable.
*/
function html_list_inlinetoc2($item){
if(isset($item['hid'])){
$link = '#'.$item['hid'];
Expand Down
3 changes: 3 additions & 0 deletions inlinetoc.js
@@ -1,3 +1,4 @@

function hideDokuwikiToc() {
if(document.getElementById('inlinetoc2')) {
var elements = document.getElementsByTagName('div');
Expand All @@ -9,3 +10,5 @@ function hideDokuwikiToc() {
}
}
}

addInitEvent(hideDokuwikiToc);

0 comments on commit 73d753d

Please sign in to comment.