1/* DOKUWIKI:include_once iris.js */ 2 3jQuery(function () { 4 5 /** 6 * Function to reload the preview styles in the main window 7 * 8 * @param {Window} target the main window 9 */ 10 function applyPreview(target) { 11 // remove style 12 var $style = target.jQuery('link[rel=stylesheet][href*="lib/exe/css.php"]'); 13 $style.attr('href', ''); 14 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>'); 19 $loader.css({ 20 'position': 'absolute', 21 'width': '100%', 22 'height': '100%', 23 'top': 0, 24 'left': 0, 25 'z-index': 5000, 26 'background-color': '#fff', 27 'opacity': '0.7', 28 'color': '#000', 29 'font-size': '2.5em', 30 'text-align': 'center', 31 'line-height': 1.5, 32 'padding-top': '2em' 33 }); 34 target.jQuery('body').append($loader); 35 } 36 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); 41 }, 500); 42 } 43 44 var doreload = 1; 45 var $styling_plugin = jQuery('#plugin__styling'); 46 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) { 51 applyPreview(window); 52 } 53 return; // nothing more to do here 54 } 55 56 /* ---- from here on we're in the popup or admin page ---- */ 57 58 // add the color picker 59 $styling_plugin.find('.color').iris({}); 60 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>'); 65 $form.prepend($btn); 66 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); 70 e.preventDefault(); 71 e.stopPropagation(); 72 }).wrap('<p></p>'); 73 return; // we exit here if this is not the popup 74 } 75 76 /* ---- from here on we're in the popup only ---- */ 77 78 // reload the main page on close 79 window.onunload = function(e) { 80 if(doreload) { 81 window.opener.DokuCookie.setValue('styling_plugin', 0); 82 window.opener.document.location.reload(); 83 } 84 return null; 85 }; 86 87 // don't reload on our own buttons 88 jQuery(':button').click(function(e){ 89 doreload = false; 90 }); 91 92 // on first load apply preview 93 applyPreview(window.opener); 94 95 // enable the preview cookie 96 window.opener.DokuCookie.setValue('styling_plugin', 1); 97}); 98