register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'handle_dokuwiki_started'); $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handle_tpl_metaheader_output'); } public function handle_dokuwiki_started(Doku_Event &$event, $param) { global $INFO, $JSINFO; $wraplimit = trim($this->getConf('wraplimit')); $xmltags = $this->getConf('xmltags'); $xmltags = ($xmltags ? explode(',', $xmltags) : array()); $JSINFO['plugin_aceeditor'] = array( 'default' => $this->getConf('default'), 'highlight' => $this->getConf('highlight'), 'wraplimit' => $wraplimit ? (int) $wraplimit : null, 'colortheme' => $this->getConf('colortheme'), 'latex' => $this->getConf('latex'), 'markdown' => $this->getConf('markdown'), 'mdpage' => substr($INFO['id'], -3) == '.md', 'xmltags' => $xmltags, ); } public function handle_tpl_metaheader_output(Doku_Event &$event, $param) { global $ACT; if (!in_array($ACT, array('edit', 'create', 'source', 'preview', 'locked', 'draft', 'recover'))) { return; } if (!$this->has_jquery() and $this->getConf('loadjquery')) { $jqueryurl = '//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js'; $this->link_script($event, $jqueryurl); $this->include_script($event, '$.noConflict();'); } if (file_exists(DOKU_INC.'lib/plugins/aceeditor/build.js')) { $this->link_script($event, DOKU_BASE.'lib/plugins/aceeditor/build.js'); } else { $this->link_script($event, DOKU_BASE.'lib/plugins/aceeditor/vendor/require.js'); $this->link_script($event, DOKU_BASE.'lib/plugins/aceeditor/scripts/init.js'); } // Workaround for conflict with syntaxhighlighter3 plugin $this->include_script($event, 'window.require = undefined;'); } public function has_jquery() { $version = getVersionData(); $date = str_replace('-', '', $version['date']); return (int) $date > 20110525; } private function include_script($event, $code) { $event->data['script'][] = array( 'type' => 'text/javascript', 'charset' => 'utf-8', '_data' => $code, ); } private function link_script($event, $url) { $event->data['script'][] = array( 'type' => 'text/javascript', 'charset' => 'utf-8', 'src' => $url, ); } }