Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/aimogen-pro/scripts/moderation.js

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + "use strict";
2 + jQuery(document).ready(function(){
3 + function aiomaticLoading(btn){
4 + btn.attr('disabled','disabled');
5 + if(!btn.find('spinner').length){
6 + btn.append('<span class="spinner"></span>');
7 + }
8 + btn.find('.spinner').css('visibility','unset');
9 + }
10 + function aiomaticRmLoading(btn){
11 + btn.removeAttr('disabled');
12 + btn.find('.spinner').remove();
13 + }
14 + jQuery('#button-start-moderation').on('click', function (e){
15 + e.preventDefault();
16 + var error_message = false;
17 + var inputv = jQuery('#aiomatic_moderation_input');
18 + if(inputv.val() === ''){
19 + error_message = 'Please enter a text to moderate!';
20 + }
21 + if(error_message){
22 + alert(error_message)
23 + }
24 + else{
25 + aiomaticModerate(inputv.val());
26 + }
27 + return false;
28 + });
29 +
30 + function aiomaticModerate(text){
31 + var btn = jQuery('#button-start-moderation');
32 + var aiomatic_error_message = jQuery('#aiomatic-error-msg');
33 + var aiomatic_upload_success = jQuery('#aiomatic_moderation_success');
34 + var aiomatic_progress = jQuery('#aiomatic_progress');
35 + var data = {
36 + action: 'aiomatic_moderate_text',
37 + text: text,
38 + nonce: aiomatic_moderation_object.nonce
39 + };
40 + jQuery.ajax({
41 + url: aiomatic_moderation_object.ajax_url,
42 + data: data,
43 + type: 'POST',
44 + xhr: function () {
45 + var xhr = jQuery.ajaxSettings.xhr();
46 + xhr.upload.addEventListener("progress", function (evt) {
47 + if (evt.lengthComputable) {
48 + var percentComplete = evt.loaded / evt.total;
49 + aiomatic_progress.find('span').css('width', (Math.round(percentComplete * 100)) + '%');
50 + }
51 + }, false);
52 + return xhr;
53 + },
54 + beforeSend: function () {
55 + aiomatic_progress.find('span').css('width', '0');
56 + aiomatic_progress.show();
57 + aiomatic_progress.css('visibility','visible');
58 + aiomaticLoading(btn);
59 + aiomatic_error_message.hide();
60 + aiomatic_upload_success.hide();
61 + },
62 + success: function (res) {
63 + if (res.status === 'success') {
64 + aiomaticRmLoading(btn);
65 + aiomatic_progress.hide();
66 + aiomatic_upload_success.show();
67 + aiomatic_upload_success.css('visibility','visible');
68 + try {
69 + var obj = JSON.parse(res.data);
70 + var pretty = JSON.stringify(obj, undefined, 4);
71 + jQuery('#aiomatic_moderation_result').text(pretty);
72 + } catch (error) {
73 + console.error("An error occurred while moderation json: " + error);
74 + }
75 + } else {
76 + aiomaticRmLoading(btn);
77 + aiomatic_progress.find('small').html('Error');
78 + aiomatic_progress.addClass('aiomatic_error');
79 + aiomatic_error_message.html(res.msg);
80 + aiomatic_error_message.show();
81 + aiomatic_error_message.css('visibility','visible');
82 + }
83 + },
84 + error: function () {
85 + aiomaticRmLoading(btn);
86 + aiomatic_progress.addClass('aiomatic_error');
87 + aiomatic_progress.find('small').html('Error');
88 + aiomatic_error_message.html('Please try again');
89 + aiomatic_error_message.show();
90 + aiomatic_error_message.css('visibility','visible');
91 + }
92 + });
93 + }
94 + });