1<?php 2/** 3 * TocTweak plugin for DokuWiki; Action closetoc 4 * set toggle state initially closed (by script.js) 5 * 6 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 7 * @author Satoshi Sahara <sahara.satoshi@gmail.com> 8 */ 9 10if(!defined('DOKU_INC')) die(); 11 12class action_plugin_toctweak_closetoc extends DokuWiki_Action_Plugin { 13 14 // register hook 15 public function register(Doku_Event_Handler $controller) { 16 $controller->register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, '_exportToJSINFO'); 17 } 18 19 /** 20 * Exports configuration settings to $JSINFO 21 */ 22 public function _exportToJSINFO(Doku_Event $event) { 23 global $JSINFO, $INFO, $ACT; 24 // TOC control should be changeable in only normal page 25 if (( empty($ACT) || ($ACT=='show') || ($ACT=='preview')) == false) return; 26 27 if (!isset($INFO['meta']['toc']['initial_state'])) { 28 $meta_tocInitialState = 1; // open state 29 } else { 30 $meta_tocInitialState = $INFO['meta']['toc']['initial_state']; 31 } 32 $JSINFO['toc'] = array( 33 'initial_state' => $meta_tocInitialState, 34 ); 35 } 36 37} 38