dialog.js
2.02 KB
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
78
79
jQuery(function ($) {
"use strict";
var dialog = $('.js-wpml-translation-basket-dialog');
var openDialog = function (result) {
/** @namespace result.call_to_action */
/** @namespace result.ts_batch_link */
var hasAdditionalContent = typeof result.call_to_action !== 'undefined' || typeof result.ts_batch_link !== 'undefined';
var options = {
dialogClass: 'wpml-dialog otgs-ui-dialog',
width: 600,
title: dialog.data('title'),
modal: true,
closeOnEscape: false,
resizable: false,
draggable: false,
open: function () {
var dialogContent = dialog.find('.js-dialog-content');
var callToAction = dialogContent.find('.js-call-to-action');
var batchLink = dialogContent.find('.js-batch-link');
var batchLinkAnchor = batchLink.find('a');
if (callToAction && typeof result.call_to_action !== 'undefined') {
callToAction.text(result.call_to_action);
hasAdditionalContent = true;
}
if (batchLinkAnchor && typeof result.ts_batch_link !== 'undefined') {
batchLinkAnchor.attr('href', result.ts_batch_link.href);
batchLinkAnchor.text(result.ts_batch_link.text);
$(batchLinkAnchor).on('click', function () {
dialog.dialog('close');
});
batchLink.show();
hasAdditionalContent = true;
}
dialog.show();
repositionDialog();
}
};
if (hasAdditionalContent) {
dialog.dialog(options);
}
};
var repositionDialog = function() {
if (dialog.hasClass("ui-dialog-content") && dialog.dialog('isOpen')) {
var winH = $(window).height() - 180;
$(".otgs-ui-dialog .ui-dialog-content").css({
"max-height": winH
});
$(".otgs-ui-dialog").css({
"max-width": "95%"
});
dialog.dialog("option", "position", {
my: "center",
at: "center",
of: window
});
}
};
$(window).resize(repositionDialog);
var form = $('#translation-jobs-translators-form');
form.on('wpml-tm-basket-submitted', function(event, response) {
if (response.result) {
openDialog(response.result);
}
});
});