PluginProbe
Survey Maker by AYS / 5.2.3.0
Survey Maker by AYS v5.2.3.0
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.3.0, at public/js/survey-maker-public-plugin.js

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