summaryrefslogtreecommitdiff
path: root/plugins/jqueryui/jqueryui.php
blob: b28631ba7d9f1b94d8237e833ca4877b1949a915 (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
72
73
74
75
76
77
<?php

/**
 * jQuery UI
 *
 * Provide the jQuery UI library with according themes.
 *
 * @version 1.8.18
 * @author Cor Bosman <roundcube@wa.ter.net>
 * @author Thomas Bruederli <roundcube@gmail.com>
 */
class jqueryui extends rcube_plugin
{
    public $noajax = true;

    public function init()
    {
        $version = '1.8.18';

        $rcmail = rcmail::get_instance();
        $this->load_config();

        // include UI scripts
        $this->include_script("js/jquery-ui-$version.custom.min.js");

        // include UI stylesheet
        $skin = $rcmail->config->get('skin');
        $ui_map = $rcmail->config->get('jquery_ui_skin_map', array());
        $ui_theme = $ui_map[$skin] ? $ui_map[$skin] : $skin;

        if (file_exists($this->home . "/themes/$ui_theme/jquery-ui-$version.custom.css")) {
            $this->include_stylesheet("themes/$ui_theme/jquery-ui-$version.custom.css");
        }
        else {
            $this->include_stylesheet("themes/larry/jquery-ui-$version.custom.css");
        }

        if ($ui_theme == 'larry') {
            // patch dialog position function in order to fully fit the close button into the window
            $rcmail->output->add_script("jQuery.extend(jQuery.ui.dialog.prototype.options.position, {
                using: function(pos) {
                    var topOffset = jQuery(this).css(pos).offset().top - 12;
                    if (topOffset < 0) jQuery(this).css('top', pos.top - topOffset);
                }
            });", 'foot');
        }

        // jquery UI localization
        $jquery_ui_i18n = $rcmail->config->get('jquery_ui_i18n', array('datepicker'));
        if (count($jquery_ui_i18n) > 0) {
            $lang_l = str_replace('_', '-', substr($_SESSION['language'], 0, 5));
            $lang_s = substr($_SESSION['language'], 0, 2);
            foreach ($jquery_ui_i18n as $package) {
                if (file_exists($this->home . "/js/i18n/jquery.ui.$package-$lang_l.js")) {
                    $this->include_script("js/i18n/jquery.ui.$package-$lang_l.js");
                }
                else
                if (file_exists($this->home . "/js/i18n/jquery.ui.$package-$lang_s.js")) {
                    $this->include_script("js/i18n/jquery.ui.$package-$lang_s.js");
                }
            }
        }

        // Date format for datepicker
        $date_format = $rcmail->config->get('date_format', 'Y-m-d');
        $date_format = strtr($date_format, array(
                'y' => 'y',
                'Y' => 'yy',
                'm' => 'mm',
                'n' => 'm',
                'd' => 'dd',
                'j' => 'd',
        ));
        $rcmail->output->set_env('date_format', $date_format);
    }

}