1 /* DOKUWIKI:include_once iris.js */
6 * Function to reload the preview styles in the main window
8 * @param {Window} target the main window
10 function applyPreview(target) {
12 var $style = target.jQuery('link[rel=stylesheet][href*="lib/exe/css.php"]');
13 $style.attr('href', '');
15 // append the loader screen
16 var $loader = target.jQuery('#plugin__styling_loader');
17 if (!$loader.length) {
18 $loader = target.jQuery('<div id="plugin__styling_loader">' + LANG.plugins.styling.loader + '</div>');
20 'position': 'absolute',
26 'background-color': '#fff',
30 'text-align': 'center',
34 target.jQuery('body').append($loader);
37 // load preview in main window (timeout works around chrome updating CSS weirdness)
38 setTimeout(function () {
39 var now = new Date().getTime();
40 $style.attr('href', DOKU_BASE + 'lib/exe/css.php?preview=1&tseed=' + now);
45 var $styling_plugin = jQuery('#plugin__styling');
47 // if we are not on the plugin page (either main or popup)
48 if (!$styling_plugin.length) {
49 // handle the preview cookie
50 if(DokuCookie.getValue('styling_plugin') == 1) {
53 return; // nothing more to do here
56 /* ---- from here on we're in the popup or admin page ---- */
58 // add the color picker
59 $styling_plugin.find('.color').iris({});
61 // add button on main page
62 if (!$styling_plugin.hasClass('ispopup')) {
63 var $form = $styling_plugin.find('form.styling').first();
64 var $btn = jQuery('<button>' + LANG.plugins.styling.popup + '</button>');
67 $btn.click(function (e) {
68 var windowFeatures = "menubar=no,location=no,resizable=yes,scrollbars=yes,status=false,width=500,height=500";
69 window.open(DOKU_BASE + 'lib/plugins/styling/popup.php', 'styling_popup', windowFeatures);
73 return; // we exit here if this is not the popup
76 /* ---- from here on we're in the popup only ---- */
78 // reload the main page on close
79 window.onunload = function(e) {
81 DokuCookie.setValue('styling_plugin', 0);
82 if(window.opener) window.opener.document.location.reload();
87 // don't reload on our own buttons
88 jQuery(':button').click(function(e){
92 // on first load apply preview
93 if(window.opener) applyPreview(window.opener);
95 // enable the preview cookie
96 DokuCookie.setValue('styling_plugin', 1);