PluginProbe
Hostinger Tools / 2.2.2
Hostinger Tools v2.2.2
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 / surveys.js

surveys.js in Hostinger Tools 2.2.2, at src/js/surveys.js

137 lines 3.8 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.hasClass( 'hts-affiliate-csat' ) ) {
17 type = 'affiliate_plugin_survey';
18 }
19
20 if ( surveyWrapper.hasClass( 'hts-prebuild-website-csat' ) ) {
21 type = 'prebuild_website_survey';
22 }
23
24 // Check if the cookie already exists
25 function checkCookie() {
26 var match = document.cookie.match(/(?:^|;)\s*HtsSkipSurvey\s*=\s*([^;]*)/);
27 var cookieValue = match ? match[1] : "";
28 return cookieValue !== undefined && cookieValue !== "";
29 }
30
31 $( ".hts-survey-wrapper .close-btn" ).click( function () {
32 var expirationTime = new Date();
33 expirationTime.setTime( expirationTime.getTime() + ( 86400 * 30 ) ) // 30 Days;
34 document.cookie = "HtsSkipSurvey=1; expires=" + expirationTime.toUTCString() + "; path=/";
35
36 $.ajax( {
37 url: ajaxurl,
38 method: 'POST',
39 data: {
40 action: 'hostinger_hide_survey',
41 nonce: hostingerContainer.nonce,
42 },
43 dataType: 'json',
44 success: function ( data ) {
45 surveyWrapper.hide();
46 },
47 error: function ( xhr, status, error ) {
48 console.log( 'AJAX request failed: ' + error );
49 }
50 } );
51 } );
52
53 if ( surveyWrapper.length && ! checkCookie() ) {
54 $.ajax( {
55 url: ajaxurl,
56 method: 'POST',
57 data: {
58 action: 'hostinger_get_survey',
59 nonce: hostingerContainer.nonce,
60 type: type
61 },
62 dataType: 'json',
63 success: function ( data ) {
64
65 if ( data.success === false) return;
66
67 let questionsCount = $( '#hts-questionsLeft' );
68 surveyWrapper.show();
69 const survey = new Survey.Model( data );
70 survey.focusFirstQuestionAutomatic = false;
71 survey.render( "hostinger-feedback-survey" );
72 survey.onComplete.add( onSurveyComplete );
73 survey.onCurrentPageChanged.add( onPageChanged ); // Add this line
74 survey.render( "surveyElement" );
75
76 let answeredQuestions = 0;
77 let totalQuestions = survey.getAllQuestions().length;
78 if ( totalQuestions >= 2 ) {
79 questionsCount.show()
80 $( "#hts-allQuestions" ).html( totalQuestions );
81 }
82
83 function updateQuestionsLeft () {
84 var remaining = answeredQuestions + 1;
85 document.getElementById( "hts-currentQuestion" ).textContent = remaining;
86 }
87
88 function onPageChanged ( sender, options ) {
89 if ( options.isNextPage || options.isPrevPage ) {
90 answeredQuestions = survey.currentPageNo;
91 updateQuestionsLeft();
92 }
93 }
94
95 function onSurveyComplete ( sender ) {
96 const results = JSON.stringify( sender.data );
97 $( '#hts-questionsLeft' ).remove();
98 hostinger_submit_survey( results, type );
99 }
100
101 updateQuestionsLeft();
102 },
103 error: function ( xhr, status, error ) {
104 console.log( 'AJAX request failed: ' + error );
105 }
106 } );
107 }
108
109 function hostinger_submit_survey ( survey_answers, type ) {
110 $.ajax( {
111 url: ajaxurl,
112 method: 'POST',
113 data: {
114 action: 'hostinger_submit_survey',
115 nonce: hostingerContainer.nonce,
116 survey_results: survey_answers,
117 type: type
118 },
119 dataType: 'json',
120 success: function ( data ) {
121 setTimeout(function ( ) {
122 var expirationTime = new Date();
123 expirationTime.setTime( expirationTime.getTime() + ( 86400 ) ); // 24Hours;
124 document.cookie = "HtsSkipSurvey=1; expires=" + expirationTime.toUTCString() + "; path=/";
125 surveyWrapper.hide('300');
126 },1000);
127 },
128 error: function ( xhr, status, error ) {
129 console.log( 'AJAX request failed: ' + error );
130 }
131 } );
132 }
133
134 } );
135
136 } )( jQuery );
137