PluginProbe
Survey Maker by AYS / 5.2.4.1
Survey Maker by AYS v5.2.4.1
5.2.4.1 5.2.4.0 5.2.3.9 5.2.3.8 5.2.3.7 5.2.3.6 5.2.3.5 5.2.3.4 5.2.3.3 5.2.3.2 5.2.3.1 5.2.3.0 5.2.2.9 5.2.2.8 5.2.2.7 5.2.2.6 5.2.2.5 5.2.2.4 5.2.2.3 5.2.2.2 5.2.2.1 5.2.2.0 5.2.1.9 5.2.1.8 5.2.0.8 All 154 releases
survey-maker / public / js / survey-maker-public-plugin.js

survey-maker-public-plugin.js in Survey Maker by AYS 5.2.4.1, at public/js/survey-maker-public-plugin.js

2,652 lines 130.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function($) {
2 'use strict';
3
4 var defaults = {
5 mode: 'lg-slide',
6 cssEasing: 'ease',
7 easing: 'linear',
8 speed: 600,
9 height: '100%',
10 width: '100%',
11 addClass: '',
12 galleryId: 1
13 };
14
15 function AysSurveyPlugin(element, options){
16 this.el = element;
17 this.$el = $(element);
18 this.htmlClassPrefix = 'ays-survey-';
19 this.dbOptionsPrefix = 'survey_';
20 this.ajaxAction = 'ays_survey_ajax';
21 this.dbOptions = undefined;
22 this.QuizQuestionsOptions = undefined;
23 this.uniqueId;
24 this.surveyId;
25 this.sectionsContainer;
26 this.sections;
27 this.current_fs;
28 this.next_fs;
29 this.previous_fs; //fieldsets
30 this.left;
31 this.opacity;
32 this.scale; //fieldset properties which we will animate
33 this.animating;
34 this.percentAnimate; //flag to prevent quick multi-click glitches
35 this.explanationTimeout;
36 this.confirmBeforeUnload = false;
37 // new added email pattern
38 this.emailValidatePattern = /^[a-zA-Z0-9._+-]+@[a-zA-Z0-9._-]+\.\w{2,}$/;
39 // phone pattern
40 this.phoneValidatePattern = /^[0-9)(+ -]+$/;
41 // old email pattern(works slower)
42 // this.emailValidatePattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
43
44 this.init();
45
46 return this;
47 }
48
49 AysSurveyPlugin.prototype.init = function() {
50 var _this = this;
51 _this.uniqueId = _this.$el.data('id');
52
53 if( typeof window.aysSurveyOptions != 'undefined' ){
54 _this.dbOptions = JSON.parse( atob( window.aysSurveyOptions[ _this.uniqueId ] ) );
55 }
56
57 if( _this.$el.hasClass( _this.htmlClassPrefix + 'blocked-content' ) ){
58 _this.blockedContent( true );
59 return false;
60 }
61
62 _this.setup();
63 _this.blockedContent( false );
64 _this.setEvents();
65
66 if(_this.dbOptions.survey_enable_survey_start_loader){
67 _this.$el.find('.ays-survey-wait-loading-loader').css("display" , "none");
68 }
69 // _this.share();
70 _this.keydown();
71 };
72
73 AysSurveyPlugin.prototype.setup = function(e) {
74 var _this = this;
75 _this.sectionsContainer = _this.$el.find('.' + _this.htmlClassPrefix + 'sections');
76 _this.sections = _this.sectionsContainer.find('.' + _this.htmlClassPrefix + 'section');
77
78 _this.sections.first().addClass('active-section');
79
80 var questionTypeText = $(document).find('textarea.' + _this.htmlClassPrefix + 'question-input-textarea');
81 autosize(questionTypeText);
82
83 var questionTypeSelect = $(document).find('.' + _this.htmlClassPrefix + 'question-select');
84
85 questionTypeSelect.each(function(){
86 $(this).aysDropdown({
87 duration: 150,
88 transition: 'scale'
89 });
90 });
91
92 if( _this.dbOptions.options ){
93 if( _this.dbOptions.options.survey_enable_info_autofill ){
94 var checkAutoFill = _this.dbOptions.options.survey_enable_info_autofill.length > 0 && _this.dbOptions.options.survey_enable_info_autofill == "on" ? true : false;
95 if(checkAutoFill){
96 var form = _this.$el.find('form');
97 var data = form.serializeFormJSON();
98 data.action = _this.ajaxAction;
99 data.function = 'ays_survey_get_user_information';
100 data.end_date = _this.GetFullDateTime();
101 data.unique_id = _this.uniqueId;
102 data._ajax_nonce = aysSurveyMakerAjaxPublic.ajaxNonce;
103 data.nonce = aysSurveyMakerAjaxPublic.autofill_nonce;
104 _this.aysAutofillData(data , _this.$el);
105 }
106 }
107 }
108 }
109
110 AysSurveyPlugin.prototype.setEvents = function(e) {
111 var _this = this;
112
113 _this.aysNext();
114 _this.aysFinish();
115 _this.aysSurveyPreviewNoticeCopy();
116
117 _this.$el.on('click', '.' + _this.htmlClassPrefix + 'start-button', function(e){
118 _this.start(e);
119 });
120
121 _this.$el.on('click', '.' + _this.htmlClassPrefix + 'section-button.ays-check-survey-password', function(e){
122 var passwordSurvey = $(this).parents('.ays-survey-section,.ays-survey-chat-container').find("input.ays-survey-password").val();
123 // var activPsw = _this.dbOptions.options.survey_generated_passwords.survey_active_passwords;
124 var activPsw = new Array();
125
126 var form = $(this).parents('form');
127 if( _this.checkSurveyPassword( passwordSurvey, true ) !== false ){
128 // if(_this.dbOptions.options.survey_password_type == 'generated_password'){
129 // if( _this.dbOptions.options.survey_enable_password && activPsw.length != 0 ){
130 // var userData;
131 // userData = form.serializeFormJSON()
132 // userData.action = _this.ajaxAction;
133 // userData.function = 'ays_survey_used_password_ajax';
134 // userData.userGeneratedPassword = passwordSurvey;
135 // userData.uniqueId = _this.uniqueId;
136
137 // $.ajax({
138 // url: window.aysSurveyMakerAjaxPublic.ajaxUrl,
139 // method: 'post',
140 // dataType: 'json',
141 // data: userData,
142 // success: function(response){
143 // if(response.status){
144
145 // }
146 // }
147 // });
148 // }
149 // }
150 }else{
151 return false;
152 }
153 $(this).parents('.ays-survey-section').removeClass('active-section');
154 $(this).parents('.ays-survey-section').next().addClass('active-section');
155 var chatModeMainParent = $(this).parents('.ays-survey-chat-container')
156 chatModeMainParent.find('.ays-survey-chat-content').css("display", "block");
157 chatModeMainParent.find('.ays-survey-section-password-content').css("display", "none");
158
159 if( _this.$el.find("div.ays-survey-section[data-id]").length === 1 ){
160 $(this).parents('.ays-survey-section').next().find('.' + _this.htmlClassPrefix + 'section-button.' + _this.htmlClassPrefix + 'finish-button').removeClass( _this.htmlClassPrefix + 'display-none' );
161 $(this).parents('.ays-survey-section').next().find('.' + _this.htmlClassPrefix + 'section-button.' + _this.htmlClassPrefix + 'next-button').addClass( _this.htmlClassPrefix + 'display-none' );
162 }
163
164 });
165
166 _this.$el.on('click', '.' + _this.htmlClassPrefix + 'answer-label-other input', function(){
167 $(this).parents('.' + _this.htmlClassPrefix + 'answer').find('.' + _this.htmlClassPrefix + 'answer-other-input').focus();
168 _this.confirmBeforeUnload = true;
169 });
170
171 _this.$el.on('input', '.' + _this.htmlClassPrefix + 'answer-other-input', function(){
172 if( $(this).parents('.' + _this.htmlClassPrefix + 'question').data('type') == 'checkbox' ){
173 var checkedCount = $(this).parents('.' + _this.htmlClassPrefix + 'question-answers').find('.' + _this.htmlClassPrefix + 'answer input[type="checkbox"][name^="' + _this.htmlClassPrefix + 'answers"]:checked').length;
174 var questionId = $(this).parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-id').val();
175
176 questionId = parseInt( questionId );
177 var options = _this.dbOptions[ _this.dbOptionsPrefix + 'checkbox_options' ][questionId];
178 if(typeof options != "undefined"){
179 if( options.enable_max_selection_count === true ){
180 if( !(options.max_selection_count != null && (options.max_selection_count < checkedCount + 1)) ){
181 $(this).parents('.' + _this.htmlClassPrefix + 'answer').find('.' + _this.htmlClassPrefix + 'answer-label-other input').prop('checked', true);
182 }
183 }
184 else{
185 $(this).parents('.' + _this.htmlClassPrefix + 'answer').find('.' + _this.htmlClassPrefix + 'answer-label-other input').prop('checked', true);
186 }
187 }
188 }else{
189 $(this).parents('.' + _this.htmlClassPrefix + 'answer').find('.' + _this.htmlClassPrefix + 'answer-label-other input').prop('checked', true);
190 }
191 _this.confirmBeforeUnload = true;
192 });
193
194 _this.sectionsContainer.on('change', 'input[type="radio"][name^="' + _this.htmlClassPrefix + 'answers"]', function(){
195 var check_required = $(this).parents('.' + _this.htmlClassPrefix + 'question').data('required');
196
197 if(!check_required){
198 $(this).parents('.' + _this.htmlClassPrefix + 'question-answers').find('.' + _this.htmlClassPrefix + 'answer-clear-selection-container').addClass('in');
199 $(this).parents('.' + _this.htmlClassPrefix + 'question-answers').find('.' + _this.htmlClassPrefix + 'answer-clear-selection-container').removeClass('out');
200 $(this).parents('.' + _this.htmlClassPrefix + 'question-answers').find('.' + _this.htmlClassPrefix + 'answer-clear-selection-container').removeClass(_this.htmlClassPrefix + 'visibility-none');
201 }
202 _this.confirmBeforeUnload = true;
203 });
204
205 _this.sectionsContainer.on('click', 'input[type="checkbox"][name^="' + _this.htmlClassPrefix + 'answers"]', function(){
206 var questionBox = $(this).parents('.' + _this.htmlClassPrefix + 'question');
207 var checkedCount = $(this).parents('.' + _this.htmlClassPrefix + 'question-answers').find('.' + _this.htmlClassPrefix + 'answer input[type="checkbox"][name^="' + _this.htmlClassPrefix + 'answers"]:checked').length;
208 var allVotesCount = $(this).parents('.' + _this.htmlClassPrefix + 'question-answers').find('.' + _this.htmlClassPrefix + 'answer input[type="checkbox"][name^="' + _this.htmlClassPrefix + 'answers"]').length;
209 var questionId = questionBox.find('.' + _this.htmlClassPrefix + 'question-id').val();
210 questionId = parseInt( questionId );
211
212
213 var options = _this.dbOptions[ _this.dbOptionsPrefix + 'checkbox_options' ][questionId];
214 var minVotes = options.min_selection_count;
215
216 var maxVotes = options.max_selection_count != null ? options.max_selection_count : 0;
217 if( options.enable_max_selection_count === true ){
218 var checkVotesCount = (maxVotes != null || minVotes != null) ? true : false;
219 if(checkVotesCount){
220 if(maxVotes <= 0 ){
221 maxVotes = allVotesCount;
222 }
223 if( maxVotes < checkedCount ){
224 var errorMessage = '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">';
225 errorMessage += '<span>' + aysSurveyLangObj.maximumVotes + ' ' + maxVotes + '</span>';
226 questionBox.find('.' + _this.htmlClassPrefix + 'votes-count-validation-error').html(errorMessage);
227
228 questionBox.find('.' + _this.htmlClassPrefix + 'votes-count-validation-error').show();
229 setTimeout(function() {
230 questionBox.find('.' + _this.htmlClassPrefix + 'votes-count-validation-error').hide();
231 }, 3000);
232 return false;
233 }
234 if(minVotes > maxVotes){
235 minVotes = maxVotes;
236 }
237 if(minVotes > allVotesCount){
238 minVotes = allVotesCount;
239 }
240 if(minVotes <= checkedCount){
241 questionBox.find('.' + _this.htmlClassPrefix + 'votes-count-validation-error').hide();
242 }
243 else{
244 var errorMessage = '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">';
245 errorMessage += '<span>' + aysSurveyLangObj.minimumVotes + ' ' + minVotes + '</span>';
246 questionBox.find('.' + _this.htmlClassPrefix + 'votes-count-validation-error').html(errorMessage);
247 questionBox.find('.' + _this.htmlClassPrefix + 'votes-count-validation-error').show();
248 }
249 }
250 }
251 });
252
253 _this.sectionsContainer.on('click', '.' + _this.htmlClassPrefix + 'answer-clear-selection-container .' + _this.htmlClassPrefix + 'button', function(){
254 var clearContainer = $(this).parents('.' + _this.htmlClassPrefix + 'answer-clear-selection-container');
255 $(this).parents('.' + _this.htmlClassPrefix + 'question-answers').find('input[type="radio"][name^="' + _this.htmlClassPrefix + 'answers"]').prop('checked', false);
256 clearContainer.removeClass('in');
257 clearContainer.addClass('out');
258
259 if( $(this).parents('.' + _this.htmlClassPrefix + 'question-answers').find('.' + _this.htmlClassPrefix + 'answer-star').length > 0 ){
260 $(this).parents('.' + _this.htmlClassPrefix + 'question-answers').find('.' + _this.htmlClassPrefix + 'answer-star .' + _this.htmlClassPrefix + 'answer-label').each(function() {
261 $(this).find('i').removeClass('fa-star').addClass('fa-star-o').removeAttr('style');
262 $(this).removeClass('active-answer');
263 });
264 }
265
266 setTimeout(function(){
267 clearContainer.addClass(_this.htmlClassPrefix + 'visibility-none');
268 }, 200);
269 });
270
271 var active = false;
272 _this.$el.on('mouseout', '.' + _this.htmlClassPrefix + 'answer-star',function(){
273 var surveyColor = _this.dbOptions[ _this.dbOptionsPrefix + 'text_color' ];
274 var surveyActiveColor = _this.dbOptions[ _this.dbOptionsPrefix + 'color' ];
275 var allRateLabels = $(this).find('label');
276
277 if($(this).find(".fa-star").length !== 0) {
278 active = true;
279 }
280
281 if (active) {
282 var index = -1;
283 allRateLabels.each(function() {
284 if ($(this).hasClass('active-answer')) {
285 index = allRateLabels.index(this);
286 }
287 });
288 for (var i = 0; i < allRateLabels.length; i++) {
289 if( _this.dbOptions[ _this.dbOptionsPrefix+'is_business'] ){
290 if (i > index) {
291 allRateLabels.eq(i).find('i').css('color','#ffffff');
292 } else {
293 allRateLabels.eq(i).find('i').css('color','#fc0');
294 }
295 }else{
296 if (i > index) {
297 allRateLabels.eq(i).find('i').removeClass('fa-star').addClass('fa-star-o');
298 } else {
299 allRateLabels.eq(i).find('i').removeClass('fa-star-o').addClass('fa-star');
300 }
301 }
302 }
303 }else{
304 allRateLabels.each(function() {
305 if( _this.dbOptions[ _this.dbOptionsPrefix+'is_business'] ){
306 $(this).find('i').css('color','#ffffff');
307 }
308 else{
309 $(this).find('i').removeClass('fa-star').addClass('fa-star-o');
310 }
311 });
312 }
313 });
314
315 _this.$el.on('click', '.' + _this.htmlClassPrefix + 'answer-star .'+ _this.htmlClassPrefix +'answer-label',function(){
316 $(this).parents('.' + _this.htmlClassPrefix + 'question').removeClass('ays-has-error');
317 $(this).parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-validation-error').html('');
318
319 $(this).parent().find('label').each(function() {
320 $(this).removeClass('active-answer');
321 });
322 $(this).addClass('active-answer');
323 active = true;
324 });
325
326 _this.$el.on('mouseover', '.'+ _this.htmlClassPrefix + 'answer-star .'+ _this.htmlClassPrefix +'answer-label',function(){
327 var surveyColor = _this.dbOptions[ _this.dbOptionsPrefix + 'color' ];
328 var allRateLabels = $(this).parent().find('label');
329 var index = allRateLabels.index(this);
330 allRateLabels.each(function() {
331 if( _this.dbOptions[ _this.dbOptionsPrefix+'is_business'] ){
332 $(this).find('i').css('color','#ffffff');
333 }
334 else{
335 $(this).find('i').removeClass('fa-star').addClass('fa-star-o');
336 }
337
338 });
339 for (var i = 0; i <= index; i++) {
340 if( _this.dbOptions[ _this.dbOptionsPrefix+'is_business'] ){
341 allRateLabels.eq(i).find('i').css('color','#fc0');
342 }
343 else{
344 allRateLabels.eq(i).find('i').removeClass('fa-star-o').addClass('fa-star');
345 }
346 }
347 });
348
349 if( _this.dbOptions[ _this.dbOptionsPrefix + 'enable_leave_page' ] ){
350 window.onbeforeunload = function (e) {
351 if( _this.confirmBeforeUnload === true ){
352 return true;
353 }else{
354 return null;
355 }
356 }
357 }
358
359 _this.$el.on('input', '.' + _this.htmlClassPrefix + 'question-email-input', function(){
360 $(this).parents('.' + _this.htmlClassPrefix + 'question').removeClass('ays-has-error');
361 if($(this).val() != ''){
362 if (!(_this.emailValidatePattern.test($(this).val()))) {
363 var errorMessage = '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">';
364 errorMessage += '<span>' + surveySanitizeSpecificContent(aysSurveyLangObj.emailValidationError) + '</span>';
365 $(this).parents('.' + _this.htmlClassPrefix + 'question').addClass('ays-has-error');
366 $(this).parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-validation-error').html(errorMessage);
367 $(this).parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-validation-error').show();
368 }else{
369 $(this).parents('.' + _this.htmlClassPrefix + 'question').removeClass('ays-has-error');
370 $(this).parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-validation-error').hide();
371 $(this).parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-validation-error').html('');
372 }
373 }else{
374 $(this).parents('.' + _this.htmlClassPrefix + 'question').removeClass('ays-has-error');
375 $(this).parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-validation-error').hide();
376 $(this).parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-validation-error').html('');
377 }
378 });
379
380 _this.$el.on('click', '.' + _this.htmlClassPrefix + 'restart-button', function(){
381 window.location.reload();
382 });
383
384 // Social buttons
385 _this.$el.find(".ays-survey-share-btn").on("click" , function(e){
386 e.preventDefault();
387 var wWidth = 650,
388 wHeight = 450;
389 var windowOptions = 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,width='+wWidth+',height='+wHeight+',top='+(screen.height/2-wHeight/2)+',left='+(screen.width/2-wWidth/2);
390 window.open(this.href, "_blank", windowOptions);
391 });
392
393 // Survey full screen
394 _this.$el.find('.ays-survey-close-full-screen, .ays-survey-open-full-screen').on('click', function() {
395 _this.toggleFullscreen(_this.el);
396 });
397 _this.aysSurveyFullScreenDeactivateAll();
398
399 // Text limit character/word
400 _this.$el.find('textarea.ays-survey-check-word-limit, input.ays-survey-check-word-limit').on('keyup keypress', function(e) {
401 var currentQuestion = $(this).parents(".ays-survey-question");
402 var currentquestionId = currentQuestion.find('.' + _this.htmlClassPrefix + 'question-id').val();
403 var questionTextLimitOptions = _this.dbOptions[ _this.dbOptionsPrefix + 'text_limit_options' ][currentquestionId];
404 _this.aysSurveyCheckTextLimit(currentQuestion,questionTextLimitOptions,e,$(this));
405 });
406
407 // Number limit character/word
408 _this.$el.find('input.ays-survey-check-number-limit').on('input', function(e) {
409 var currentQuestion = $(this).parents(".ays-survey-question");
410 var currentquestionId = currentQuestion.find('.' + _this.htmlClassPrefix + 'question-id').val();
411 var questionTextLimitOptions = _this.dbOptions[ _this.dbOptionsPrefix + 'number_limit_options' ][currentquestionId];
412 _this.aysSurveyCheckNumberLimit(currentQuestion,questionTextLimitOptions,e,$(this));
413 });
414
415 // Number limit character/word, phone validation
416 _this.$el.find('input.ays-survey-is-phone-type').on('keypress', function(e) {
417 var theEvent = e || window.event;
418 var key = theEvent.keyCode || theEvent.which;
419 key = String.fromCharCode( key );
420 var checkingVal = _this.phoneValidatePattern.test(key);
421 if( !checkingVal ){
422 theEvent.returnValue = false;
423 if(theEvent.preventDefault) e.preventDefault();
424
425 }
426 });
427
428 _this.$el.find('.ays-survey-section .ays-survey-answer-label input[type="radio"],.ays-survey-detect-selected-question-dropdown').on('change' , function(){
429 _this.aysAutoNext($(this));
430 });
431
432 _this.$el.on('change', 'input[type="date"][name^="' + _this.htmlClassPrefix + 'answers"]', function(){
433
434 $(this).parents('.' + _this.htmlClassPrefix + 'question').removeClass('ays-has-error');
435 $(this).parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-validation-error').html('');
436
437 _this.confirmBeforeUnload = true;
438 });
439
440 var timeInput = _this.$el.find('.' + _this.htmlClassPrefix + 'timepicker');
441 if(timeInput.length > 0){
442 _this.$el.find('.' + _this.htmlClassPrefix + 'timepicker').timepicker();
443 }
444
445 _this.aysSurveyonTabPress();
446
447 }
448
449 AysSurveyPlugin.prototype.start = function(e) {
450 var _this = this;
451 // var $this = _this.$el.find('.ays_next.start_button');
452
453 // _this.quizId = _this.$el.find('input[name="ays_quiz_id"]').val();
454 // _this.dbOptions = JSON.parse(atob(window.aysQuizOptions[_this.quizId]));
455 // console.log(_this.dbOptions);
456 // if(typeof _this.dbOptions.answers_rw_texts == 'undefined'){
457 // _this.dbOptions.answers_rw_texts = 'on_passing';
458 // }
459 // if(typeof _this.dbOptions.make_questions_required == 'undefined'){
460 // _this.dbOptions.make_questions_required = 'off';
461 // }
462 // var quizOptionsName = 'quizOptions_' + _this.quizId;
463 // _this.QuizQuestionsOptions = [];
464 // if(typeof window[quizOptionsName] !== 'undefined'){
465 // for(var i in window[quizOptionsName]){
466 // _this.QuizQuestionsOptions[i] = JSON.parse(window.atob(window[quizOptionsName][i]));
467 // }
468 // }
469
470 // _this.aysResetQuiz( _this.$el );
471
472 // _this.$el.css('padding-bottom', '0px');
473
474 // var isRequiredQuestion = (_this.dbOptions.make_questions_required && _this.dbOptions.make_questions_required == "on") ? true : false;
475 // if(isRequiredQuestion === true){
476 // _this.$el.find('div[data-question-id]').each(function(){
477 // var thisStep = $(this);
478 // if(!thisStep.find('input.ays_next').hasClass('ays_display_none')){
479 // thisStep.find('input.ays_next').attr('disabled', 'disabled');
480 // }else if(!thisStep.find('i.ays_next_arrow').hasClass('ays_display_none')){
481 // thisStep.find('i.ays_next_arrow').attr('disabled', 'disabled');
482 // }
483
484 // if(!thisStep.find('input.ays_early_finish').hasClass('ays_display_none')){
485 // thisStep.find('input.ays_early_finish').attr('disabled', 'disabled');
486 // }else if(!thisStep.find('i.ays_early_finish').hasClass('ays_display_none')){
487 // thisStep.find('i.ays_early_finish').attr('disabled', 'disabled');
488 // }
489 // });
490 // }
491
492 // setTimeout(function(){
493 // _this.$el.css('border-radius', _this.dbOptions.quiz_border_radius + 'px');
494 // _this.$el.find('.step').css('border-radius', _this.dbOptions.quiz_border_radius + 'px');
495 // }, 400);
496
497 // $(e.target).parents('div.step').removeClass('active-step');
498 // $(e.target).parents('div.step').next().addClass('active-step');
499 // _this.current_fs = $this.parents('.step');
500 // _this.next_fs = $this.parents('.step').next();
501 // _this.startLiveProgressBar($this);
502
503 // if(_this.dbOptions.enable_pass_count == 'on'){
504 // _this.aysAnimateStep(_this.$el.data('questEffect'), _this.$el.find('.ays_quizn_ancnoxneri_qanak'));
505 // }
506 // if(_this.dbOptions.enable_rate_avg == 'on'){
507 // _this.aysAnimateStep(_this.$el.data('questEffect'), _this.$el.find('.ays_quiz_rete_avg'));
508 // }
509 // _this.selects();
510 // _this.answersField();
511 _this.activeStep( $(e.target), 'next', null);
512 };
513
514 AysSurveyPlugin.prototype.startTime = function (e) {
515 var _this = this;
516 var $this = $(e.target);
517 var thisStep = $this.parents('.step');
518 _this.$el.find('.ays-live-bar-wrap').css({'display': 'block'});
519 _this.$el.find('.ays-live-bar-percent').css({'display': 'inline-block'});
520 _this.$el.find('input.ays-start-date').val(_this.GetFullDateTime());
521 if (_this.dbOptions.enable_timer == 'on') {
522 _this.$el.find('div.ays-survey-timer').hide();
523 var timer = parseInt(_this.$el.find('div.ays-survey-timer').attr('data-timer'));
524 if (!isNaN(timer) && _this.dbOptions.timer !== undefined) {
525 if (_this.dbOptions.timer === timer && timer !== 0) {
526 timer += 2;
527 if (timer !== undefined) {
528 _this.timer(timer, {
529 isTimer: true,
530 blockedContent: false,
531 blockedElement: null,
532 });
533 }
534 } else {
535 alert('Wanna cheat??');
536 window.location.reload();
537 }
538 }
539 }
540 }
541
542 AysSurveyPlugin.prototype.timer = function(timer, args) {
543 if(typeof args == "undefined"){
544 args = {};
545 }
546 var _this = this;
547 var addTime = 0;
548 if(timer >= 0){
549 addTime = (timer * 1000);
550 }
551 var countDownDate = new Date().getTime() + addTime;
552 var timeForShow;
553 if(addTime > 0){
554 var x = setInterval(function (){
555 var now = new Date().getTime();
556 var distance = countDownDate - Math.ceil(now/1000)*1000;
557 var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
558 var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
559 var seconds = Math.floor((distance % (1000 * 60)) / 1000);
560 if(hours <= 0){
561 hours = null;
562 }else if (hours < 10) {
563 hours = '0' + hours;
564 }
565 if (minutes < 10) {
566 minutes = '0' + minutes;
567 }
568 if (seconds < 10) {
569 seconds = '0' + seconds;
570 }
571 timeForShow = ((hours == null)? "" : (hours + ":")) + minutes + ":" + seconds;
572 if(distance <= 1000){
573 timeForShow = ((hours == null) ? "" : "00:") + "00:00";
574 }else{
575 timeForShow = timeForShow;
576 }
577 _this.$el.find('.' + _this.htmlClassPrefix + 'countdown-time').html(timeForShow);
578 if(_this.$el.find('.' + _this.htmlClassPrefix + 'countdown-time').length === 0){
579 clearInterval(x);
580 }
581
582 if (distance <= 1000) {
583 clearInterval(x);
584 if(args.blockedContent){
585 if(args.redirectNewTab){
586 window.open( args.redirectUrl , "_blank");
587 }
588 else{
589 window.location.assign( args.redirectUrl );
590 }
591 }
592 }
593 }, 1000);
594 }
595 else{
596 if(args.blockedContent){
597 if(args.redirectNewTab){
598 window.open( args.redirectUrl , "_blank");
599 }
600 else{
601 window.location.assign( args.redirectUrl );
602 }
603 }
604 }
605 };
606
607 AysSurveyPlugin.prototype.ratingAvg = function() {
608 var _this = this;
609 _this.$el.find('.for_quiz_rate_avg.ui.rating').rating('disable');
610 };
611
612 AysSurveyPlugin.prototype.aysNext = function() {
613 var _this = this;
614 _this.$el.on('click', '.' + _this.htmlClassPrefix + 'next-button', function (e){
615 var currentPage = _this.$el.find("div.ays-survey-section.active-section").data("pageNumber") + 1;
616 _this.confirmBeforeUnload = true;
617 e.preventDefault();
618 if (_this.animating) return false;
619 _this.animating = true;
620 if( _this.checkForm( $( e.target ) ) ){
621 _this.activeStep($(e.target), 'next');
622 _this.aysAnimateStep('fade', _this.current_fs, _this.next_fs);
623
624 _this.goTo();
625 if( _this.dbOptions.survey_cover_only_first_section && currentPage == 2){
626 _this.$el.find(".ays-survey-cover-photo-title-wrap").css('height' , 'auto');
627 _this.$el.find(".ays-survey-cover-photo-title-wrap").css('background-image' , 'unset');
628 }
629 var pageCount = _this.$el.find("div.ays-survey-section:not(:last-child)").length;
630 var fillWidth = (currentPage*100)/pageCount;
631 _this.$el.find("div.ays-survey-live-bar-fill").animate({'width': fillWidth+"%"}, 1000);
632 _this.$el.find("span.ays-survey-live-bar-changeable-text").text(currentPage);
633
634 }else{
635
636 }
637 });
638
639 _this.$el.on('click', '.' + _this.htmlClassPrefix + 'prev-button', function (e){
640 _this.confirmBeforeUnload = true;
641 e.preventDefault();
642 var currentPage = _this.$el.find("div.ays-survey-section.active-section").data("pageNumber") - 1;
643 var pageCount = _this.$el.find("div.ays-survey-section:not(:last-child)").length;
644 var fillWidth = (currentPage*100)/pageCount;
645 _this.$el.find("div.ays-survey-live-bar-fill").animate({'width': fillWidth+"%"}, 500);
646 _this.$el.find("span.ays-survey-live-bar-changeable-text").text(currentPage);
647 _this.current_fs.find('.' + _this.htmlClassPrefix + 'next-button').removeClass('display_none_important');
648 if (_this.animating) return false;
649 _this.animating = true;
650 if( _this.dbOptions.survey_cover_only_first_section && currentPage == 1){
651 _this.$el.find(".ays-survey-cover-photo-title-wrap").css('height' , _this.dbOptions.survey_cover_photo_height);
652 _this.$el.find(".ays-survey-cover-photo-title-wrap").css('background-image' , "url(" + (_this.dbOptions.survey_cover_photo) + ")");
653 }
654
655 _this.activeStep($(e.target), 'prev');
656 _this.aysAnimateStep('fade', _this.current_fs, _this.next_fs);
657
658 _this.goTo();
659 });
660 };
661
662 AysSurveyPlugin.prototype.aysFinish = function() {
663 var _this = this;
664 var fButtonSelector = 'input.' + _this.htmlClassPrefix + 'finish-button';
665
666 _this.$el.on('click', fButtonSelector, function (e) {
667 e.preventDefault();
668 _this.confirmBeforeUnload = false;
669
670 if( _this.checkForm( $( e.target ) ) ){
671
672 var form = _this.$el.find('form');
673
674 var data = form.serializeFormJSON();
675
676 var surveyCurrentPageLink = form.find('input[name="ays-survey-curent_page_link"]').val();
677 var surveyCurrentPageTitle = form.find('input[name="ays-survey-curent_page_title"]').val();
678 data.action = _this.ajaxAction;
679 data.function = 'ays_finish_survey';
680 data._ajax_nonce = window.aysSurveyMakerAjaxPublic.ajaxNonce;
681 data.end_date = _this.GetFullDateTime();
682 data.unique_id = _this.uniqueId;
683 data.survey_current_page_link = surveyCurrentPageLink;
684 data.survey_current_page_title = surveyCurrentPageTitle;
685
686 var sections = _this.$el.find('.' + _this.htmlClassPrefix + 'sections > .' + _this.htmlClassPrefix + 'section:not(:last-child)');
687 setTimeout( function(){
688 sections.remove();
689 }, 100 );
690
691 _this.$el.find('.' + _this.htmlClassPrefix + 'sections > .' + _this.htmlClassPrefix + 'section.' + _this.htmlClassPrefix + 'results-content').show(150);
692
693 var aysQuizLoader = form.find('div.ays-loader[data-role="loader"]');
694 aysQuizLoader.addClass(aysQuizLoader.data('class'));
695 aysQuizLoader.removeClass('ays-survey-loader');
696
697 setTimeout(function () {
698 _this.sendSurveyData(data, $(e.target));
699 }, 2000);
700
701 _this.goTo();
702 }
703 });
704 }
705
706 AysSurveyPlugin.prototype.validateButtonsVisibility = function() {
707 var _this = this;
708 var nextQuestionType = _this.next_fs.find('input[name^="ays_questions"]').attr('type');
709 var buttonsDiv = _this.next_fs.find('.ays_buttons_div');
710 var enableArrows = _this.$el.find(".ays_qm_enable_arrows").val();
711
712 if(_this.dbOptions.enable_arrows){
713 enableArrows = _this.dbOptions.enable_arrows == 'on' ? true : false;
714 }else{
715 enableArrows = parseInt(enableArrows) == 1 ? true : false;
716 }
717 var nextArrowIsDisabled = buttonsDiv.find('i.ays_next_arrow').hasClass('ays_display_none');
718 var nextButtonIsDisabled = buttonsDiv.find('input.ays_next').hasClass('ays_display_none');
719
720 if(_this.next_fs.find('textarea[name^="ays_questions"]').attr('type')==='text' && nextArrowIsDisabled && nextButtonIsDisabled){
721 buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
722 }
723 if(_this.next_fs.find('textarea[name^="ays_questions"]').attr('type')==='text' && enableArrows){
724 buttonsDiv.find('input.ays_next').addClass('ays_display_none');
725 buttonsDiv.find('i.ays_next_arrow').removeClass('ays_display_none');
726 }
727
728 if(nextQuestionType === 'checkbox' && nextArrowIsDisabled && nextButtonIsDisabled){
729 buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
730 }
731 if(nextQuestionType === 'checkbox' && enableArrows){
732 buttonsDiv.find('input.ays_next').addClass('ays_display_none');
733 buttonsDiv.find('i.ays_next_arrow').removeClass('ays_display_none');
734 }
735
736 if(nextQuestionType === 'number' && nextArrowIsDisabled && nextButtonIsDisabled){
737 buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
738 }
739 if(nextQuestionType === 'number' && enableArrows){
740 buttonsDiv.find('input.ays_next').addClass('ays_display_none');
741 buttonsDiv.find('i.ays_next_arrow').removeClass('ays_display_none');
742 }
743
744 if(nextQuestionType === 'text' && nextArrowIsDisabled && nextButtonIsDisabled){
745 next_fs.find('.ays_buttons_div').find('input.ays_next').removeClass('ays_display_none');
746 }
747 if(nextQuestionType === 'text' && enableArrows){
748 next_fs.find('.ays_buttons_div').find('input.ays_next').addClass('ays_display_none');
749 next_fs.find('.ays_buttons_div').find('i.ays_next_arrow').removeClass('ays_display_none');
750 }
751
752 if(nextQuestionType === 'date' && nextArrowIsDisabled && nextButtonIsDisabled){
753 buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
754 }
755 if(nextQuestionType === 'date' && enableArrows){
756 buttonsDiv.find('input.ays_next').addClass('ays_display_none');
757 buttonsDiv.find('.ays_next_arrow').removeClass('ays_display_none');
758 }
759
760 var isRequiredQuestion = (_this.dbOptions.make_questions_required && _this.dbOptions.make_questions_required == "on") ? true : false;
761 if(isRequiredQuestion === true){
762 if(_this.next_fs.find('.information_form').length === 0){
763 if(enableArrows){
764 buttonsDiv.find('i.ays_next_arrow').attr('disabled', 'disabled');
765 }else{
766 buttonsDiv.find('input.ays_next').attr('disabled', 'disabled');
767 }
768 }
769 }
770 }
771
772 AysSurveyPlugin.prototype.goToTop = function( el ) {
773 el.get(0).scrollIntoView({
774 block: "center",
775 behavior: "smooth"
776 });
777 }
778
779 AysSurveyPlugin.prototype.goTo = function() {
780 var surveyAnimationTop;
781
782 if(this.dbOptions != 'undefined'){
783 surveyAnimationTop = (this.dbOptions.survey_animation_top && this.dbOptions.survey_animation_top != 0) ? parseInt(this.dbOptions.survey_animation_top) : 200;
784 }else{
785 surveyAnimationTop = 200;
786 }
787 if(this.dbOptions.survey_enable_animation_top){
788 $('html, body').animate({
789 scrollTop: this.$el.offset().top - surveyAnimationTop + 'px'
790 }, 'fast');
791 }
792 return this; // for chaining...
793 }
794
795 AysSurveyPlugin.prototype.keydown = function(){
796 var _this = this, $this = _this.$el;
797 $this.find('input').on('focus', function () {
798 $(window).on('keydown', function (event) {
799 if (event.keyCode === 13) {
800 return false;
801 }
802 });
803 });
804
805 $this.find('input').on('blur', function () {
806 $(window).off('keydown');
807 });
808 }
809
810 AysSurveyPlugin.prototype.aysSurveyPreviewNoticeCopy = function(){
811 var _this = this;
812
813 $(document).off('click.aysSurveyPreviewNoticeCopy').on('click.aysSurveyPreviewNoticeCopy', '.' + _this.htmlClassPrefix + 'preview-copy-shortcode', function(e){
814 e.preventDefault();
815 _this.aysSurveyCopyPreviewShortcode( $(this) );
816 });
817 }
818
819 AysSurveyPlugin.prototype.aysSurveyCopyPreviewShortcode = function( button ){
820 var shortcode = button.attr('data-shortcode');
821 var label = button.attr('data-label');
822 var copiedLabel = button.attr('data-copied-label');
823 var labelNode = button.find('.' + this.htmlClassPrefix + 'preview-copy-shortcode-label');
824
825 if ( ! shortcode || labelNode.length === 0 ) {
826 return;
827 }
828
829 shortcode = '[' + shortcode + ']';
830
831 var setCopiedLabel = function() {
832 labelNode.text( copiedLabel );
833
834 setTimeout(function() {
835 labelNode.text( label );
836 }, 1800);
837 };
838
839 var copyWithFallback = function() {
840 var input = $('<textarea readonly></textarea>');
841 input.val( shortcode );
842 input.css({
843 position: 'absolute',
844 left: '-9999px'
845 });
846
847 $('body').append( input );
848 input[0].select();
849 document.execCommand('copy');
850 input.remove();
851 setCopiedLabel();
852 };
853
854 if ( navigator.clipboard && navigator.clipboard.writeText ) {
855 navigator.clipboard.writeText( shortcode ).then( setCopiedLabel ).catch( copyWithFallback );
856 return;
857 }
858
859 copyWithFallback();
860 }
861
862 AysSurveyPlugin.prototype.aysAnimateStep = function(animation, current_fs, next_fs){
863 var _this = this;
864 if(typeof next_fs !== "undefined"){
865 switch(animation){
866 case "lswing":
867 current_fs.parents('.ays-questions-container').css({
868 perspective: '800px',
869 });
870
871 current_fs.addClass('swing-out-right-bck');
872 current_fs.css({
873 'pointer-events': 'none'
874 });
875 setTimeout(function(){
876 current_fs.css({
877 'position': 'absolute',
878 });
879 next_fs.css('display', 'flex');
880 next_fs.addClass('swing-in-left-fwd');
881 },400);
882 setTimeout(function(){
883 current_fs.hide();
884 current_fs.css({
885 'pointer-events': 'auto',
886 'position': 'static'
887 });
888 next_fs.css({
889 'position':'relative',
890 'pointer-events': 'auto'
891 });
892 current_fs.removeClass('swing-out-right-bck');
893 next_fs.removeClass('swing-in-left-fwd');
894 _this.animating = false;
895 },1000);
896 break;
897 case "rswing":
898 current_fs.parents('.ays-questions-container').css({
899 perspective: '800px',
900 });
901
902 current_fs.addClass('swing-out-left-bck');
903 current_fs.css({
904 'pointer-events': 'none'
905 });
906 setTimeout(function(){
907 current_fs.css({
908 'position': 'absolute',
909 });
910 next_fs.css('display', 'flex');
911 next_fs.addClass('swing-in-right-fwd');
912 },400);
913 setTimeout(function(){
914 current_fs.hide();
915 current_fs.css({
916 'pointer-events': 'auto',
917 'position': 'static'
918 });
919 next_fs.css({
920 'position':'relative',
921 'pointer-events': 'auto'
922 });
923 current_fs.removeClass('swing-out-left-bck');
924 next_fs.removeClass('swing-in-right-fwd');
925 _this.animating = false;
926 },1000);
927 break;
928 case "shake":
929 current_fs.animate({opacity: 0}, {
930 step: function (now, mx) {
931 _this.scale = 1 - (1 - now) * 0.2;
932 _this.left = (now * 50) + "%";
933 _this.opacity = 1 - now;
934 current_fs.css({
935 'transform': 'scale(' + _this.scale + ')',
936 'position': 'absolute',
937 'top':0,
938 'opacity': 1,
939 'pointer-events': 'none'
940 });
941 next_fs.css({
942 'left': _this.left,
943 'opacity': _this.opacity,
944 'display':'flex',
945 'position':'relative',
946 'pointer-events': 'none'
947 });
948 },
949 duration: 800,
950 complete: function () {
951 current_fs.hide();
952 current_fs.css({
953 'pointer-events': 'auto',
954 'opacity': 1,
955 'position': 'static'
956 });
957 next_fs.css({
958 'display':'flex',
959 'position':'relative',
960 'transform':'scale(1)',
961 'opacity': 1,
962 'pointer-events': 'auto'
963 });
964 _this.animating = false;
965 },
966 easing: 'easeInOutBack'
967 });
968 break;
969 case "fade":
970 current_fs.animate({opacity: 0}, {
971 step: function (now, mx) {
972 _this.opacity = 1 - now;
973 current_fs.attr('style' , 'position: absolute !important;width: 100% !important;pointer-events: none !important;');
974 next_fs.attr('style' , 'opacity: '+_this.opacity+' !important;position: relative !important;display: block !important;width: 100% !important;pointer-events: none !important;');
975 },
976 duration: 500,
977 complete: function () {
978 current_fs.hide();
979 current_fs.attr('style' , 'position: static !important;pointer-events: auto !important;');
980 next_fs.attr('style' , 'display: block !important;position: relative !important;opacity: 1 !important;pointer-events: auto !important;');
981 _this.animating = false;
982 }
983 });
984 break;
985 default:
986 current_fs.animate({}, {
987 step: function (now, mx) {
988 current_fs.css({
989 'pointer-events': 'none'
990 });
991 next_fs.css({
992 'position':'relative',
993 'pointer-events': 'none'
994 });
995 },
996 duration: 0,
997 complete: function () {
998 current_fs.hide();
999 current_fs.css({
1000 'pointer-events': 'auto'
1001 });
1002 next_fs.css({
1003 'display':'block',
1004 'position':'relative',
1005 'transform':'scale(1)',
1006 'pointer-events': 'auto'
1007 });
1008 _this.animating = false;
1009 }
1010 });
1011 break;
1012 }
1013 }else{
1014 switch(animation){
1015 case "lswing":
1016 current_fs.parents('.ays-questions-container').css({
1017 perspective: '800px',
1018 });
1019 current_fs.addClass('swing-out-right-bck');
1020 current_fs.css({
1021 'pointer-events': 'none'
1022 });
1023 setTimeout(function(){
1024 current_fs.css({
1025 'position': 'absolute',
1026 });
1027 },400);
1028 setTimeout(function(){
1029 current_fs.hide();
1030 current_fs.css({
1031 'pointer-events': 'auto',
1032 'position': 'static'
1033 });
1034 current_fs.removeClass('swing-out-right-bck');
1035 _this.animating = false;
1036 },1000);
1037 break;
1038 case "rswing":
1039 current_fs.parents('.ays-questions-container').css({
1040 perspective: '800px',
1041 });
1042 current_fs.addClass('swing-out-left-bck');
1043 current_fs.css({
1044 'pointer-events': 'none'
1045 });
1046 setTimeout(function(){
1047 current_fs.css({
1048 'position': 'absolute',
1049 });
1050 },400);
1051 setTimeout(function(){
1052 current_fs.hide();
1053 current_fs.css({
1054 'pointer-events': 'auto',
1055 'position': 'static'
1056 });
1057 current_fs.removeClass('swing-out-left-bck');
1058 _this.animating = false;
1059 },1000);
1060 case "shake":
1061 current_fs.animate({opacity: 0}, {
1062 step: function (now, mx) {
1063 _this.scale = 1 - (1 - now) * 0.2;
1064 _this.left = (now * 50) + "%";
1065 _this.opacity = 1 - now;
1066 current_fs.css({
1067 'transform': 'scale(' + _this.scale + ')',
1068 });
1069 },
1070 duration: 800,
1071 complete: function () {
1072 current_fs.hide();
1073 _this.animating = false;
1074 },
1075 easing: 'easeInOutBack'
1076 });
1077 break;
1078 case "fade":
1079 current_fs.animate({opacity: 0}, {
1080 step: function (now, mx) {
1081 _this.opacity = 1 - now;
1082 },
1083 duration: 500,
1084 complete: function () {
1085 current_fs.hide();
1086 _this.animating = false;
1087 },
1088 easing: 'easeInOutBack'
1089 });
1090 break;
1091 default:
1092 current_fs.animate({}, {
1093 step: function (now, mx) {
1094
1095 },
1096 duration: 0,
1097 complete: function () {
1098 current_fs.hide();
1099 _this.animating = false;
1100 }
1101 });
1102 break;
1103 }
1104 }
1105 }
1106
1107 AysSurveyPlugin.prototype.activeStep = function(button, action) {
1108 var _this = this;
1109 _this.current_fs = button.parents('.' + _this.htmlClassPrefix + 'section');
1110 if(action == 'next'){
1111 _this.next_fs = button.parents('.' + _this.htmlClassPrefix + 'section').next();
1112 }
1113 if(action == 'prev'){
1114 _this.next_fs = button.parents('.' + _this.htmlClassPrefix + 'section').prev();
1115 }
1116 _this.current_fs.removeClass('active-section');
1117 _this.next_fs.addClass('active-section');
1118 }
1119
1120 AysSurveyPlugin.prototype.startLiveProgressBar = function(button) {
1121 var _this = this;
1122 if (button.parents('.step').next().find('.information_form').length === 0 ){
1123 var questions_count = _this.$el.find('form').find('div[data-question-id]').length;
1124 var curent_number = _this.$el.find('form').find('div[data-question-id]').index(button.parents('div[data-question-id]')) + 1;
1125 var final_width = ((curent_number+1) / questions_count * 100) + "%";
1126 if(button.parents('.ays-quiz-container').find('.ays-live-bar-percent').hasClass('ays-live-bar-count')){
1127 button.parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(curent_number+1));
1128 }else{
1129 button.parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(final_width));
1130 }
1131 button.parents('.ays-quiz-container').find('.ays-live-bar-fill').animate({'width': final_width}, 500);
1132 }
1133 }
1134
1135 AysSurveyPlugin.prototype.actionLiveProgressBar = function(button, action) {
1136 var _this = this;
1137 var questions_count = _this.$el.find('form').find('div[data-question-id]').length;
1138 var curent_number;
1139 if(action == 'next'){
1140 curent_number = _this.$el.find('form').find('div[data-question-id]').index(button.parents('div[data-question-id]')) + 1;
1141 }
1142 if(action == 'prev'){
1143 curent_number = _this.$el.find('form').find('div[data-question-id]').index(button.parents('div[data-question-id]')) - 1;
1144 }
1145 if(curent_number != questions_count){
1146 if((button.hasClass('ays_finish')) == false){
1147 if (!($(this).hasClass('start_button'))) {
1148 var current_width = button.parents('.ays-quiz-container').find('.ays-live-bar-fill').width();
1149 var final_width = ((curent_number+1) / questions_count * 100) + "%";
1150 if(button.parents('.ays-quiz-container').find('.ays-live-bar-percent').hasClass('ays-live-bar-count')){
1151 button.parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(curent_number+1));
1152 }else{
1153 button.parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(final_width));
1154 }
1155 button.parents('.ays-quiz-container').find('.ays-live-bar-fill').animate({'width': final_width}, 500);
1156 }
1157 }
1158 }else{
1159 button.parents('.ays-quiz-container').find('.ays-live-bar-wrap').removeClass('rubberBand').addClass('bounceOut');
1160 setTimeout(function () {
1161 button.parents('.ays-quiz-container').find('.ays-live-bar-wrap').css('display','none');
1162 },300)
1163 }
1164
1165 if(questions_count === curent_number){
1166 if(_this.current_fs.hasClass('.information_form').length !== 0){
1167 _this.current_fs.parents('.ays-quiz-container').find('.ays-quiz-timer').parent().slideUp(500);
1168 setTimeout(function () {
1169 _this.current_fs.parents('.ays-quiz-container').find('.ays-quiz-timer').parent().remove();
1170 },500);
1171 }
1172 }
1173 }
1174
1175 AysSurveyPlugin.prototype.checkForm = function( button ){
1176 var _this = this;
1177 _this.animating = false;
1178
1179 var section = button.parents('.' + _this.htmlClassPrefix + 'section');
1180 var requiredQuestions = section.find('[data-required="true"]');
1181 if ( requiredQuestions.length !== 0) {
1182 var empty_inputs = 0;
1183 var errorQuestions = section.find('.ays-has-error');
1184 section.find('.ays-has-error').removeClass('ays-has-error');
1185 for (var i = 0; i < requiredQuestions.length; i++) {
1186 var item = requiredQuestions.eq(i);
1187 var checkMinVotes = requiredQuestions.eq(i).data('isMin');
1188 var checkAllTermsAndConds = item.data('allTermsCheck');
1189 if( item.data('type') == 'text' || item.data('type') == 'email' || item.data('type') == 'name' || item.data('type') == 'short_text' || item.data('type') == 'number' || item.data('type') == 'phone' || item.data('type') == 'date' || item.data('type') == 'time' || item.data('type') == 'date_time'){
1190 var errorMessage = '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">';
1191
1192 if(item.data('type') == 'date_time'){
1193 var dateTimeInps = item.find( '.' + _this.htmlClassPrefix + 'input' );
1194 var dateTimeInps = item.find( '.' + _this.htmlClassPrefix + 'input:not(.' + _this.htmlClassPrefix + 'not-required-field)' );
1195 var dateTimeChecker = true;
1196 dateTimeInps.each(function(e,i){
1197 if($(i).val() == ''){
1198 dateTimeChecker = false;
1199
1200 if($(dateTimeInps[0]).val() == ''){
1201 $(dateTimeInps[0]).focus();
1202 }
1203 else{
1204 $(dateTimeInps[e]).focus();
1205 }
1206 errorMessage += '<span>' + _this.dbOptions.survey_required_questions_message + '</span>';
1207 item.addClass('ays-has-error');
1208 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').html(errorMessage);
1209 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').show();
1210 _this.goToTop( item );
1211
1212 empty_inputs++;
1213 }
1214 });
1215 if(!dateTimeChecker){
1216 break;
1217 }
1218 }
1219
1220 if( item.find( '.' + _this.htmlClassPrefix + 'input' ).val() == '' ){
1221 errorMessage += '<span>' + _this.dbOptions.survey_required_questions_message + '</span>';
1222 item.addClass('ays-has-error');
1223 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').html(errorMessage);
1224 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').show();
1225 _this.goToTop( item );
1226 item.find( '.' + _this.htmlClassPrefix + 'input' ).focus();
1227 empty_inputs++;
1228 break;
1229 }else{
1230 if( item.data('type') == 'email' ){
1231 if ( ! (_this.emailValidatePattern.test( item.find( '.' + _this.htmlClassPrefix + 'input' ).val() ) ) ) {
1232 errorMessage += '<span>' + surveySanitizeSpecificContent(aysSurveyLangObj.emailValidationError) + '</span>';
1233 item.addClass('ays-has-error');
1234 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').html(errorMessage);
1235 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').show();
1236 _this.goToTop( item );
1237 item.find( '.' + _this.htmlClassPrefix + 'input' ).focus();
1238 empty_inputs++;
1239 }
1240 }else{
1241 if( item.data('type') != 'number' ){
1242 continue;
1243 }
1244 }
1245 }
1246 }
1247
1248 var errorFlag = false;
1249 var checker = false;
1250 if ( item.data('type') == 'radio' || item.data('type') == 'checkbox' || item.data('type') == 'star' ) {
1251 var questionType = item.data('type') === 'star' ? 'radio' : item.data('type') || '';
1252
1253 if(typeof checkMinVotes != 'undefined' && checkMinVotes){
1254 checker = _this.checkMinVotes(item);
1255 if(!checker){
1256 return false;
1257 }
1258 }
1259
1260 if(typeof checkAllTermsAndConds != 'undefined' && checkAllTermsAndConds){
1261 checker = _this.checkTermsAndConds( item );
1262 if( ! checker ){
1263 return false;
1264 }
1265 }
1266
1267 if( item.find('input[type="'+ questionType +'"]:checked').length == 0 ){
1268 errorFlag = true;
1269 }
1270
1271 if( item.find('.' + _this.htmlClassPrefix + 'answer-other-input').length != 0 &&
1272 item.find('.' + _this.htmlClassPrefix + 'answer-label-other > input[value="0"]:checked').length > 0 ){
1273 if( item.find('.' + _this.htmlClassPrefix + 'answer-other-input').val() == '' ){
1274 errorFlag = true;
1275 item.find('.' + _this.htmlClassPrefix + 'answer-other-input').focus();
1276 }
1277 }
1278
1279 if( errorFlag ){
1280 var errorMessage = '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">';
1281 errorMessage += '<span>' + _this.dbOptions.survey_required_questions_message + '</span>';
1282 item.addClass('ays-has-error');
1283 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').html(errorMessage);
1284 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').show();
1285 _this.goToTop( item );
1286 empty_inputs++;
1287 break;
1288 }else{
1289 continue;
1290 }
1291 }
1292
1293 if ( item.data('type') == 'select' ) {
1294 if( item.find('.' + _this.htmlClassPrefix + 'question-select').aysDropdown('get value') == '' ){
1295 var errorMessage = '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">';
1296 errorMessage += '<span>' + _this.dbOptions.survey_required_questions_message + '</span>';
1297 item.addClass('ays-has-error');
1298 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').html(errorMessage);
1299 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').show();
1300 _this.goToTop( item );
1301 empty_inputs++;
1302 break;
1303 }else{
1304 continue;
1305 }
1306 }
1307
1308 if( item.data('type') == 'number' ){
1309 var numberInput = item.find('input.ays-survey-check-number-limit');
1310 var currentQuestion = item;
1311 var currentquestionId = currentQuestion.find('.' + _this.htmlClassPrefix + 'question-id').val();
1312 var questionTextLimitOptions = _this.dbOptions[ _this.dbOptionsPrefix + 'number_limit_options' ][currentquestionId];
1313 _this.aysSurveyCheckNumberLimit(currentQuestion,questionTextLimitOptions,numberInput,$(numberInput));
1314
1315 if( item.hasClass('ays-has-error') ){
1316 _this.goToTop( item );
1317 item.find( '.' + _this.htmlClassPrefix + 'input' ).focus();
1318 empty_inputs++;
1319 break;
1320 }else{
1321 continue;
1322 }
1323 }
1324
1325 }
1326
1327 for (var i = 0; i < errorQuestions.length; i++) {
1328 var item = errorQuestions.eq(i);
1329 if( item.data('type') == 'email' ){
1330 if( ! (_this.emailValidatePattern.test( item.find( '.' + _this.htmlClassPrefix + 'input' ).val() ) ) ){
1331 var errorMessage = '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">';
1332 errorMessage += '<span>' + surveySanitizeSpecificContent(aysSurveyLangObj.emailValidationError) + '</span>';
1333
1334 item.addClass('ays-has-error');
1335 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').html(errorMessage);
1336 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').show();
1337 _this.goToTop( item );
1338 item.find( '.' + _this.htmlClassPrefix + 'input' ).focus();
1339 empty_inputs++;
1340 break;
1341 }else{
1342 continue;
1343 }
1344 }
1345 }
1346
1347 if (empty_inputs !== 0) {
1348 return false;
1349 }else{
1350 return true;
1351 }
1352 }
1353 else{
1354 var empty_inputs = 0;
1355 var errorQuestions = section.find('.ays-has-error');
1356 for (var i = 0; i < errorQuestions.length; i++) {
1357 var item = errorQuestions.eq(i);
1358 if( item.data('type') == 'email' ){
1359 if( ! (_this.emailValidatePattern.test( item.find( '.' + _this.htmlClassPrefix + 'input' ).val() ) ) ){
1360 var errorMessage = '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">';
1361 errorMessage += '<span>' + surveySanitizeSpecificContent(aysSurveyLangObj.emailValidationError) + '</span>';
1362
1363 item.addClass('ays-has-error');
1364 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').html(errorMessage);
1365 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').show();
1366 _this.goToTop( item );
1367 item.find( '.' + _this.htmlClassPrefix + 'input' ).focus();
1368 empty_inputs++;
1369 break;
1370 }else{
1371 continue;
1372 }
1373 }
1374 if( item.data('type') == 'number' ){
1375 if( item.hasClass('ays-has-error') ){
1376 _this.goToTop( item );
1377 item.find( '.' + _this.htmlClassPrefix + 'input' ).focus();
1378 empty_inputs++;
1379 break;
1380 }else{
1381 continue;
1382 }
1383 }
1384 }
1385 var questions = section.find('.' + _this.htmlClassPrefix + 'question[data-is-min="true"]');
1386
1387 if(questions.length > 0){
1388 for(var i = 0; i < questions.length; i++){
1389 var checker = _this.checkMinVotes(questions.eq(i));
1390 if(!checker){
1391 return false;
1392 }
1393 }
1394 }
1395 if (empty_inputs !== 0) {
1396 return false;
1397 }else{
1398 return true;
1399 }
1400
1401 }
1402 }
1403
1404 AysSurveyPlugin.prototype.blockedContent = function( blocked ) {
1405 var _this = this;
1406
1407 if( blocked ){
1408 var blockedContent = _this.$el.hasClass( _this.htmlClassPrefix + 'blocked-content' );
1409 if ( blockedContent ) {
1410 var limitAttemptCount = _this.dbOptions[ _this.dbOptionsPrefix + 'limit_users' ];
1411 var redirectUrl = _this.dbOptions[ _this.dbOptionsPrefix + 'redirect_url' ];
1412 if( limitAttemptCount && redirectUrl != ''){
1413 var redirectTimerHTML = '<div class="' + _this.htmlClassPrefix + 'redirect-timer ' + _this.htmlClassPrefix + 'countdown-timer">' +
1414 aysSurveyLangObj.redirectAfter + ' <span class="' + _this.htmlClassPrefix + 'countdown-time">' + _this.dbOptions[ _this.dbOptionsPrefix + 'redirect_delay_seconds' ] + '</span>' +
1415 '</div>';
1416
1417 _this.$el.find('.' + _this.htmlClassPrefix + 'section-header').prepend( $( redirectTimerHTML ) );
1418
1419 var timer = _this.dbOptions[ _this.dbOptionsPrefix + 'redirect_delay' ] + 2;
1420 _this.timer( timer, {
1421 blockedContent: true,
1422 redirectUrl: _this.dbOptions[ _this.dbOptionsPrefix + 'redirect_url' ]
1423 });
1424 }
1425 }
1426 }
1427
1428 if( _this.$el.find('.ays_survey_login_form').length > 0 ){
1429 var surveyLoginForm = _this.$el.find('.ays_survey_login_form');
1430 var usernameInput = surveyLoginForm.find('input[type="text"]');
1431 var passwordInput = surveyLoginForm.find('input[type="password"]');
1432 var checkboxInput = surveyLoginForm.find('input[type="checkbox"]');
1433 var submitInput = surveyLoginForm.find('input[type="submit"]');
1434 _this.makeSurveyStyleInput( usernameInput );
1435 _this.makeSurveyStyleInput( passwordInput );
1436 _this.makeSurveyStyleSubmit( submitInput );
1437 if( checkboxInput.length > 0 ){
1438 _this.makeSurveyStyleCheckbox( checkboxInput );
1439 }
1440 }
1441
1442 if(_this.dbOptions[ _this.dbOptionsPrefix + 'enable_survey_start_loader' ]){
1443 _this.$el.find('.ays-survey-wait-loading-loader').css("display" , "none");
1444 }
1445 }
1446
1447 AysSurveyPlugin.prototype.selects = function(){
1448 var _this = this;
1449 _this.$el.find('.ays-field').on('click', function() {
1450 if ($(this).find(".select2").hasClass('select2-container--open')) {
1451 $(this).find('b[role="presentation"]').removeClass('ays_fa ays_fa_chevron_down');
1452 $(this).find('b[role="presentation"]').addClass('ays_fa ays_fa_chevron_up');
1453 } else {
1454 $(this).find('b[role="presentation"]').removeClass('ays_fa ays_fa_chevron_up');
1455 $(this).find('b[role="presentation"]').addClass('ays_fa ays_fa_chevron_down');
1456 }
1457 });
1458
1459 _this.$el.find('select.ays-select').on("select2:selecting", function(e){
1460 $(this).parents('.ays-quiz-container').find('b[role="presentation"]').addClass('ays_fa ays_fa_chevron_down');
1461 });
1462
1463 _this.$el.find('select.ays-select').on("select2:closing", function(e){
1464 $(this).parents('.ays-quiz-container').find('b[role="presentation"]').addClass('ays_fa ays_fa_chevron_down');
1465 });
1466
1467 _this.$el.find('select.ays-select').on("select2:select", function(e){
1468 $(this).parent().find('.ays-select-field-value').attr("value", $(this).val());
1469 if ($(this).parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') && $(this).parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
1470 $(this).parents('div[data-question-id]').find('.ays_next').trigger('click');
1471 }
1472 if($(this).parents(".ays-questions-container").find('form[id^="ays_finish_quiz"]').hasClass('enable_correction')) {
1473 if ($(this).find('option:selected').data("chisht") == 1) {
1474 $(this).parents('.ays-field').addClass('correct correct_div');
1475 $(this).parents('.ays-field').find('.select2-selection.select2-selection--single').css("border-bottom-color", "green");
1476 } else {
1477 $(this).parents('.ays-field').addClass('wrong wrong_div');
1478 $(this).parents('.ays-field').find('.select2-selection.select2-selection--single').css("border-bottom-color", "red");
1479 }
1480 if ($(this).find('option:selected').data("chisht") == 1) {
1481 $(e.target).parents().eq(3).find('.right_answer_text').fadeIn();
1482 }
1483 else {
1484 $(e.target).parents().eq(3).find('.wrong_answer_text').fadeIn();
1485 }
1486 $(this).attr("disabled", true);
1487 $(e.target).next().css("background-color", "#777");
1488 $(e.target).next().find('.selection').css("background-color", "#777");
1489 $(e.target).next().find('.select2-selection').css("background-color", "#777");
1490 }
1491 var this_select_value = $(this).val();
1492 $(this).find("option").removeAttr("selected");
1493 $(this).find("option[value='"+this_select_value+"']").attr("selected", true);
1494 });
1495 }
1496
1497 AysSurveyPlugin.prototype.answersField = function(){
1498 var _this = this;
1499
1500 _this.$el.on('change', 'input[name^="ays_questions"]', function (e) {
1501 var quizContainer = _this.$el;
1502 if(typeof myOptions != 'undefined'){
1503 var isRequiredQuestion = (_this.dbOptions.make_questions_required && _this.dbOptions.make_questions_required == "on") ? true : false;
1504 if(isRequiredQuestion === true){
1505 if($(e.target).attr('type') === 'radio' || $(e.target).attr('type') === 'checkbox'){
1506 if($(e.target).parents('div[data-question-id]').find('input[name^="ays_questions"]:checked').length != 0){
1507 if (!$(e.target).parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none')){
1508 $(e.target).parents('div[data-question-id]').find('input.ays_next').removeAttr('disabled');
1509 $(e.target).parents('div[data-question-id]').find('input.ays_early_finish').removeAttr('disabled');
1510 }else if(!$(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
1511 $(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').removeAttr('disabled');
1512 $(e.target).parents('div[data-question-id]').find('i.ays_early_finish').removeAttr('disabled');
1513 }
1514 }else{
1515 if (!$(e.target).parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none')){
1516 $(e.target).parents('div[data-question-id]').find('input.ays_next').attr('disabled', true);
1517 $(e.target).parents('div[data-question-id]').find('input.ays_early_finish').attr('disabled', true);
1518 }else if(!$(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
1519 $(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').attr('disabled', true);
1520 $(e.target).parents('div[data-question-id]').find('i.ays_early_finish').attr('disabled', true);
1521 }
1522 }
1523 }
1524 }
1525 }
1526
1527 if($(e.target).parents('.step').hasClass('not_influence_to_score')){
1528 if($(e.target).attr('type') === 'radio') {
1529 $(e.target).parents('.ays-quiz-answers').find('.checked_answer_div').removeClass('checked_answer_div');
1530 $(e.target).parents('.ays-field').addClass('checked_answer_div');
1531 }
1532 if($(e.target).attr('type') === 'checkbox') {
1533 if(!$(e.target).parents('.ays-field').hasClass('checked_answer_div')){
1534 $(e.target).parents('.ays-field').addClass('checked_answer_div');
1535 }else{
1536 $(e.target).parents('.ays-field').removeClass('checked_answer_div');
1537 }
1538 }
1539 var checked_inputs = $(e.target).parents().eq(1).find('input:checked');
1540 if (checked_inputs.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') &&
1541 checked_inputs.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
1542 if (checked_inputs.attr('type') === 'radio') {
1543 checked_inputs.parents('div[data-question-id]').find('.ays_next').trigger('click');
1544 }
1545 }
1546 if ($(e.target).parents().eq(4).hasClass('enable_correction')) {
1547 if (checked_inputs.attr('type') === "radio") {
1548 $(e.target).parents('div[data-question-id]').find('input[name^="ays_questions"]').attr('disabled', true);
1549 $(e.target).parents('div[data-question-id]').find('input[name^="ays_questions"]').off('change');
1550 } else if (checked_inputs.attr('type') === "checkbox") {
1551 $(e.target).attr('disabled', true);
1552 $(e.target).off('change');
1553 }
1554 }
1555 return false;
1556 }
1557
1558 if (quizContainer.find('form').hasClass('enable_correction')) {
1559 var right_answer_sound = quizContainer.find('.ays_quiz_right_ans_sound').get(0);
1560 var wrong_answer_sound = quizContainer.find('.ays_quiz_wrong_ans_sound').get(0);
1561 var finishAfterWrongAnswer = (_this.dbOptions.finish_after_wrong_answer && _this.dbOptions.finish_after_wrong_answer == "on") ? true : false;
1562 if ($(e.target).parents().eq(1).find('input[name="ays_answer_correct[]"]').length !== 0) {
1563 var checked_inputs = $(e.target).parents().eq(1).find('input:checked');
1564 if (checked_inputs.attr('type') === "radio") {
1565
1566 checked_inputs.nextAll().addClass('answered');
1567 checked_inputs.parent().addClass('checked_answer_div');
1568 if (checked_inputs.prev().val() == 1){
1569 checked_inputs.nextAll().addClass('correct')
1570 checked_inputs.parent().addClass('correct_div');
1571 }else{
1572 checked_inputs.nextAll().addClass('wrong');
1573 checked_inputs.parent().addClass('wrong_div');
1574 }
1575
1576 if (checked_inputs.prev().val() == 1) {
1577 if(_this.dbOptions.answers_rw_texts && (_this.dbOptions.answers_rw_texts == 'on_passing' || _this.dbOptions.answers_rw_texts == 'on_both')){
1578 var explanationTime = _this.dbOptions.explanation_time && _this.dbOptions.explanation_time != "" ? parseInt(_this.dbOptions.explanation_time) : 4;
1579 if(! $(e.target).parents('.step').hasClass('not_influence_to_score')){
1580 $(e.target).parents().eq(3).find('.right_answer_text').slideDown(250);
1581 }
1582 _this.explanationTimeout = setTimeout(function(){
1583 if (checked_inputs.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') &&
1584 checked_inputs.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
1585 checked_inputs.parents('div[data-question-id]').find('input.ays_next').trigger('click');
1586 }
1587 }, explanationTime * 1000);
1588 }else{
1589 if (checked_inputs.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') &&
1590 checked_inputs.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
1591 checked_inputs.parents('div[data-question-id]').find('input.ays_next').trigger('click');
1592 }
1593 }
1594 if((right_answer_sound)){
1595 resetPlaying([right_answer_sound, wrong_answer_sound]);
1596 setTimeout(function(){
1597 right_answer_sound.play();
1598 }, 10);
1599 }
1600 } else {
1601 $(e.target).parents('.ays-quiz-answers').find('input[name="ays_answer_correct[]"][value="1"]').parent().addClass('correct_div').addClass('checked_answer_div');
1602 $(e.target).parents('.ays-quiz-answers').find('input[name="ays_answer_correct[]"][value="1"]').nextAll().addClass('correct answered');
1603
1604 if(_this.dbOptions.answers_rw_texts && (_this.dbOptions.answers_rw_texts == 'on_passing' || _this.dbOptions.answers_rw_texts == 'on_both')){
1605 var explanationTime = _this.dbOptions.explanation_time && _this.dbOptions.explanation_time != "" ? parseInt(_this.dbOptions.explanation_time) : 4;
1606 if(! $(e.target).parents('.step').hasClass('not_influence_to_score')){
1607 $(e.target).parents().eq(3).find('.wrong_answer_text').slideDown(250);
1608 }
1609 _this.explanationTimeout = setTimeout(function(){
1610 if (checked_inputs.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') &&
1611 checked_inputs.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
1612 if(finishAfterWrongAnswer){
1613 goToLastPage(e);
1614 }else{
1615 checked_inputs.parents('div[data-question-id]').find('input.ays_next').trigger('click');
1616 }
1617 }else{
1618 if(finishAfterWrongAnswer){
1619 goToLastPage(e);
1620 }
1621 }
1622 }, explanationTime * 1000);
1623 }else{
1624 if (checked_inputs.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') &&
1625 checked_inputs.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
1626 if(finishAfterWrongAnswer){
1627 goToLastPage(e);
1628 }else{
1629 checked_inputs.parents('div[data-question-id]').find('input.ays_next').trigger('click');
1630 }
1631 }else{
1632 if(finishAfterWrongAnswer){
1633 goToLastPage(e);
1634 }
1635 }
1636 }
1637 if((wrong_answer_sound)){
1638 resetPlaying([right_answer_sound, wrong_answer_sound]);
1639 setTimeout(function(){
1640 wrong_answer_sound.play();
1641 }, 10);
1642 }
1643 }
1644 $(e.target).parents('div[data-question-id]').find('input[name^="ays_questions"]').attr('disabled', true);
1645 $(e.target).parents('div[data-question-id]').find('input[name^="ays_questions"]').off('change');
1646 $(e.target).parents('div[data-question-id]').find('.ays-field').css({
1647 'pointer-events': 'none'
1648 });
1649
1650 }else if(checked_inputs.attr('type') === "checkbox"){
1651 checked_inputs = $(e.target);
1652 if (checked_inputs.length === 1) {
1653 checked_inputs.parent().addClass('checked_answer_div');
1654 if(checked_inputs.prev().val() == 1){
1655 if((right_answer_sound)){
1656 resetPlaying([right_answer_sound, wrong_answer_sound]);
1657 setTimeout(function(){
1658 right_answer_sound.play();
1659 }, 10);
1660 }
1661 checked_inputs.parent().addClass('correct_div');
1662 checked_inputs.nextAll().addClass('correct answered');
1663 }else{
1664 if((wrong_answer_sound)){
1665 resetPlaying([right_answer_sound, wrong_answer_sound]);
1666 setTimeout(function(){
1667 wrong_answer_sound.play();
1668 }, 10);
1669 }
1670 if(finishAfterWrongAnswer){
1671 goToLastPage(e);
1672 }
1673 checked_inputs.parent().addClass('wrong_div');
1674 checked_inputs.nextAll().addClass('wrong answered');
1675 }
1676 }else{
1677 for (var i = 0; i < checked_inputs.length; i++) {
1678 if(checked_inputs.eq(i).prev().val() == 1){
1679 if((right_answer_sound)){
1680 resetPlaying([right_answer_sound, wrong_answer_sound]);
1681 setTimeout(function(){
1682 right_answer_sound.play();
1683 }, 10);
1684 }
1685 checked_inputs.eq(i).nextAll().addClass('correct answered');
1686 checked_inputs.eq(i).parent().addClass('correct_div');
1687 checked_inputs.eq(i).parent().addClass('checked_answer_div');
1688 }else{
1689 if((wrong_answer_sound)){
1690 resetPlaying([right_answer_sound, wrong_answer_sound]);
1691 setTimeout(function(){
1692 wrong_answer_sound.play();
1693 }, 10);
1694 }
1695 if(finishAfterWrongAnswer){
1696 goToLastPage(e);
1697 }
1698 checked_inputs.eq(i).parent().addClass('checked_answer_div');
1699 checked_inputs.eq(i).nextAll().addClass('wrong answered');
1700 checked_inputs.eq(i).parent().addClass('wrong_div');
1701 }
1702 }
1703 if(checked_inputs.eq(i).prev().val() == 1){
1704 checked_inputs.eq(i).next().addClass('correct answered');
1705 if((right_answer_sound)){
1706 resetPlaying([right_answer_sound, wrong_answer_sound]);
1707 setTimeout(function(){
1708 right_answer_sound.play();
1709 }, 10);
1710 }
1711 }else{
1712 checked_inputs.eq(i).next().addClass('wrong answered');
1713 if((wrong_answer_sound)){
1714 resetPlaying([right_answer_sound, wrong_answer_sound]);
1715 setTimeout(function(){
1716 wrong_answer_sound.play();
1717 }, 10);
1718 }
1719 }
1720
1721 }
1722 $(e.target).attr('disabled', true);
1723 $(e.target).off('change');
1724 }
1725 }
1726 }else{
1727 if($(e.target).attr('type') === 'radio') {
1728 $(e.target).parents('.ays-quiz-answers').find('.checked_answer_div').removeClass('checked_answer_div');
1729 $(e.target).parents('.ays-field').addClass('checked_answer_div');
1730 }
1731 if($(e.target).attr('type') === 'checkbox') {
1732 if(!$(e.target).parents('.ays-field').hasClass('checked_answer_div')){
1733 $(e.target).parents('.ays-field').addClass('checked_answer_div');
1734 }else{
1735 $(e.target).parents('.ays-field').removeClass('checked_answer_div');
1736 }
1737 }
1738 var checked_inputs = $(e.target).parents().eq(1).find('input:checked');
1739 if (checked_inputs.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') &&
1740 checked_inputs.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
1741 if (checked_inputs.attr('type') === 'radio') {
1742 checked_inputs.parents('div[data-question-id]').find('input.ays_next').trigger('click');
1743 }
1744 }
1745 }
1746 });
1747
1748 _this.$el.find('button.ays_check_answer').on('click', function (e) {
1749 var thisAnswerOptions;
1750 var quizContainer = _this.$el;
1751 var right_answer_sound = quizContainer.find('.ays_quiz_right_ans_sound').get(0);
1752 var wrong_answer_sound = quizContainer.find('.ays_quiz_wrong_ans_sound').get(0);
1753 var questionId = $(this).parents('.step').data('questionId');
1754 var finishAfterWrongAnswer = (_this.dbOptions.finish_after_wrong_answer && _this.dbOptions.finish_after_wrong_answer == "on") ? true : false;
1755 thisAnswerOptions = _this.QuizQuestionsOptions[questionId];
1756 if($(this).parent().find('.ays-text-input').val() !== ""){
1757 if ($(e.target).parents('form[id^="ays_finish_quiz"]').hasClass('enable_correction')) {
1758 if($(e.target).parents('.step').hasClass('not_influence_to_score')){
1759 return false;
1760 }
1761 $(this).css({
1762 animation: "bounceOut .5s",
1763 });
1764 setTimeout(function(){
1765 $(e.target).parent().find('.ays-text-input').css('width', '100%');
1766 $(e.target).css("display", "none");
1767 },480);
1768 $(e.target).parent().find('.ays-text-input').css('background-color', '#eee');
1769 $(this).parent().find('.ays-text-input').attr('disabled', 'disabled');
1770 $(this).attr('disabled', 'disabled');
1771 $(this).off('change');
1772 $(this).off('click');
1773
1774 var input = $(this).parent().find('.ays-text-input');
1775 var type = input.attr('type');
1776 var userAnsweredText = input.val().trim();
1777
1778 var trueAnswered = false;
1779 var thisQuestionAnswer = thisAnswerOptions.question_answer.toLowerCase();
1780
1781 if(type == 'date'){
1782 var correctDate = new Date(thisAnswerOptions.question_answer),
1783 correctDateYear = correctDate.getFullYear(),
1784 correctDateMonth = correctDate.getMonth(),
1785 correctDateDay = correctDate.getDate();
1786 var userDate = new Date(userAnsweredText),
1787 userDateYear = userDate.getFullYear(),
1788 userDateMonth = userDate.getMonth(),
1789 userDateDay = userDate.getDate();
1790 if(correctDateYear == userDateYear && correctDateMonth == userDateMonth && correctDateDay == userDateDay){
1791 trueAnswered = true;
1792 }
1793 }else if(type != 'number'){
1794 thisQuestionAnswer = thisQuestionAnswer.split('%%%');
1795 for(var i = 0; i < thisQuestionAnswer.length; i++){
1796 if(userAnsweredText.toLowerCase() == thisQuestionAnswer[i].trim()){
1797 trueAnswered = true;
1798 break;
1799 }
1800 }
1801 }else{
1802 if(userAnsweredText.toLowerCase() == thisQuestionAnswer.trim()){
1803 trueAnswered = true;
1804 }
1805 }
1806
1807 if(trueAnswered){
1808 if((right_answer_sound)){
1809 resetPlaying([right_answer_sound, wrong_answer_sound]);
1810 setTimeout(function(){
1811 right_answer_sound.play();
1812 }, 10);
1813 }
1814 $(this).parent().find('.ays-text-input').css('background-color', 'rgba(39,174,96,0.5)');
1815 $(this).parent().find('input[name="ays_answer_correct[]"]').val(1);
1816 }else{
1817 if((wrong_answer_sound)){
1818 resetPlaying([right_answer_sound, wrong_answer_sound]);
1819 setTimeout(function(){
1820 wrong_answer_sound.play();
1821 }, 10);
1822 }
1823 $(this).parent().find('.ays-text-input').css('background-color', 'rgba(243,134,129,0.8)');
1824 $(this).parent().find('input[name="ays_answer_correct[]"]').val(0);
1825 var rightAnswerText = '<div class="ays-text-right-answer">';
1826
1827 if(type == 'date'){
1828 var correctDate = new Date(thisAnswerOptions.question_answer),
1829 correctDateYear = correctDate.getFullYear(),
1830 correctDateMonth = (correctDate.getMonth() + 1) < 10 ? "0"+(correctDate.getMonth() + 1) : (correctDate.getMonth() + 1),
1831 correctDateDay = (correctDate.getDate() < 10) ? "0"+correctDate.getDate() : correctDate.getDate();
1832 rightAnswerText += [correctDateMonth, correctDateDay, correctDateYear].join('/');
1833 }else if(type != 'number'){
1834 rightAnswerText += thisQuestionAnswer[0];
1835 }else{
1836 rightAnswerText += thisQuestionAnswer;
1837 }
1838
1839 rightAnswerText += '</div>';
1840 $(this).parents('.ays-quiz-answers').append(rightAnswerText);
1841 $(this).parents('.ays-quiz-answers').find('.ays-text-right-answer').slideDown(500);
1842 if(finishAfterWrongAnswer){
1843 goToLastPage(e);
1844 }
1845 }
1846 }
1847 }
1848 });
1849 }
1850
1851 AysSurveyPlugin.prototype.makeSurveyStyleInput = function( input ) {
1852 var _this = this;
1853
1854 var html = '<div class="' + _this.htmlClassPrefix + 'question-input-box">'+
1855 '<div class="' + _this.htmlClassPrefix + 'input-underline"></div>'+
1856 '<div class="' + _this.htmlClassPrefix + 'input-underline-animation"></div>'+
1857 '</div>';
1858 html = $( html );
1859
1860 html.insertAfter( input );
1861
1862 html.prepend( input );
1863
1864 input.addClass( _this.htmlClassPrefix + 'input' );
1865 input.addClass( _this.htmlClassPrefix + 'question-input' );
1866 }
1867
1868 AysSurveyPlugin.prototype.makeSurveyStyleCheckbox = function( input ) {
1869 var _this = this;
1870
1871 var html = '<div class="' + _this.htmlClassPrefix + 'answer-label-content">'+
1872 '<div class="' + _this.htmlClassPrefix + 'answer-icon-content">'+
1873 '<div class="' + _this.htmlClassPrefix + 'answer-icon-ink"></div>'+
1874 '<div class="' + _this.htmlClassPrefix + 'answer-icon-content-1">'+
1875 '<div class="' + _this.htmlClassPrefix + 'answer-icon-content-2">'+
1876 '<div class="' + _this.htmlClassPrefix + 'answer-icon-content-3"></div>'+
1877 '</div>'+
1878 '</div>'+
1879 '</div>'+
1880 '<span class=""></span>'+
1881 '</div>';
1882 html = $( html );
1883
1884 var inputCheckboxLabel = input.parents('label');
1885 var inputCheckbox = input;
1886
1887 inputCheckboxLabel.addClass('ays-survey-answer-label');
1888 html.find('span').text( inputCheckboxLabel.text() );
1889 inputCheckboxLabel.text('');
1890 input.remove();
1891 inputCheckboxLabel.prepend( inputCheckbox );
1892 html.insertAfter( inputCheckbox );
1893 }
1894
1895 AysSurveyPlugin.prototype.makeSurveyStyleRadio = function( input ) {
1896 var _this = this;
1897
1898 var html = '<div class="' + _this.htmlClassPrefix + 'answer-label-content">'+
1899 '<div class="' + _this.htmlClassPrefix + 'answer-icon-content">'+
1900 '<div class="' + _this.htmlClassPrefix + 'answer-icon-ink"></div>'+
1901 '<div class="' + _this.htmlClassPrefix + 'answer-icon-content-1">'+
1902 '<div class="' + _this.htmlClassPrefix + 'answer-icon-content-2">'+
1903 '<div class="' + _this.htmlClassPrefix + 'answer-icon-content-3"></div>'+
1904 '</div>'+
1905 '</div>'+
1906 '</div>'+
1907 '<span class=""></span>'+
1908 '</div>';
1909 html = $( html );
1910
1911 var inputCheckboxLabel = input.parents('label');
1912 var inputCheckbox = input;
1913
1914 inputCheckboxLabel.addClass('ays-survey-answer-label');
1915 html.find('span').text( inputCheckboxLabel.text() );
1916 inputCheckboxLabel.text('');
1917 input.remove();
1918 inputCheckboxLabel.prepend( inputCheckbox );
1919 html.insertAfter( inputCheckbox );
1920 }
1921
1922 AysSurveyPlugin.prototype.makeSurveyStyleSubmit = function( input ) {
1923 var _this = this;
1924
1925 var html = '<div class="' + _this.htmlClassPrefix + 'section-buttons">'+
1926 '<div class="' + _this.htmlClassPrefix + 'section-button-container">'+
1927 '<div class="' + _this.htmlClassPrefix + 'section-button-content">'+
1928 '</div>'+
1929 '</div>'+
1930 '</div>';
1931 html = $( html );
1932
1933 html.insertAfter( input );
1934
1935 html.find('.' + _this.htmlClassPrefix + 'section-button-content').append( input );
1936
1937 input.addClass('ays-survey-section-button');
1938 input.removeClass('button button-primary');
1939 }
1940
1941
1942 /**
1943 * @return {string}
1944 */
1945 AysSurveyPlugin.prototype.GetFullDateTime = function() {
1946 var now = new Date();
1947 var strDateTime = [[now.getFullYear(), AddZero(now.getMonth() + 1), AddZero(now.getDate())].join("-"), [AddZero(now.getHours()), AddZero(now.getMinutes()), AddZero(now.getSeconds())].join(":")].join(" ");
1948 return strDateTime;
1949 }
1950
1951 /**
1952 * @return {string}
1953 */
1954 AysSurveyPlugin.prototype.AddZero = function (num) {
1955 return (num >= 0 && num < 10) ? "0" + num : num + "";
1956 }
1957
1958 /**
1959 * @return {boolean}
1960 */
1961 AysSurveyPlugin.prototype.validatePhoneNumber = function (input) {
1962 var phoneno = /^[+ 0-9-]+$/;
1963 if (input.value.match(phoneno)) {
1964 return true;
1965 } else {
1966 return false;
1967 }
1968 }
1969
1970 AysSurveyPlugin.prototype.sendSurveyData = function(data, element){
1971 var _this = this;
1972 if(typeof _this.sendSurveyData.counter == 'undefined'){
1973 _this.sendSurveyData.counter = 0;
1974 }
1975 if(window.navigator.onLine){
1976 _this.sendSurveyData.counter++;
1977 $.ajax({
1978 url: window.aysSurveyMakerAjaxPublic.ajaxUrl,
1979 method: 'post',
1980 dataType: 'json',
1981 data: data,
1982 success: function(response){
1983 if(response.status === true){
1984 _this.doSurveyResult(response);
1985 }else{
1986 if(_this.sendSurveyData.counter >= 5){
1987 swal.fire({
1988 type: 'error',
1989 html: aysSurveyLangObj.sorry + ".<br>" + aysSurveyLangObj.unableStoreData + "."
1990 });
1991 // _this.goQuizFinishPage(element);
1992 }else{
1993 if(window.navigator.onLine){
1994 setTimeout(function(){
1995 _this.sendSurveyData(data, element);
1996 },3000);
1997 }else{
1998 _this.sendSurveyData(data, element);
1999 }
2000 }
2001 }
2002 },
2003 error: function(jqXHR, textStatus, errorThrown) {
2004 if(_this.sendSurveyData.counter >= 5){
2005 swal.fire({
2006 type: 'error',
2007 html: aysSurveyLangObj.sorry + ".<br>" + aysSurveyLangObj.unableStoreData + "."
2008 });
2009 // _this.goQuizFinishPage(element);
2010 }else{
2011 setTimeout(function(){
2012 _this.sendSurveyData(data, element);
2013 },3000);
2014 }
2015 }
2016 });
2017 }else{
2018 swal.fire({
2019 type: 'warning',
2020 html: aysSurveyLangObj.connectionLost + ".<br>" + aysSurveyLangObj.checkConnection + "."
2021 });
2022 _this.sendSurveyData.counter = 0;
2023 // _this.goQuizFinishPage(element);
2024 }
2025 }
2026
2027 AysSurveyPlugin.prototype.goQuizFinishPage = function(element){
2028 var _this = this;
2029 var currentFS = _this.$el.find('.step.active-step');
2030 var next_sibilings_count = _this.$el.find('.ays_question_count_per_page').val();
2031 if (parseInt(next_sibilings_count) > 0 &&
2032 (element.parents('.step').attr('data-question-id') ||
2033 element.parents('.step').next().attr('data-question-id'))) {
2034 currentFS = _this.$el.find('div[data-question-id]');
2035 }
2036 currentFS.prev().css('display', 'flex');
2037 _this.aysAnimateStep(_this.$el.data('questEffect'), currentFS, currentFS.prev());
2038
2039 if(_this.dbOptions.enable_correction == 'on'){
2040 if(currentFS.prev().find('input:checked').length > 0){
2041 currentFS.prev().find('.ays-field input').attr('disabled', 'disabled');
2042 currentFS.prev().find('.ays-field input').on('click', function(){
2043 return false;
2044 });
2045 currentFS.prev().find('.ays-field input').on('change', function(){
2046 return false;
2047 });
2048 }
2049 if(currentFS.prev().find('option:checked').length > 0){
2050 currentFS.prev().find('.ays-field select').attr('disabled', 'disabled');
2051 currentFS.prev().find('.ays-field select').on('click', function(){
2052 return false;
2053 });
2054 currentFS.prev().find('.ays-field select').on('change', function(){
2055 return false;
2056 });
2057 }
2058 if(currentFS.prev().find('textarea').length > 0){
2059 if(currentFS.prev().find('textarea').val() !== ''){
2060 currentFS.prev().find('.ays-field textarea').attr('disabled', 'disabled');
2061 currentFS.prev().find('.ays-field textarea').on('click', function(){
2062 return false;
2063 });
2064 currentFS.prev().find('.ays-field textarea').on('change', function(){
2065 return false;
2066 });
2067 }
2068 }
2069 }
2070 }
2071
2072 AysSurveyPlugin.prototype.doSurveyResult = function( response ){
2073 var _this = this;
2074 if( response.status ){
2075 var formResults = _this.$el.find('.' + _this.htmlClassPrefix + 'thank-you-page');
2076 if (_this.$el.hasClass('enable_questions_result')) {
2077
2078 }
2079
2080 var aysQuizLoader = _this.$el.find('div.ays-loader[data-role="loader"]');
2081 aysQuizLoader.addClass('ays-survey-loader');
2082 aysQuizLoader.removeClass(aysQuizLoader.data('class'));
2083 _this.$el.find('div.ays-survey-loader.ays-survey-loader-snake').hide();
2084 _this.$el.find('.ays-survey-loader-with-text').hide();
2085 _this.$el.find('.ays-survey-loader-with-custom-gif').hide();
2086 if( response.message ){
2087 formResults.prepend( $( '<div>' + response.message + '</div>' ) );
2088 }
2089
2090 if( response.socialHeading ){
2091 _this.$el.find(".ays-survey-social-shares-heading").append(response.socialHeading);
2092 }
2093
2094 if( _this.dbOptions[ _this.dbOptionsPrefix + 'redirect_after_submit' ] ){
2095 if(!( _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_delay' ] )){
2096 _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_delay' ] = 0;
2097 }
2098
2099 if( parseInt( _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_delay' ] ) > 0 ){
2100 if( _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_url' ] != '' ){
2101 var redirectAfterSubmitTimerHTML = '<div class="' + _this.htmlClassPrefix + 'redirect-timer ' + _this.htmlClassPrefix + 'countdown-timer">' +
2102 aysSurveyLangObj.redirectAfter + ' <span class="' + _this.htmlClassPrefix + 'countdown-time">' + _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_seconds' ] + '</span>' +
2103 '</div>';
2104 formResults.prepend( $( redirectAfterSubmitTimerHTML ) );
2105 var timer = parseInt( _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_delay' ] ) + 2;
2106 _this.timer( timer, {
2107 blockedContent: true,
2108 redirectUrl: _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_url' ],
2109 redirectNewTab: _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_new_tab' ]
2110 });
2111 }
2112 }
2113 else{
2114
2115 _this.timer( timer, {
2116 blockedContent: true,
2117 redirectUrl: _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_url' ],
2118 redirectNewTab: _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_new_tab' ]
2119 });
2120 }
2121 }
2122
2123 var popupContainer = _this.$el.parents('.ays-survey-popup-survey-window');
2124 if(typeof popupContainer != 'undefined' && popupContainer.length > 0){
2125 var dataClosePopup = popupContainer.attr('data-close-popup');
2126 if(typeof dataClosePopup != 'undefined' && dataClosePopup == 'true'){
2127 var dataClosePopupDelay = popupContainer.attr('data-close-popup-delay');
2128 if(typeof dataClosePopupDelay != 'undefined' && dataClosePopupDelay){
2129 var popupCloseButton = popupContainer.find('.ays-survey-popup-btn-close');
2130 popupCloseButton.addClass('ays-survey-popup-btn-close-timer');
2131 var dataClosePopupDelayCount = +dataClosePopupDelay;
2132 if(dataClosePopupDelay > 0){
2133 var popupCloser = setInterval(function(){
2134 popupCloseButton.text(dataClosePopupDelayCount);
2135 dataClosePopupDelayCount--;
2136 if(dataClosePopupDelayCount < 0){
2137 clearInterval(popupCloser);
2138 popupCloseButton.trigger('click');
2139 }
2140 }, 1000);
2141 }else{
2142 setInterval(function(){
2143 popupCloseButton.trigger('click');
2144 }, 1000);
2145 }
2146 }
2147 }
2148 }
2149
2150 formResults.css({'display':'block'});
2151 }else{
2152
2153 }
2154 }
2155
2156 AysSurveyPlugin.prototype.aysResetQuiz = function ($quizContainer){
2157 var cont = $quizContainer.find('div[data-question-id]');
2158 cont.find('input[type="text"], textarea, input[type="number"], input[type="url"], input[type="email"]').each(function(){
2159 $(this).val('');
2160 });
2161 cont.find('select').each(function(){
2162 $(this).val('');
2163 });
2164 cont.find('select.ays-select').each(function(){
2165 $(this).val(null).trigger('change');
2166 });
2167 cont.find('select option').each(function(){
2168 $(this).removeAttr('selected');
2169 });
2170 cont.find('input[type="radio"], input[type="checkbox"]').each(function(){
2171 $(this).removeAttr('checked');
2172 });
2173 }
2174
2175 AysSurveyPlugin.prototype.aysAutofillData = function (data, currentEl){
2176 $.ajax({
2177 url: window.aysSurveyMakerAjaxPublic.ajaxUrl,
2178 method: 'post',
2179 dataType: 'json',
2180 data: data,
2181 success: function (response) {
2182 if(response !== null){
2183 if( response.data ){
2184 currentEl.find(".ays-survey-question[data-type='name'] input.ays-survey-question-input").val(response.data.display_name);
2185 currentEl.find(".ays-survey-question[data-type='email'] input.ays-survey-question-email-input").val(response.data.user_email);
2186 }
2187 } //:last-of-type
2188 }
2189 });
2190 }
2191
2192 AysSurveyPlugin.prototype.checkSurveyPassword = function(passwordSurvey, isAlert){
2193 var _this = this;
2194 var activPsw = new Array();
2195
2196 if( _this.dbOptions.options.survey_enable_password && _this.dbOptions.options.survey_password_survey != "" ){
2197 if( _this.dbOptions.options.survey_password_survey !== passwordSurvey ){
2198 if(isAlert){
2199 alert( aysSurveyLangObj.passwordIsWrong );
2200 }
2201 return false;
2202 }
2203 }
2204
2205 return true;
2206 }
2207
2208 AysSurveyPlugin.prototype.checkMinVotes = function( item ){
2209 var _this = this;
2210 var options;
2211 var questionId = item.find('.' + _this.htmlClassPrefix + 'question-id').val();
2212 options = _this.dbOptions[ _this.dbOptionsPrefix + 'checkbox_options' ][questionId];
2213 if(options.enable_max_selection_count){
2214 var allVotesCount = item.find('.' + _this.htmlClassPrefix + 'answer input[type="checkbox"][name^="' + _this.htmlClassPrefix + 'answers"]').length;
2215 var checkedCount = item.find('.' + _this.htmlClassPrefix + 'answer input[type="checkbox"][name^="' + _this.htmlClassPrefix + 'answers"]:checked').length;
2216 var MinVotes = options.min_selection_count;
2217 var MaxVotes = options.max_selection_count;
2218 if(MinVotes > MaxVotes){
2219 MinVotes = MaxVotes;
2220 }
2221 if(MinVotes > allVotesCount){
2222 MinVotes = allVotesCount;
2223 }
2224 var errorMessage = '';
2225 if(MinVotes <= checkedCount){
2226 item.find('.' + _this.htmlClassPrefix + 'votes-count-validation-error').hide();
2227 }
2228 if(MinVotes > checkedCount){
2229 errorMessage += '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">';
2230 errorMessage += '<span>' + aysSurveyLangObj.minimumVotes + ' ' + MinVotes + '</span>';
2231 item.addClass('ays-has-error');
2232 item.find('.' + _this.htmlClassPrefix + 'votes-count-validation-error').html(errorMessage);
2233 item.find('.' + _this.htmlClassPrefix + 'votes-count-validation-error').show();
2234 _this.goToTop( item );
2235 return false;
2236 }
2237 else{
2238 return true;
2239 }
2240 }
2241 return true;
2242 }
2243
2244 AysSurveyPlugin.prototype.toggleFullscreen = function (elem) {
2245 var _this = this;
2246 elem = elem || document.documentElement;
2247 if (!document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement) {
2248 _this.aysSurveyFullScreenActivate( elem );
2249 _this.aysSurveyFullScreenWindowActivator( elem );
2250 }else{
2251 _this.aysSurveyFullScreenDeactivate( elem );
2252 _this.aysSurveyFullScreenWindowDeactivator();
2253 }
2254 }
2255
2256 AysSurveyPlugin.prototype.aysSurveyFullScreenActivate = function (elem) {
2257 $(elem).css({'background-color':'#fff'});
2258 $(elem).find('.ays-survey-full-screen-mode .ays-survey-close-full-screen').css({'display':'inline'});
2259 $(elem).find('.ays-survey-full-screen-mode .ays-survey-open-full-screen').css('display','none');
2260 $(elem).find('.ays-survey-full-screen-mode').css({'padding-right':'15px'});
2261 $(elem).css({'overflow':'auto'});
2262 }
2263
2264 AysSurveyPlugin.prototype.aysSurveyFullScreenDeactivate = function (elem) {
2265 $(elem).css({'background-color':'initial'});
2266 $(elem).find('.ays-survey-full-screen-mode .ays-survey-open-full-screen').css({'display':'inline'});
2267 $(elem).find('.ays-survey-full-screen-mode .ays-survey-close-full-screen').css('display','none');
2268 $(elem).find('.ays-survey-full-screen-mode').css({'padding-right':'0'});
2269 $(elem).css({'overflow':'initial'});
2270 }
2271
2272 AysSurveyPlugin.prototype.aysSurveyFullScreenDeactivateAll = function (elem) {
2273 var _this = this;
2274 document.addEventListener('fullscreenchange', function(event) {
2275 if (!document.fullscreenElement) {
2276 var eventTarget = event.target;
2277 if( $( eventTarget ).hasClass('ays-survey-container') ){
2278 _this.aysSurveyFullScreenDeactivate( eventTarget );
2279 }
2280 }
2281 }, false);
2282 }
2283
2284 AysSurveyPlugin.prototype.aysSurveyFullScreenWindowActivator = function (elem) {
2285 if (elem.requestFullscreen) {
2286 elem.requestFullscreen();
2287 }else if (elem.msRequestFullscreen) {
2288 elem.msRequestFullscreen();
2289 }else if (elem.mozRequestFullScreen) {
2290 elem.mozRequestFullScreen();
2291 }else if (elem.webkitRequestFullscreen) {
2292 elem.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
2293 }
2294 }
2295
2296 AysSurveyPlugin.prototype.aysSurveyFullScreenWindowDeactivator = function () {
2297 if(document.exitFullscreen) {
2298 document.exitFullscreen();
2299 }else if (document.msExitFullscreen) {
2300 document.msExitFullscreen();
2301 }else if (document.mozCancelFullScreen) {
2302 document.mozCancelFullScreen();
2303 }else if (document.webkitExitFullscreen) {
2304 document.webkitExitFullscreen();
2305 }
2306 }
2307
2308 AysSurveyPlugin.prototype.aysSurveyCheckTextLimit = function(question, options,e,current) {
2309 var $this = current;
2310 var _this = this;
2311 var box = question.find('.ays-survey-question-text-message');
2312 var questionTextMessage = question.find('.ays-survey-question-text-message-span');
2313 // Maximum length of a text field
2314 var enable_question_text_max_length = (options.enable_word_limitation && options.enable_word_limitation != "") ? options.enable_word_limitation : false;
2315 // Length
2316 var question_text_max_length = (options.limit_length && options.limit_length != "") ? parseInt(options.limit_length) : '';
2317 // Limit by
2318 var question_limit_text_type = (options.limit_by && options.limit_by != "") ? options.limit_by : '';
2319 // Show word/character counter
2320 var question_enable_text_message = (options.limit_counter && options.limit_counter != '') ? options.limit_counter : false;
2321
2322 var remainder = '';
2323 if(question_text_max_length != '' && question_text_max_length != 0){
2324 switch ( question_limit_text_type ) {
2325 case 'char':
2326 var tval = $this.val();
2327 var tlength = tval.length;
2328 var set = question_text_max_length;
2329 var remain = parseInt(set - tlength);
2330 if (remain <= 0 && e.which !== 0 && e.charCode !== 0) {
2331 $this.val((tval).substring(0, tlength - 1));
2332 }
2333 if (e.type=="keyup") {
2334 var tval = $this.val().trim();
2335 if(tval.length > 0 && tval != null){
2336 var wordsLength = $this[0].value.split('').length;
2337 if (wordsLength > question_text_max_length) {
2338 var trimmed = tval.split('', question_text_max_length).join("");
2339 $this.val(trimmed);
2340 }
2341 }
2342 }
2343 remainder = remain;
2344 break;
2345 case 'word':
2346 if (e.type=="keyup") {
2347 var tval = $this.val().trim();
2348 if(tval.length > 0 && tval != null){
2349 var wordsLength = $this[0].value.match(/\S+/g).length;
2350 if (wordsLength > question_text_max_length) {
2351 var trimmed = tval.split(/\s+/, question_text_max_length).join(" ");
2352 $this.val(trimmed + " ");
2353 }
2354 remainder = question_text_max_length - wordsLength;
2355 }
2356 }
2357 break;
2358 default:
2359 break;
2360 }
2361 if (e.type=="keyup") {
2362 if ( question_enable_text_message ) {
2363 if(question_text_max_length != '' && question_text_max_length != 0){
2364 if (remainder <= 0) {
2365 remainder = 0;
2366 if (! box.hasClass(_this.htmlClassPrefix + ' question-text-error-message') ) {
2367 box.addClass(_this.htmlClassPrefix + 'question-text-error-message')
2368 }
2369 }else{
2370 if ( box.hasClass(_this.htmlClassPrefix + 'question-text-error-message') ) {
2371 box.removeClass(_this.htmlClassPrefix + 'question-text-error-message')
2372 }
2373 }
2374 if (tval.length == 0 || tval == null) {
2375 if ( box.hasClass(_this.htmlClassPrefix + 'question-text-error-message') ) {
2376 box.removeClass(_this.htmlClassPrefix + 'question-text-error-message')
2377 }
2378 remainder = question_text_max_length;
2379 }
2380
2381 questionTextMessage.html( remainder );
2382 }
2383 }
2384 }
2385 }
2386 }
2387
2388 AysSurveyPlugin.prototype.aysSurveyCheckNumberLimit = function(question, options,e,current) {
2389 var $this = current;
2390 var _this = this;
2391 var errorBox = question.find('.ays-survey-number-limit-message-box');
2392 question.removeClass('ays-has-error');
2393 errorBox.hide();
2394 var limitBox = question.find('.ays-survey-question-text-message');
2395 var questionTextMessage = question.find('.ays-survey-question-text-message-span');
2396 // Enable Limitation
2397 var enableQuestionLimit = (options.enable_number_limitation && options.enable_number_limitation != "") ? options.enable_number_limitation : false;
2398 // Min Value
2399 var questionTextMinValue = (options.number_min_selection && options.number_min_selection != "") ? parseInt(options.number_min_selection) : '';
2400 // Max Value
2401 var questionTextMaxValue = (options.number_max_selection && options.number_max_selection != "") ? parseInt(options.number_max_selection) : '';
2402 // Show error message
2403 var enableTextMessage = (options.enable_number_error_message && options.enable_number_error_message != '') ? options.enable_number_error_message : false;
2404 // Max Length
2405 var questionTextMaxLength = (options.number_limit_length && options.number_limit_length != "") ? parseInt(options.number_limit_length) : '';
2406 // Show char length
2407 var questionEnableTextMessage = (options.enable_number_limit_counter && options.enable_number_limit_counter != '') ? options.enable_number_limit_counter : false;
2408 if(questionTextMinValue >= questionTextMaxValue){
2409 questionTextMaxValue = questionTextMinValue;
2410 }
2411 if(enableQuestionLimit){
2412 var remainder = '';
2413 var showErrorMessage = 0;
2414 if(questionTextMaxLength != '' && questionTextMaxLength != 0){
2415 var tval = $this.val();
2416 var tlength = tval.length;
2417 var set = questionTextMaxLength;
2418 var remain = parseInt(set - tlength);
2419 // if (remain <= 0 && e.which !== 0 && e.charCode !== 0) {
2420 // $this.val((tval).substring(0, tlength - 1));
2421 // }
2422 // if (e.type=="keyup") {
2423 var tval = $this.val().trim();
2424 if(tval.length > 0 && tval != null){
2425
2426 var wordsLength = $this[0].value.split('').length;
2427 if (wordsLength > questionTextMaxLength) {
2428 // var trimmed = tval.split('', questionTextMaxLength).join("");
2429 // $this.val(trimmed);
2430 showErrorMessage++;
2431 question.addClass('ays-has-error');
2432 } else {
2433 // Remove error class if length is within limit
2434 question.removeClass('ays-has-error');
2435 }
2436 }
2437 // }
2438 remainder = remain;
2439 }
2440 var enteredValue = $this.val().trim();
2441 var inputValue = parseInt( enteredValue );
2442
2443 // Check if min value exists and min value not 0
2444 if(questionTextMinValue != '' && questionTextMinValue != 0){
2445 if( ! isNaN(inputValue) ){
2446 // if (e.type=="keyup") {
2447 if ( inputValue < questionTextMinValue ) {
2448 // $this.val(questionTextMinValue);
2449 showErrorMessage++;
2450 question.addClass('ays-has-error');
2451 }
2452 // }
2453 }
2454 }
2455
2456 // Check if min value exists and max value not 0
2457 if(questionTextMaxValue != '' && questionTextMaxValue != 0){
2458 // if (e.type=="keyup") {
2459 if ( inputValue > questionTextMaxValue ) {
2460 // $this.val(questionTextMaxValue);
2461 showErrorMessage++;
2462 question.addClass('ays-has-error');
2463 }
2464 // }
2465 }
2466
2467 // Check if min value exists and min value <= 0
2468 if(questionTextMaxValue != '' && questionTextMinValue <= 0){
2469 if( ! isNaN(inputValue) ){
2470 // if (e.type=="keyup") {
2471 if ( inputValue < questionTextMinValue ) {
2472 // $this.val(questionTextMinValue);
2473 showErrorMessage++;
2474 question.addClass('ays-has-error');
2475 }
2476 // }
2477 }
2478 }
2479 // if (e.type=="keyup") {
2480 $this.val(tval.substring(0, questionTextMaxLength));
2481 // Remove error class after trimming text to valid length
2482 if ($this.val().length <= questionTextMaxLength) {
2483 question.removeClass('ays-has-error');
2484 }
2485 if ( questionEnableTextMessage ) {
2486 if(questionTextMaxLength != '' && questionTextMaxLength != 0){
2487 if (remainder <= 0) {
2488 remainder = 0;
2489 if (! limitBox.hasClass(_this.htmlClassPrefix + 'question-text-error-message') ) {
2490 limitBox.addClass(_this.htmlClassPrefix + 'question-text-error-message')
2491 }
2492 }else{
2493 if ( limitBox.hasClass(_this.htmlClassPrefix + 'question-text-error-message') ) {
2494 limitBox.removeClass(_this.htmlClassPrefix + 'question-text-error-message')
2495 }
2496 }
2497 if (tval.length == 0 || tval == null) {
2498 if ( limitBox.hasClass(_this.htmlClassPrefix + 'question-text-error-message') ) {
2499 limitBox.removeClass(_this.htmlClassPrefix + 'question-text-error-message')
2500 }
2501 remainder = questionTextMaxLength;
2502 }
2503
2504 questionTextMessage.html( remainder );
2505 }
2506 }
2507 // }
2508 if(enableTextMessage && showErrorMessage > 0){
2509 errorBox.show();
2510 }
2511
2512 }
2513 }
2514
2515 AysSurveyPlugin.prototype.checkTermsAndConds = function( item ){
2516 var _this = this;
2517 var alltermsCondsCount = item.find('.' + _this.htmlClassPrefix + 'is-checked-terms-and-conditions').length;
2518 var checkedTermsConsdCount = item.find('.' + _this.htmlClassPrefix + 'is-checked-terms-and-conditions:checked').length;
2519 if( alltermsCondsCount != checkedTermsConsdCount ){
2520 if( _this.dbOptions['enable_terms_and_conditions_required_message' ] ){
2521 item.find('.'+_this.htmlClassPrefix+'section-terms-and-conditions-required-message-content').css( 'display', 'block' );
2522 }
2523 item.find('.' + _this.htmlClassPrefix + 'is-checked-terms-and-conditions:not(:checked)').next().addClass('ays-has-error');
2524 return false;
2525 }else{
2526 return true;
2527 }
2528 }
2529
2530 AysSurveyPlugin.prototype.aysSurveyonTabPress = function() {
2531 var _this = this;
2532 _this.$el.on('keydown', (e) => {
2533 var selectedBox = $(e.target);
2534 if( !selectedBox.hasClass( 'ays-survey-answer-text-inputs' ) ){
2535 if (e.keyCode === 32) {
2536 e.preventDefault();
2537 if(selectedBox.hasClass('ays-survey-section-button-container')){
2538 selectedBox.find('.ays-survey-section-button').trigger("click");
2539 }
2540 else{
2541 selectedBox.trigger("click");
2542 }
2543 }
2544 }
2545 });
2546 }
2547
2548 AysSurveyPlugin.prototype.aysAutoNext = function(button) {
2549 var _this = this;
2550 var checkedRadiosCount = 0;
2551 var activeSection = button.parents('.ays-survey-section.active-section');
2552
2553 var sectionQuestions = activeSection.find('.ays-survey-section-questions .ays-survey-question');
2554 var sectionQuestionsCount = sectionQuestions.length;
2555
2556 var checkedRadios = sectionQuestions.find('input[type="radio"]:checked');
2557 checkedRadiosCount += checkedRadios.length;
2558
2559 var changedDropdown = sectionQuestions.find('input.ays-survey-detect-selected-question-dropdown');
2560
2561 changedDropdown.each(function() {
2562 if ($(this).val().trim() !== '') {
2563 checkedRadiosCount++;
2564 }
2565 });
2566
2567 var nextButton = activeSection.find('.' + _this.htmlClassPrefix + 'next-button');
2568 if((checkedRadiosCount >= sectionQuestionsCount) && nextButton.hasClass('display_none_important')){
2569 nextButton.trigger('click');
2570 }
2571 }
2572
2573 /**
2574 * @return {string}
2575 */
2576 function AddZero(num) {
2577 return (num >= 0 && num < 10) ? "0" + num : num + "";
2578 }
2579
2580 /**
2581 * @return {string}
2582 */
2583 function aysEscapeHtml(text) {
2584 var map = {
2585 '&': '&amp;',
2586 '<': '&lt;',
2587 '>': '&gt;',
2588 '"': '&quot;',
2589 "'": '&#039;'
2590 };
2591 return text.replace(/[&<>\"']/g, function(m) { return map[m]; });
2592 }
2593
2594 function validatePhoneNumber(input) {
2595 var phoneno = /^[+ 0-9-]+$/;
2596 if (input.value.match(phoneno)) {
2597 return true;
2598 } else {
2599 return false;
2600 }
2601 }
2602
2603 function surveySanitizeSpecificContent(content) {
2604 // Pattern to match <script> tags and dangerous attributes
2605 const pattern = /<script.*?>.*?<\/script>|<[^>]+(?:\bon\w+\s*=|attributeName\s*=)[^>]*>/gis;
2606
2607 // Replace matched patterns with escaped HTML entities
2608 return content.replace(pattern, match =>
2609 match.replace(/[<>&"'`]/g, char => ({
2610 '<': '&lt;',
2611 '>': '&gt;',
2612 '&': '&amp;',
2613 '"': '&quot;',
2614 "'": '&#39;',
2615 '`': '&#96;'
2616 })[char] || char)
2617 );
2618 }
2619
2620
2621 $.fn.serializeFormJSON = function () {
2622 var o = {},
2623 a = this.serializeArray();
2624 $.each(a, function () {
2625 if (o[this.name]) {
2626 if (!o[this.name].push) {
2627 o[this.name] = [o[this.name]];
2628 }
2629 o[this.name].push(this.value || '');
2630 } else {
2631 o[this.name] = this.value || '';
2632 }
2633 });
2634 return o;
2635 };
2636
2637 $.fn.AysSurveyMaker = function(options) {
2638 return this.each(function() {
2639 if (!$.data(this, 'AysSurveyMaker')) {
2640 $.data(this, 'AysSurveyMaker', new AysSurveyPlugin(this, options));
2641 } else {
2642 try {
2643 $(this).data('AysSurveyMaker').init();
2644 } catch (err) {
2645 console.error('AysSurveyMaker has not initiated properly');
2646 }
2647 }
2648 });
2649 };
2650
2651 })(jQuery);
2652