From 6667cd8743e57a4492cfbcbe1066ea48d444f7a2 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 26 Jun 2015 12:57:58 +0200 Subject: changed the whole thing to a real popup --- lib/plugins/styling/admin.php | 27 ++++++------- lib/plugins/styling/lang/en/lang.php | 4 +- lib/plugins/styling/popup.php | 28 ++++++++++++++ lib/plugins/styling/script.js | 73 +++++++----------------------------- 4 files changed, 56 insertions(+), 76 deletions(-) create mode 100644 lib/plugins/styling/popup.php (limited to 'lib/plugins') diff --git a/lib/plugins/styling/admin.php b/lib/plugins/styling/admin.php index 3c2ab577c..627efbd15 100644 --- a/lib/plugins/styling/admin.php +++ b/lib/plugins/styling/admin.php @@ -11,6 +11,8 @@ if(!defined('DOKU_INC')) die(); class admin_plugin_styling extends DokuWiki_Admin_Plugin { + public $ispopup = false; + /** * @return int sort number in admin menu */ @@ -25,15 +27,6 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { return true; } - /** - * @param string $language - * @return string - */ - public function getMenuText($language) { - $js = $this->getLang('js'); - return $js['menu']; - } - /** * handle the different actions (also called from ajax) */ @@ -49,17 +42,19 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { * Render HTML output, e.g. helpful text and a form */ public function html() { - echo '
'; - ptln('

'.$this->getMenuText('').'

'); - $this->form(false); + $class = 'nopopup'; + if($this->ispopup) $class = 'ispopup'; + + echo '
'; + ptln('

'.$this->getLang('menu').'

'); + $this->form(); echo '
'; } /** * Create the actual editing form - * @param boolean $isajax */ - public function form($isajax) { + public function form() { global $conf; global $ID; define('SIMPLE_TEST', 1); // hack, ideally certain functions should be moved out of css.php @@ -67,8 +62,8 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { $styleini = css_styleini($conf['template'], true); $replacements = $styleini['replacements']; - if($isajax) { - $target = wl($ID, array('do' => 'styling_plugin')); + if($this->ispopup) { + $target = DOKU_BASE.'lib/plugins/styling/popup.php'; } else { $target = wl($ID, array('do' => 'admin', 'page' => 'styling')); } diff --git a/lib/plugins/styling/lang/en/lang.php b/lib/plugins/styling/lang/en/lang.php index d100d4324..85ac0ec29 100644 --- a/lib/plugins/styling/lang/en/lang.php +++ b/lib/plugins/styling/lang/en/lang.php @@ -6,7 +6,9 @@ */ // menu entry for admin plugins -$lang['js']['menu'] = 'Template Style Settings'; +$lang['menu'] = 'Template Style Settings'; + + $lang['js']['popup'] = 'Open as Popup'; // custom language strings for the plugin diff --git a/lib/plugins/styling/popup.php b/lib/plugins/styling/popup.php new file mode 100644 index 000000000..eea4f3bfd --- /dev/null +++ b/lib/plugins/styling/popup.php @@ -0,0 +1,28 @@ +ispopup = true; + +// handle posts +$plugin->handle(); + +// output plugin in a very minimal template: +?> + + + <?php echo $plugin->getLang('menu') ?> + + + +
+ html() ?> +
+ + diff --git a/lib/plugins/styling/script.js b/lib/plugins/styling/script.js index 6dc4c84ed..8b4563986 100644 --- a/lib/plugins/styling/script.js +++ b/lib/plugins/styling/script.js @@ -1,74 +1,29 @@ /* DOKUWIKI:include_once iris.js */ jQuery(function () { - // add popup option to admin page + var $styling_plugin = jQuery('#plugin__styling'); - if ($styling_plugin.length) { + if(!$styling_plugin.length) return; + + + if (!$styling_plugin.hasClass('ispopup')) { var $hl = $styling_plugin.find('h1').first(); var $btn = jQuery(''); $hl.append($btn); $btn.click(function (e) { - DokuCookie.setValue('styling_plugin', 1); - document.location.href = document.location.href.replace(/&?do=admin/, ''); + var windowFeatures = "menubar=no,location=no,resizable=yes,scrollbars=yes,status=false,width=500,height=500"; + window.open(DOKU_BASE + 'lib/plugins/styling/popup.php', 'styling', windowFeatures) }); + return; } - // continue only if the styling Dialog is currently enabled - if (DokuCookie.getValue('styling_plugin') != 1) return; - - var styling_timeout = null; - - // create dialog element - var $dialog = jQuery(document.createElement('div')); - jQuery('body').append($dialog); - - /** - * updates the current CSS with a new preview one - */ - function styling_updateCSS() { - var now = new Date().getTime(); - var $style = jQuery('link[rel=stylesheet][href*="lib/exe/css.php"]'); - $style.attr('href', DOKU_BASE + 'lib/exe/css.php?preview=1&tseed=' + now); - } - - // prepare the dialog - $dialog.dialog({ - 'autoOpen': false, - 'title': LANG.plugins.styling.menu, - 'width': 500, - 'height': 500, - 'position': {'my': 'left bottom', 'at': 'left bottom-40', 'of': window}, - 'closeOnEscape': true, - - // bring everything back to normal on close - 'close': function (event, ui) { - // disable the styling plugin again - DokuCookie.setValue('styling_plugin', 0); - // reload - document.location.reload() - } - }); - - - // load the dialog content and apply listeners - $dialog.load( - DOKU_BASE + 'lib/exe/ajax.php', - { - 'call': 'plugin_styling', - 'run': 'html', - 'id': JSINFO.id - }, - function () { - // load the preview template - styling_updateCSS(); - - // open the dialog - $dialog.dialog('open'); + // add the color picker + $styling_plugin.find('.color').iris({}); - // add the color picker FIXME add saveAndUpdate to correct event - $dialog.find('.color').iris({}); - } - ); + // load preview in main window + var now = new Date().getTime(); + var $style = window.opener.jQuery('link[rel=stylesheet][href*="lib/exe/css.php"]'); + $style.attr('href', DOKU_BASE + 'lib/exe/css.php?preview=1&tseed=' + now); }); -- cgit v1.2.3