1<?php 2/** 3 * DokuWiki Action Plugin InlineJS 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Satoshi Sahara <sahara.satoshi@gmail.com> 7 */ 8// must be run within Dokuwiki 9if (!defined('DOKU_INC')) die(); 10 11class action_plugin_inlinejs extends DokuWiki_Action_Plugin 12{ 13 // register hook 14 public function register(Doku_Event_Handler $controller) 15 { 16 $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'inlinejs_handleMeta'); 17 } 18 19 20 /** 21 * TPL_METAHEADER_OUTPUT 22 * add inline javascript and/or stylesheet to the <head> section. 23 */ 24 public function inlinejs_handleMeta(Doku_Event $event, $param) 25 { 26 global $INFO; 27 28 if (!isset($INFO['meta']['plugin_inlinejs'])) return; 29 30 foreach ($INFO['meta']['plugin_inlinejs'] as $entry) { 31 switch ($entry['_tag']) { 32 case 'style': 33 $event->data['style'][] = array( 34 'type' => 'text/css', 35 '_data' => $entry['_data'], 36 ); 37 break; 38 case 'link': 39 $event->data['link'][] = array( 40 'rel' => 'stylesheet', 41 'type' => 'text/css', 42 'href' => $entry['href'], 43 ); 44 break; 45 case 'script': 46 if (isset($entry['src'])) { 47 $event->data['script'][] = array( 48 'type' => 'text/javascript', 49 'charset' => 'utf-8', 50 'src' => $entry['src'], 51 '_data' => '', 52 ); 53 } else { 54 $event->data['script'][] = array( 55 'type' => 'text/javascript', 56 // 'charset' => 'utf-8', 57 '_data' => $entry['_data'], 58 ); 59 } 60 break; 61 } 62 } 63 return; 64 } 65} 66