From 831864db51ec2c0cd8b86aaee1f1c160df91087d Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 17 May 2015 10:53:22 +0200 Subject: make styler work without JS as well --- lib/plugins/styler/action.php | 37 +++++++++++++++++++++++++++++++------ lib/plugins/styler/admin.php | 2 +- 2 files changed, 32 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/plugins/styler/action.php b/lib/plugins/styler/action.php index b7dd27cc4..b63cf3ec1 100644 --- a/lib/plugins/styler/action.php +++ b/lib/plugins/styler/action.php @@ -20,7 +20,7 @@ if(!defined('DOKU_INC')) die(); class action_plugin_styler extends DokuWiki_Action_Plugin { /** - * Registers a callback function for a given event + * Registers a callback functions * * @param Doku_Event_Handler $controller DokuWiki's event controller object * @return void @@ -28,12 +28,37 @@ class action_plugin_styler extends DokuWiki_Action_Plugin { public function register(Doku_Event_Handler $controller) { $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax'); $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_action'); + $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handle_header'); + } + + /** + * Adds the preview parameter to the stylesheet loading in non-js mode + * + * @param Doku_Event $event event object by reference + * @param mixed $param [the parameters passed as fifth argument to register_hook() when this + * handler was registered] + * @return void + */ + public function handle_header(Doku_Event &$event, $param) { + global $ACT; + global $INPUT; + if($ACT != 'admin' || $INPUT->str('page') != 'styler') return; + if(!auth_isadmin()) return; - // FIXME load preview style when on admin page + // set preview + $len = count($event->data['link']); + for($i = 0; $i < $len; $i++) { + if( + $event->data['link'][$i]['rel'] == 'stylesheet' && + strpos($event->data['link'][$i]['href'], 'lib/exe/css.php') !== false + ) { + $event->data['link'][$i]['href'] .= '&preview=1&tseed='.time(); + } + } } /** - * [Custom event handler which performs action] + * Updates the style.ini settings by passing it on to handle() of the admin component * * @param Doku_Event $event event object by reference * @param mixed $param [the parameters passed as fifth argument to register_hook() when this @@ -41,8 +66,8 @@ class action_plugin_styler extends DokuWiki_Action_Plugin { * @return void */ public function handle_action(Doku_Event &$event, $param) { - if(!auth_isadmin()) return; if($event->data != 'styler_plugin') return; + if(!auth_isadmin()) return; $event->data = 'show'; /** @var admin_plugin_styler $hlp */ @@ -51,7 +76,7 @@ class action_plugin_styler extends DokuWiki_Action_Plugin { } /** - * [Custom event handler which performs action] + * Create the style form in the floating Dialog * * @param Doku_Event $event event object by reference * @param mixed $param [the parameters passed as fifth argument to register_hook() when this @@ -60,8 +85,8 @@ class action_plugin_styler extends DokuWiki_Action_Plugin { */ public function handle_ajax(Doku_Event &$event, $param) { - if(!auth_isadmin()) return; if($event->data != 'plugin_styler') return; + if(!auth_isadmin()) return; $event->preventDefault(); $event->stopPropagation(); diff --git a/lib/plugins/styler/admin.php b/lib/plugins/styler/admin.php index dfc72373c..bb9426e12 100644 --- a/lib/plugins/styler/admin.php +++ b/lib/plugins/styler/admin.php @@ -26,7 +26,7 @@ class admin_plugin_styler extends DokuWiki_Admin_Plugin { } /** - * Should carry out any processing required by the plugin. + * handle the different actions (also called from ajax) */ public function handle() { global $INPUT; -- cgit v1.2.3