PluginProbe
Hostinger Tools / 1.9.1
Hostinger Tools v1.9.1
3.0.77 3.0.76 3.0.75 3.0.74 3.0.73 3.0.72 3.0.71 3.0.70 3.0.69 3.0.68 3.0.67 3.0.66 1.8.1 1.8.2 1.8.3 1.9.1 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.4 All 108 releases
hostinger / src / js / survey.js

survey.js in Hostinger Tools 1.9.1, at src/js/survey.js

93 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import * as Survey from 'survey-jquery'
2
3 ( function ( $ ) {
4 $( document ).on( 'ready', function () {
5 let type = 'ai_survey';
6 let surveyWrapper = $( '.hts-survey-wrapper' );
7
8 if ( surveyWrapper.hasClass( 'hts-woocommerce-csat' ) ) {
9 type = 'woo_survey';
10 }
11
12 if ( surveyWrapper.hasClass( 'hts-ai-onboarding-csat' ) ) {
13 type = 'ai_onboarding_survey';
14 }
15
16 if ( surveyWrapper.length ) {
17 $.ajax( {
18 url: ajaxurl,
19 method: 'POST',
20 data: {
21 action: 'hostinger_get_survey',
22 nonce: ajax_var.nonce,
23 type: type
24 },
25 dataType: 'json',
26 success: function ( data ) {
27 let questionsCount = $( '#hts-questionsLeft' );
28 surveyWrapper.show();
29 const survey = new Survey.Model( data );
30 survey.focusFirstQuestionAutomatic = false;
31 survey.render( "hostinger-feedback-survey" );
32 survey.onComplete.add( onSurveyComplete );
33 survey.onCurrentPageChanged.add( onPageChanged ); // Add this line
34 survey.render( "surveyElement" );
35
36 let answeredQuestions = 0;
37 let totalQuestions = survey.getAllQuestions().length;
38 if ( totalQuestions >= 2 ) {
39 questionsCount.show()
40 $( "#hts-allQuestions" ).html( totalQuestions );
41 }
42
43 function updateQuestionsLeft () {
44 var remaining = answeredQuestions + 1;
45 document.getElementById( "hts-currentQuestion" ).textContent = remaining;
46 }
47
48 function onPageChanged ( sender, options ) {
49 if ( options.isNextPage || options.isPrevPage ) {
50 answeredQuestions = survey.currentPageNo;
51 updateQuestionsLeft();
52 }
53 }
54
55 function onSurveyComplete ( sender ) {
56 const results = JSON.stringify( sender.data );
57 $( '#hts-questionsLeft' ).remove();
58 hostinger_submit_survey( results, type );
59 }
60
61 updateQuestionsLeft();
62
63 },
64 error: function ( xhr, status, error ) {
65 console.log( 'AJAX request failed: ' + error );
66 }
67 } );
68 }
69
70 function hostinger_submit_survey ( survey_answers, type ) {
71 $.ajax( {
72 url: ajaxurl,
73 method: 'POST',
74 data: {
75 action: 'hostinger_submit_survey',
76 nonce: ajax_var.nonce,
77 survey_results: survey_answers,
78 type: type
79 },
80 dataType: 'json',
81 success: function ( data ) {
82
83 },
84 error: function ( xhr, status, error ) {
85 console.log( 'AJAX request failed: ' + error );
86 }
87 } );
88 }
89
90 } );
91
92 } )( jQuery );
93