PluginProbe
Survey Maker by AYS / 5.2.2.8
Survey Maker by AYS v5.2.2.8
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.2.8, at public/js/survey-maker-public-plugin.js

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