xref: /dokuwiki/lib/plugins/styling/script.js (revision 86c97e91e4aa9ed17ed75df279181e4b61353c7c)
1/* DOKUWIKI:include_once iris.js */
2
3jQuery(function () {
4    // add popup option to admin page
5    var $styling_plugin = jQuery('#plugin__styling');
6    if ($styling_plugin.length) {
7        var $hl = $styling_plugin.find('h1').first();
8        var $btn = jQuery('<button class="btn">' + LANG.plugins.styling.popup + '</button>');
9        $hl.append($btn);
10
11        $btn.click(function (e) {
12            DokuCookie.setValue('styling_plugin', 1);
13            document.location.href = document.location.href.replace(/&?do=admin/, '');
14        });
15    }
16
17    // continue only if the styling Dialog is currently enabled
18    if (DokuCookie.getValue('styling_plugin') != 1) return;
19
20    var styling_timeout = null;
21
22    // create dialog element
23    var $dialog = jQuery(document.createElement('div'));
24    jQuery('body').append($dialog);
25
26    /**
27     * updates the current CSS with a new preview one
28     */
29    function styling_updateCSS() {
30        var now = new Date().getTime();
31        var $style = jQuery('link[rel=stylesheet][href*="lib/exe/css.php"]');
32        $style.attr('href', DOKU_BASE + 'lib/exe/css.php?preview=1&tseed=' + now);
33    }
34
35    // prepare the dialog
36    $dialog.dialog({
37        'autoOpen':      false,
38        'title':         LANG.plugins.styling.menu,
39        'width':         500,
40        'height':        500,
41        'position':      {'my': 'left bottom', 'at': 'left bottom-40', 'of': window},
42        'closeOnEscape': true,
43
44        // bring everything back to normal on close
45        'close': function (event, ui) {
46            // disable the styling plugin again
47            DokuCookie.setValue('styling_plugin', 0);
48            // reload
49            document.location.reload()
50        }
51    });
52
53
54    // load the dialog content and apply listeners
55    $dialog.load(
56        DOKU_BASE + 'lib/exe/ajax.php',
57        {
58            'call': 'plugin_styling',
59            'run':  'html',
60            'id':   JSINFO.id
61        },
62        function () {
63            // load the preview template
64            styling_updateCSS();
65
66            // open the dialog
67            $dialog.dialog('open');
68
69            // add the color picker  FIXME add saveAndUpdate to correct event
70            $dialog.find('.color').iris({});
71        }
72    );
73
74});
75