1jQuery(function () {
2    jQuery('.plugin_feedback')
3        .show()
4        .click(function (e) {
5            e.preventDefault();
6
7            var getPageId = function() {
8                if (window.JSINFO.plugins.feedback.isMedia) {
9                    return window.JSINFO.plugins.feedback.mediaID;
10                }
11                return window.JSINFO.id;
12            };
13
14            // create the dialog frame
15            var $dialog = jQuery(
16                '<div>' +
17                    '<form>' +
18                    '<textarea></textarea>' +
19                    '</form>' +
20                    '</div>');
21
22            // initialize the dialog functionality
23            $dialog.dialog({
24                title: LANG.plugins.feedback.title,
25                width: 400,
26                height: 300,
27                dialogClass: 'plugin_feedbackdialog',
28                buttons: [
29                    {
30                        text: LANG.plugins.feedback.cancel,
31                        click: function () {
32                            $dialog.dialog("close");
33                        }
34                    },
35                    {
36                        text: LANG.plugins.feedback.submit,
37                        click: function () {
38                            var self = this;
39                            var text = $dialog.find('textarea').val();
40                            if (!text) return;
41
42                            // switch button set and empty form
43                            $dialog.html('');
44                            $dialog.dialog('option', 'buttons',
45                                [
46                                    {
47                                        text: LANG.plugins.feedback.close,
48                                        click: function () {
49                                            $dialog.dialog("close");
50                                        }
51                                    }
52                                ]
53                            );
54
55                            // post the data
56                            jQuery.post(
57                                DOKU_BASE + 'lib/exe/ajax.php',
58                                {
59                                    call: 'plugin_feedback',
60                                    feedback: text,
61                                    id: getPageId(),
62                                    media: !!window.JSINFO.plugins.feedback.isMedia
63                                },
64                                // display thank you message
65                                function (result) {
66                                    $dialog.html(result);
67                                }
68                            );
69                        }
70                    }
71                ],
72                // remove HTML from DOM again
73                close: function () {
74                    jQuery(this).remove();
75                }
76            });
77
78
79        });
80});
81