xref: /dokuwiki/lib/plugins/styling/script.js (revision d634152e42ef1c75d899f021132ce0c2632257ac)
1/* DOKUWIKI:include_once iris.js */
2
3jQuery(function () {
4
5    var doreload = 1;
6
7    var $styling_plugin = jQuery('#plugin__styling');
8    if (!$styling_plugin.length) return;
9
10    // add the color picker
11    $styling_plugin.find('.color').iris({});
12
13    // add button on main page
14    if (!$styling_plugin.hasClass('ispopup')) {
15        var $form = $styling_plugin.find('form.styling').first();
16        var $btn = jQuery('<button>' + LANG.plugins.styling.popup + '</button>');
17        $form.prepend($btn);
18
19        $btn.click(function (e) {
20            var windowFeatures = "menubar=no,location=no,resizable=yes,scrollbars=yes,status=false,width=500,height=500";
21            window.open(DOKU_BASE + 'lib/plugins/styling/popup.php', 'styling', windowFeatures)
22            e.preventDefault();
23        }).wrap('<p></p>');
24        return;
25    }
26
27    // reload the main page on close
28    window.onunload = function(e) {
29        if(doreload) {
30            window.opener.document.location.reload();
31        }
32        return null;
33    };
34
35    // don't reload on our own buttons
36    jQuery('input[type=submit]').click(function(e){
37        doreload = false;
38    });
39
40    // remove style
41    var $style = window.opener.jQuery('link[rel=stylesheet][href*="lib/exe/css.php"]');
42    $style.attr('href', '');
43
44    // append the loader screen
45    $loader = window.opener.jQuery('#plugin__styling_loader');
46    if (!$loader.length) {
47        $loader = jQuery('<div id="plugin__styling_loader">' + LANG.plugins.styling.loader + '</div>');
48        $loader.css({
49            'position':         'absolute',
50            'width':            '100%',
51            'height':           '100%',
52            'top':              0,
53            'left':             0,
54            'z-index':          5000,
55            'background-color': '#fff',
56            'opacity':          '0.7',
57            'color':            '#000',
58            'font-size':        '2.5em',
59            'text-align':       'center',
60            'line-height':      1.5,
61            'padding-top':       '2em'
62        });
63        window.opener.jQuery('body').append($loader);
64    }
65
66    // load preview in main window (timeout works around chrome updating CSS weirdness)
67    window.setTimeout(function() {
68        var now = new Date().getTime();
69        $style.attr('href', DOKU_BASE + 'lib/exe/css.php?preview=1&tseed=' + now);
70    }, 500);
71
72
73});
74