summaryrefslogtreecommitdiff
path: root/lib/plugins/styling/script.js
blob: 6fc2b9043c79ee5f58a6cc6313080fb0a62a7aef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* DOKUWIKI:include_once iris.js */

jQuery(function () {

    var doreload = 1;

    var $styling_plugin = jQuery('#plugin__styling');
    if (!$styling_plugin.length) return;

    // add the color picker
    $styling_plugin.find('.color').iris({});

    // add button on main page
    if (!$styling_plugin.hasClass('ispopup')) {
        var $hl = $styling_plugin.find('h1').first();
        var $btn = jQuery('<button class="btn">' + LANG.plugins.styling.popup + '</button>');
        $hl.append($btn);

        $btn.click(function (e) {
            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;
    }

    // reload the main page on close
    window.onunload = function(e) {
        if(doreload) {
            window.opener.document.location.reload();
        }
        return null;
    };

    // don't reload on our own buttons
    jQuery('input[type=submit]').click(function(e){
        doreload = false;
    });

    // remove style
    var $style = window.opener.jQuery('link[rel=stylesheet][href*="lib/exe/css.php"]');
    $style.attr('href', '');

    // append the loader screen
    $loader = window.opener.jQuery('#plugin__styling_loader');
    if (!$loader.length) {
        $loader = jQuery('<div id="plugin__styling_loader">' + LANG.plugins.styling.loader + '</div>');
        $loader.css({
            'position':         'absolute',
            'width':            '100%',
            'height':           '100%',
            'top':              0,
            'left':             0,
            'z-index':          5000,
            'background-color': '#fff',
            'opacity':          '0.7',
            'color':            '#000',
            'font-size':        '40px',
            'text-align':       'center',
            'line-height':      '90px'
        });
        window.opener.jQuery('body').append($loader);
    }

    // load preview in main window (timeout works around chrome updating CSS weirdness)
    window.setTimeout(function() {
        var now = new Date().getTime();
        $style.attr('href', DOKU_BASE + 'lib/exe/css.php?preview=1&tseed=' + now);
    }, 500);


});