1<?php 2/** 3 * jQuery Plugin 4 * 5 * @license GPLv3 (http://www.gnu.org/licenses/gpl.html) 6 * @link http://www.dokuwiki.org/plugin:jquery 7 * @author Markus Birth <markus@birth-online.de> 8 */ 9 10if(!defined('DOKU_INC')) die(); 11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 12require_once(DOKU_PLUGIN.'action.php'); 13 14class action_plugin_jquery extends DokuWiki_Action_Plugin { 15 16 /** 17 * return some info 18 */ 19 function getInfo(){ 20 return confToHash(dirname(__FILE__).'/INFO.txt'); 21 } 22 23 /* 24 * plugin should use this method to register its handlers with the dokuwiki's event controller 25 */ 26 function register(&$controller) { 27 $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, '_addjquery'); 28 // $controller->register_hook('JQUERY_READY', 'BEFORE', $this, '_test'); 29 } 30 31 function _test(&$event, $param) { 32 $event->data[] = 'alert(\'Test successful!\');'; 33 } 34 35 // output jQuery.noConflict(); so that it doesn't break current $() functionality 36 function _addjquery(&$event, $param) { 37 // script.js is automagically used by js.php 38 $morecode = array(); 39 $addjs = ''; 40 trigger_event('JQUERY_READY', $morecode, NULL, false); 41 foreach ($morecode as $id=>$mc) { 42 $addjs .= '// BEGIN --- ' . $id . PHP_EOL; 43 $addjs .= $mc . PHP_EOL; 44 $addjs .= '// END --- ' . $id . PHP_EOL; 45 } 46 47 $fulljs = 'jQuery.noConflict();' . PHP_EOL; 48 if (!empty($addjs)) { 49 $fulljs .= 'jQuery(document).ready(function() {' . PHP_EOL; 50 $fulljs .= $addjs . PHP_EOL; 51 $fulljs .= '});' . PHP_EOL; 52 } 53 $event->data['script'][] = array( 54 'type' => 'text/javascript', 55 'charset' => 'utf-8', 56 '_data' => $fulljs, 57 ); 58 } 59 60}