Skip to content
Snippets Groups Projects
Commit d071b66c authored by Andreas Gohr's avatar Andreas Gohr
Browse files

autopreview in styler plugin

parent a93f9a7a
No related branches found
No related tags found
No related merge requests found
...@@ -91,11 +91,16 @@ class action_plugin_styler extends DokuWiki_Action_Plugin { ...@@ -91,11 +91,16 @@ class action_plugin_styler extends DokuWiki_Action_Plugin {
$event->stopPropagation(); $event->stopPropagation();
global $ID; global $ID;
global $INPUT;
$ID = getID(); $ID = getID();
/** @var admin_plugin_styler $hlp */ /** @var admin_plugin_styler $hlp */
$hlp = plugin_load('admin', 'styler'); $hlp = plugin_load('admin', 'styler');
$hlp->form(true); if($INPUT->str('run') == 'preview') {
$hlp->run_preview();
} else {
$hlp->form(true);
}
} }
} }
......
...@@ -87,13 +87,13 @@ class admin_plugin_styler extends DokuWiki_Admin_Plugin { ...@@ -87,13 +87,13 @@ class admin_plugin_styler extends DokuWiki_Admin_Plugin {
echo '<tr>'; echo '<tr>';
echo '<td>'.$name.'</td>'; echo '<td>'.$name.'</td>';
echo '<td><input name="tpl['.hsc($key).']" value="'.hsc($value).'" '.$this->colorClass($key).' />'; echo '<td><input type="text" name="tpl['.hsc($key).']" value="'.hsc($value).'" '.$this->colorClass($key).' />';
echo '</tr>'; echo '</tr>';
} }
echo '</table>'; echo '</table>';
echo '<p class="center">'; echo '<p class="center">';
echo '<input type="submit" name="run[preview]" value="'.$this->getLang('btn_preview').'">'; echo '<input type="submit" name="run[preview]" class="btn_preview" value="'.$this->getLang('btn_preview').'">';
echo '<input type="submit" name="run[reset]" value="'.$this->getLang('btn_reset').'">'; #FIXME only if preview.ini exists echo '<input type="submit" name="run[reset]" value="'.$this->getLang('btn_reset').'">'; #FIXME only if preview.ini exists
echo '</p>'; echo '</p>';
...@@ -139,9 +139,9 @@ class admin_plugin_styler extends DokuWiki_Admin_Plugin { ...@@ -139,9 +139,9 @@ class admin_plugin_styler extends DokuWiki_Admin_Plugin {
} }
/** /**
* saves the preview.ini * saves the preview.ini (alos called from ajax directly)
*/ */
protected function run_preview() { public function run_preview() {
global $conf; global $conf;
$ini = $conf['cachedir'].'/preview.ini'; $ini = $conf['cachedir'].'/preview.ini';
io_saveFile($ini, $this->makeini()); io_saveFile($ini, $this->makeini());
......
...@@ -7,43 +7,86 @@ jQuery(function () { ...@@ -7,43 +7,86 @@ jQuery(function () {
document.location.href = document.location.href.replace(/do=admin/, ''); document.location.href = document.location.href.replace(/do=admin/, '');
} }
// The Styler Dialog is currently enabled, display it here and apply the preview styles // continue only if the Styler Dialog is currently enabled
if (DokuCookie.getValue('styler_plugin') == 1) { if (DokuCookie.getValue('styler_plugin') != 1) return;
// load dialog
var $dialog = jQuery(document.createElement('div')); var styler_timeout = null;
jQuery('body').append($dialog);
$dialog.load( // create dialog element
DOKU_BASE + '/lib/exe/ajax.php', var $dialog = jQuery(document.createElement('div'));
{ jQuery('body').append($dialog);
'call': 'plugin_styler',
'id': JSINFO.id
}, /**
function () { * updates the current CSS with a new preview one
// load the preview template */
var now = new Date().getTime(); function styler_updateCSS() {
var $style = jQuery('link[rel=stylesheet][href*="lib/exe/css.php"]'); var now = new Date().getTime();
$style.attr('href', DOKU_BASE + 'lib/exe/css.php?preview=1&tseed=' + now); var $style = jQuery('link[rel=stylesheet][href*="lib/exe/css.php"]');
$style.attr('href', DOKU_BASE + 'lib/exe/css.php?preview=1&tseed=' + now);
// open the dialog }
var $dlg = $dialog.dialog({
'title': LANG.plugins.styler.menu, /**
'width': 500, * save current values and reload preview (debounced)
'height': 500, */
'top': 50, function styler_saveAndUpdate() {
'position': { 'my': 'left bottom', 'at': 'left bottom', 'of': window }, if (styler_timeout) window.clearTimeout(styler_timeout);
// bring everything back to normal styler_timeout = window.setTimeout(function () {
'close': function (event, ui) { styler_timeout = null;
// disable the styler plugin again
DokuCookie.setValue('styler_plugin', 0); var params = $dialog.find('input[type=text]').serializeArray();
// reload params[params.length] = { name: 'call', value: 'plugin_styler'};
document.location.reload() params[params.length] = {name: 'run', value: 'preview'};
}
}); jQuery.post(
DOKU_BASE + '/lib/exe/ajax.php',
jQuery('.styler .color').iris({ params,
}); styler_updateCSS
);
} }, 500);
);
} }
// load the dialog content and apply listeners
$dialog.load(
DOKU_BASE + '/lib/exe/ajax.php',
{
'call': 'plugin_styler',
'run': 'html',
'id': JSINFO.id
},
function () {
// load the preview template
styler_updateCSS();
// open the dialog
$dialog.dialog({
'title': LANG.plugins.styler.menu,
'width': 500,
'height': 500,
'top': 50,
'position': { 'my': 'left bottom', 'at': 'left bottom', 'of': window },
// bring everything back to normal
'close': function (event, ui) {
// disable the styler plugin again
DokuCookie.setValue('styler_plugin', 0);
// reload
document.location.reload()
}
});
// we don't need the manual preview in JS mode
$dialog.find('.btn_preview').hide();
// add the color picker FIXME add saveAndUpdate to correct event
$dialog.find('.color').iris({ });
// listen to keyup events
$dialog.find('input[type=text]').keyup(function () {
console.log('change');
styler_saveAndUpdate();
});
}
);
}); });
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment