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

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

2,512 lines 123.6 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
74 AysSurveyPlugin.prototype.setup = function(e) {
75 var _this = this;
76 _this.sectionsContainer = _this.$el.find('.' + _this.htmlClassPrefix + 'sections');
77 _this.sections = _this.sectionsContainer.find('.' + _this.htmlClassPrefix + 'section');
78
79 _this.sections.first().addClass('active-section');
80
81 var questionTypeText = $(document).find('textarea.' + _this.htmlClassPrefix + 'question-input-textarea');
82 autosize(questionTypeText);
83
84 var questionTypeSelect = $(document).find('.' + _this.htmlClassPrefix + 'question-select');
85
86 questionTypeSelect.each(function(){
87 $(this).aysDropdown({
88 duration: 150,
89 transition: 'scale'
90 });
91 });
92
93 if( _this.dbOptions.options ){
94 if( _this.dbOptions.options.survey_enable_info_autofill ){
95 var checkAutoFill = _this.dbOptions.options.survey_enable_info_autofill.length > 0 && _this.dbOptions.options.survey_enable_info_autofill == "on" ? true : false;
96 if(checkAutoFill){
97 var form = _this.$el.find('form');
98 var data = form.serializeFormJSON();
99 data.action = _this.ajaxAction;
100 data.function = 'ays_survey_get_user_information';
101 data.end_date = _this.GetFullDateTime();
102 data.unique_id = _this.uniqueId;
103 data.nonce = aysSurveyMakerAjaxPublic.autofill_nonce;
104 _this.aysAutofillData(data , _this.$el);
105 }
106 }
107 }
108 }
109
110 AysSurveyPlugin.prototype.setEvents = function(e) {
111 var _this = this;
112
113 _this.aysNext();
114 _this.aysFinish();
115
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.aysAnimateStep = function(animation, current_fs, next_fs){
763 var _this = this;
764 if(typeof next_fs !== "undefined"){
765 switch(animation){
766 case "lswing":
767 current_fs.parents('.ays-questions-container').css({
768 perspective: '800px',
769 });
770
771 current_fs.addClass('swing-out-right-bck');
772 current_fs.css({
773 'pointer-events': 'none'
774 });
775 setTimeout(function(){
776 current_fs.css({
777 'position': 'absolute',
778 });
779 next_fs.css('display', 'flex');
780 next_fs.addClass('swing-in-left-fwd');
781 },400);
782 setTimeout(function(){
783 current_fs.hide();
784 current_fs.css({
785 'pointer-events': 'auto',
786 'position': 'static'
787 });
788 next_fs.css({
789 'position':'relative',
790 'pointer-events': 'auto'
791 });
792 current_fs.removeClass('swing-out-right-bck');
793 next_fs.removeClass('swing-in-left-fwd');
794 _this.animating = false;
795 },1000);
796 break;
797 case "rswing":
798 current_fs.parents('.ays-questions-container').css({
799 perspective: '800px',
800 });
801
802 current_fs.addClass('swing-out-left-bck');
803 current_fs.css({
804 'pointer-events': 'none'
805 });
806 setTimeout(function(){
807 current_fs.css({
808 'position': 'absolute',
809 });
810 next_fs.css('display', 'flex');
811 next_fs.addClass('swing-in-right-fwd');
812 },400);
813 setTimeout(function(){
814 current_fs.hide();
815 current_fs.css({
816 'pointer-events': 'auto',
817 'position': 'static'
818 });
819 next_fs.css({
820 'position':'relative',
821 'pointer-events': 'auto'
822 });
823 current_fs.removeClass('swing-out-left-bck');
824 next_fs.removeClass('swing-in-right-fwd');
825 _this.animating = false;
826 },1000);
827 break;
828 case "shake":
829 current_fs.animate({opacity: 0}, {
830 step: function (now, mx) {
831 _this.scale = 1 - (1 - now) * 0.2;
832 _this.left = (now * 50) + "%";
833 _this.opacity = 1 - now;
834 current_fs.css({
835 'transform': 'scale(' + _this.scale + ')',
836 'position': 'absolute',
837 'top':0,
838 'opacity': 1,
839 'pointer-events': 'none'
840 });
841 next_fs.css({
842 'left': _this.left,
843 'opacity': _this.opacity,
844 'display':'flex',
845 'position':'relative',
846 'pointer-events': 'none'
847 });
848 },
849 duration: 800,
850 complete: function () {
851 current_fs.hide();
852 current_fs.css({
853 'pointer-events': 'auto',
854 'opacity': 1,
855 'position': 'static'
856 });
857 next_fs.css({
858 'display':'flex',
859 'position':'relative',
860 'transform':'scale(1)',
861 'opacity': 1,
862 'pointer-events': 'auto'
863 });
864 _this.animating = false;
865 },
866 easing: 'easeInOutBack'
867 });
868 break;
869 case "fade":
870 current_fs.animate({opacity: 0}, {
871 step: function (now, mx) {
872 _this.opacity = 1 - now;
873 current_fs.attr('style' , 'position: absolute !important;width: 100% !important;pointer-events: none !important;');
874 next_fs.attr('style' , 'opacity: '+_this.opacity+' !important;position: relative !important;display: block !important;width: 100% !important;pointer-events: none !important;');
875 },
876 duration: 500,
877 complete: function () {
878 current_fs.hide();
879 current_fs.attr('style' , 'position: static !important;pointer-events: auto !important;');
880 next_fs.attr('style' , 'display: block !important;position: relative !important;opacity: 1 !important;pointer-events: auto !important;');
881 _this.animating = false;
882 }
883 });
884 break;
885 default:
886 current_fs.animate({}, {
887 step: function (now, mx) {
888 current_fs.css({
889 'pointer-events': 'none'
890 });
891 next_fs.css({
892 'position':'relative',
893 'pointer-events': 'none'
894 });
895 },
896 duration: 0,
897 complete: function () {
898 current_fs.hide();
899 current_fs.css({
900 'pointer-events': 'auto'
901 });
902 next_fs.css({
903 'display':'block',
904 'position':'relative',
905 'transform':'scale(1)',
906 'pointer-events': 'auto'
907 });
908 _this.animating = false;
909 }
910 });
911 break;
912 }
913 }else{
914 switch(animation){
915 case "lswing":
916 current_fs.parents('.ays-questions-container').css({
917 perspective: '800px',
918 });
919 current_fs.addClass('swing-out-right-bck');
920 current_fs.css({
921 'pointer-events': 'none'
922 });
923 setTimeout(function(){
924 current_fs.css({
925 'position': 'absolute',
926 });
927 },400);
928 setTimeout(function(){
929 current_fs.hide();
930 current_fs.css({
931 'pointer-events': 'auto',
932 'position': 'static'
933 });
934 current_fs.removeClass('swing-out-right-bck');
935 _this.animating = false;
936 },1000);
937 break;
938 case "rswing":
939 current_fs.parents('.ays-questions-container').css({
940 perspective: '800px',
941 });
942 current_fs.addClass('swing-out-left-bck');
943 current_fs.css({
944 'pointer-events': 'none'
945 });
946 setTimeout(function(){
947 current_fs.css({
948 'position': 'absolute',
949 });
950 },400);
951 setTimeout(function(){
952 current_fs.hide();
953 current_fs.css({
954 'pointer-events': 'auto',
955 'position': 'static'
956 });
957 current_fs.removeClass('swing-out-left-bck');
958 _this.animating = false;
959 },1000);
960 case "shake":
961 current_fs.animate({opacity: 0}, {
962 step: function (now, mx) {
963 _this.scale = 1 - (1 - now) * 0.2;
964 _this.left = (now * 50) + "%";
965 _this.opacity = 1 - now;
966 current_fs.css({
967 'transform': 'scale(' + _this.scale + ')',
968 });
969 },
970 duration: 800,
971 complete: function () {
972 current_fs.hide();
973 _this.animating = false;
974 },
975 easing: 'easeInOutBack'
976 });
977 break;
978 case "fade":
979 current_fs.animate({opacity: 0}, {
980 step: function (now, mx) {
981 _this.opacity = 1 - now;
982 },
983 duration: 500,
984 complete: function () {
985 current_fs.hide();
986 _this.animating = false;
987 },
988 easing: 'easeInOutBack'
989 });
990 break;
991 default:
992 current_fs.animate({}, {
993 step: function (now, mx) {
994
995 },
996 duration: 0,
997 complete: function () {
998 current_fs.hide();
999 _this.animating = false;
1000 }
1001 });
1002 break;
1003 }
1004 }
1005 }
1006
1007 AysSurveyPlugin.prototype.activeStep = function(button, action) {
1008 var _this = this;
1009 _this.current_fs = button.parents('.' + _this.htmlClassPrefix + 'section');
1010 if(action == 'next'){
1011 _this.next_fs = button.parents('.' + _this.htmlClassPrefix + 'section').next();
1012 }
1013 if(action == 'prev'){
1014 _this.next_fs = button.parents('.' + _this.htmlClassPrefix + 'section').prev();
1015 }
1016 _this.current_fs.removeClass('active-section');
1017 _this.next_fs.addClass('active-section');
1018 }
1019
1020 AysSurveyPlugin.prototype.startLiveProgressBar = function(button) {
1021 var _this = this;
1022 if (button.parents('.step').next().find('.information_form').length === 0 ){
1023 var questions_count = _this.$el.find('form').find('div[data-question-id]').length;
1024 var curent_number = _this.$el.find('form').find('div[data-question-id]').index(button.parents('div[data-question-id]')) + 1;
1025 var final_width = ((curent_number+1) / questions_count * 100) + "%";
1026 if(button.parents('.ays-quiz-container').find('.ays-live-bar-percent').hasClass('ays-live-bar-count')){
1027 button.parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(curent_number+1));
1028 }else{
1029 button.parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(final_width));
1030 }
1031 button.parents('.ays-quiz-container').find('.ays-live-bar-fill').animate({'width': final_width}, 500);
1032 }
1033 }
1034
1035 AysSurveyPlugin.prototype.actionLiveProgressBar = function(button, action) {
1036 var _this = this;
1037 var questions_count = _this.$el.find('form').find('div[data-question-id]').length;
1038 var curent_number;
1039 if(action == 'next'){
1040 curent_number = _this.$el.find('form').find('div[data-question-id]').index(button.parents('div[data-question-id]')) + 1;
1041 }
1042 if(action == 'prev'){
1043 curent_number = _this.$el.find('form').find('div[data-question-id]').index(button.parents('div[data-question-id]')) - 1;
1044 }
1045 if(curent_number != questions_count){
1046 if((button.hasClass('ays_finish')) == false){
1047 if (!($(this).hasClass('start_button'))) {
1048 var current_width = button.parents('.ays-quiz-container').find('.ays-live-bar-fill').width();
1049 var final_width = ((curent_number+1) / questions_count * 100) + "%";
1050 if(button.parents('.ays-quiz-container').find('.ays-live-bar-percent').hasClass('ays-live-bar-count')){
1051 button.parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(curent_number+1));
1052 }else{
1053 button.parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(final_width));
1054 }
1055 button.parents('.ays-quiz-container').find('.ays-live-bar-fill').animate({'width': final_width}, 500);
1056 }
1057 }
1058 }else{
1059 button.parents('.ays-quiz-container').find('.ays-live-bar-wrap').removeClass('rubberBand').addClass('bounceOut');
1060 setTimeout(function () {
1061 button.parents('.ays-quiz-container').find('.ays-live-bar-wrap').css('display','none');
1062 },300)
1063 }
1064
1065 if(questions_count === curent_number){
1066 if(_this.current_fs.hasClass('.information_form').length !== 0){
1067 _this.current_fs.parents('.ays-quiz-container').find('.ays-quiz-timer').parent().slideUp(500);
1068 setTimeout(function () {
1069 _this.current_fs.parents('.ays-quiz-container').find('.ays-quiz-timer').parent().remove();
1070 },500);
1071 }
1072 }
1073 }
1074
1075 AysSurveyPlugin.prototype.checkForm = function( button ){
1076 var _this = this;
1077 _this.animating = false;
1078
1079 var section = button.parents('.' + _this.htmlClassPrefix + 'section');
1080 var requiredQuestions = section.find('[data-required="true"]');
1081 if ( requiredQuestions.length !== 0) {
1082 var empty_inputs = 0;
1083 var errorQuestions = section.find('.ays-has-error');
1084 section.find('.ays-has-error').removeClass('ays-has-error');
1085 for (var i = 0; i < requiredQuestions.length; i++) {
1086 var item = requiredQuestions.eq(i);
1087 var checkMinVotes = requiredQuestions.eq(i).data('isMin');
1088 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'){
1089 var errorMessage = '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">';
1090
1091 if(item.data('type') == 'date_time'){
1092 var dateTimeInps = item.find( '.' + _this.htmlClassPrefix + 'input' );
1093 var dateTimeInps = item.find( '.' + _this.htmlClassPrefix + 'input:not(.' + _this.htmlClassPrefix + 'not-required-field)' );
1094 var dateTimeChecker = true;
1095 dateTimeInps.each(function(e,i){
1096 if($(i).val() == ''){
1097 dateTimeChecker = false;
1098
1099 if($(dateTimeInps[0]).val() == ''){
1100 $(dateTimeInps[0]).focus();
1101 }
1102 else{
1103 $(dateTimeInps[e]).focus();
1104 }
1105 errorMessage += '<span>' + _this.dbOptions.survey_required_questions_message + '</span>';
1106 item.addClass('ays-has-error');
1107 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').html(errorMessage);
1108 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').show();
1109 _this.goToTop( item );
1110
1111 empty_inputs++;
1112 }
1113 });
1114 if(!dateTimeChecker){
1115 break;
1116 }
1117 }
1118
1119 if( item.find( '.' + _this.htmlClassPrefix + 'input' ).val() == '' ){
1120 errorMessage += '<span>' + _this.dbOptions.survey_required_questions_message + '</span>';
1121 item.addClass('ays-has-error');
1122 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').html(errorMessage);
1123 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').show();
1124 _this.goToTop( item );
1125 item.find( '.' + _this.htmlClassPrefix + 'input' ).focus();
1126 empty_inputs++;
1127 break;
1128 }else{
1129 if( item.data('type') == 'email' ){
1130 if ( ! (_this.emailValidatePattern.test( item.find( '.' + _this.htmlClassPrefix + 'input' ).val() ) ) ) {
1131 errorMessage += '<span>' + surveySanitizeSpecificContent(aysSurveyLangObj.emailValidationError) + '</span>';
1132 item.addClass('ays-has-error');
1133 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').html(errorMessage);
1134 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').show();
1135 _this.goToTop( item );
1136 item.find( '.' + _this.htmlClassPrefix + 'input' ).focus();
1137 empty_inputs++;
1138 }
1139 }else{
1140 if( item.data('type') != 'number' ){
1141 continue;
1142 }
1143 }
1144 }
1145 }
1146
1147 var errorFlag = false;
1148 var checker = false;
1149 if ( item.data('type') == 'radio' || item.data('type') == 'checkbox' || item.data('type') == 'star' ) {
1150 var questionType = item.data('type') === 'star' ? 'radio' : item.data('type') || '';
1151
1152 if(typeof checkMinVotes != 'undefined' && checkMinVotes){
1153 checker = _this.checkMinVotes(item);
1154 if(!checker){
1155 return false;
1156 }
1157 }
1158 if( item.find('input[type="'+ questionType +'"]:checked').length == 0 ){
1159 errorFlag = true;
1160 }
1161
1162 if( item.find('.' + _this.htmlClassPrefix + 'answer-other-input').length != 0 &&
1163 item.find('.' + _this.htmlClassPrefix + 'answer-label-other > input[value="0"]:checked').length > 0 ){
1164 if( item.find('.' + _this.htmlClassPrefix + 'answer-other-input').val() == '' ){
1165 errorFlag = true;
1166 item.find('.' + _this.htmlClassPrefix + 'answer-other-input').focus();
1167 }
1168 }
1169
1170 if( errorFlag ){
1171 var errorMessage = '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">';
1172 errorMessage += '<span>' + _this.dbOptions.survey_required_questions_message + '</span>';
1173 item.addClass('ays-has-error');
1174 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').html(errorMessage);
1175 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').show();
1176 _this.goToTop( item );
1177 empty_inputs++;
1178 break;
1179 }else{
1180 continue;
1181 }
1182 }
1183
1184 if ( item.data('type') == 'select' ) {
1185 if( item.find('.' + _this.htmlClassPrefix + 'question-select').aysDropdown('get value') == '' ){
1186 var errorMessage = '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">';
1187 errorMessage += '<span>' + _this.dbOptions.survey_required_questions_message + '</span>';
1188 item.addClass('ays-has-error');
1189 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').html(errorMessage);
1190 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').show();
1191 _this.goToTop( item );
1192 empty_inputs++;
1193 break;
1194 }else{
1195 continue;
1196 }
1197 }
1198
1199 if( item.data('type') == 'number' ){
1200 var numberInput = item.find('input.ays-survey-check-number-limit');
1201 var currentQuestion = item;
1202 var currentquestionId = currentQuestion.find('.' + _this.htmlClassPrefix + 'question-id').val();
1203 var questionTextLimitOptions = _this.dbOptions[ _this.dbOptionsPrefix + 'number_limit_options' ][currentquestionId];
1204 _this.aysSurveyCheckNumberLimit(currentQuestion,questionTextLimitOptions,numberInput,$(numberInput));
1205
1206 if( item.hasClass('ays-has-error') ){
1207 _this.goToTop( item );
1208 item.find( '.' + _this.htmlClassPrefix + 'input' ).focus();
1209 empty_inputs++;
1210 break;
1211 }else{
1212 continue;
1213 }
1214 }
1215
1216 }
1217
1218 for (var i = 0; i < errorQuestions.length; i++) {
1219 var item = errorQuestions.eq(i);
1220 if( item.data('type') == 'email' ){
1221 if( ! (_this.emailValidatePattern.test( item.find( '.' + _this.htmlClassPrefix + 'input' ).val() ) ) ){
1222 var errorMessage = '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">';
1223 errorMessage += '<span>' + surveySanitizeSpecificContent(aysSurveyLangObj.emailValidationError) + '</span>';
1224
1225 item.addClass('ays-has-error');
1226 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').html(errorMessage);
1227 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').show();
1228 _this.goToTop( item );
1229 item.find( '.' + _this.htmlClassPrefix + 'input' ).focus();
1230 empty_inputs++;
1231 break;
1232 }else{
1233 continue;
1234 }
1235 }
1236 }
1237
1238 if (empty_inputs !== 0) {
1239 return false;
1240 }else{
1241 return true;
1242 }
1243 }
1244 else{
1245 var empty_inputs = 0;
1246 var errorQuestions = section.find('.ays-has-error');
1247 for (var i = 0; i < errorQuestions.length; i++) {
1248 var item = errorQuestions.eq(i);
1249 if( item.data('type') == 'email' ){
1250 if( ! (_this.emailValidatePattern.test( item.find( '.' + _this.htmlClassPrefix + 'input' ).val() ) ) ){
1251 var errorMessage = '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">';
1252 errorMessage += '<span>' + surveySanitizeSpecificContent(aysSurveyLangObj.emailValidationError) + '</span>';
1253
1254 item.addClass('ays-has-error');
1255 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').html(errorMessage);
1256 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').show();
1257 _this.goToTop( item );
1258 item.find( '.' + _this.htmlClassPrefix + 'input' ).focus();
1259 empty_inputs++;
1260 break;
1261 }else{
1262 continue;
1263 }
1264 }
1265 if( item.data('type') == 'number' ){
1266 if( item.hasClass('ays-has-error') ){
1267 _this.goToTop( item );
1268 item.find( '.' + _this.htmlClassPrefix + 'input' ).focus();
1269 empty_inputs++;
1270 break;
1271 }else{
1272 continue;
1273 }
1274 }
1275 }
1276 var questions = section.find('.' + _this.htmlClassPrefix + 'question[data-is-min="true"]');
1277
1278 if(questions.length > 0){
1279 for(var i = 0; i < questions.length; i++){
1280 var checker = _this.checkMinVotes(questions.eq(i));
1281 if(!checker){
1282 return false;
1283 }
1284 }
1285 }
1286 if (empty_inputs !== 0) {
1287 return false;
1288 }else{
1289 return true;
1290 }
1291
1292 }
1293 }
1294
1295 AysSurveyPlugin.prototype.blockedContent = function( blocked ) {
1296 var _this = this;
1297
1298 if( blocked ){
1299 var blockedContent = _this.$el.hasClass( _this.htmlClassPrefix + 'blocked-content' );
1300 if ( blockedContent ) {
1301 var limitAttemptCount = _this.dbOptions[ _this.dbOptionsPrefix + 'limit_users' ];
1302 var redirectUrl = _this.dbOptions[ _this.dbOptionsPrefix + 'redirect_url' ];
1303 if( limitAttemptCount && redirectUrl != ''){
1304 var redirectTimerHTML = '<div class="' + _this.htmlClassPrefix + 'redirect-timer ' + _this.htmlClassPrefix + 'countdown-timer">' +
1305 aysSurveyLangObj.redirectAfter + ' <span class="' + _this.htmlClassPrefix + 'countdown-time">' + _this.dbOptions[ _this.dbOptionsPrefix + 'redirect_delay_seconds' ] + '</span>' +
1306 '</div>';
1307
1308 _this.$el.find('.' + _this.htmlClassPrefix + 'section-header').prepend( $( redirectTimerHTML ) );
1309
1310 var timer = _this.dbOptions[ _this.dbOptionsPrefix + 'redirect_delay' ] + 2;
1311 _this.timer( timer, {
1312 blockedContent: true,
1313 redirectUrl: _this.dbOptions[ _this.dbOptionsPrefix + 'redirect_url' ]
1314 });
1315 }
1316 }
1317 }
1318
1319 if( _this.$el.find('.ays_survey_login_form').length > 0 ){
1320 var surveyLoginForm = _this.$el.find('.ays_survey_login_form');
1321 var usernameInput = surveyLoginForm.find('input[type="text"]');
1322 var passwordInput = surveyLoginForm.find('input[type="password"]');
1323 var checkboxInput = surveyLoginForm.find('input[type="checkbox"]');
1324 var submitInput = surveyLoginForm.find('input[type="submit"]');
1325 _this.makeSurveyStyleInput( usernameInput );
1326 _this.makeSurveyStyleInput( passwordInput );
1327 _this.makeSurveyStyleSubmit( submitInput );
1328 if( checkboxInput.length > 0 ){
1329 _this.makeSurveyStyleCheckbox( checkboxInput );
1330 }
1331 }
1332
1333 if(_this.dbOptions[ _this.dbOptionsPrefix + 'enable_survey_start_loader' ]){
1334 _this.$el.find('.ays-survey-wait-loading-loader').css("display" , "none");
1335 }
1336 }
1337
1338 AysSurveyPlugin.prototype.selects = function(){
1339 var _this = this;
1340 _this.$el.find('.ays-field').on('click', function() {
1341 if ($(this).find(".select2").hasClass('select2-container--open')) {
1342 $(this).find('b[role="presentation"]').removeClass('ays_fa ays_fa_chevron_down');
1343 $(this).find('b[role="presentation"]').addClass('ays_fa ays_fa_chevron_up');
1344 } else {
1345 $(this).find('b[role="presentation"]').removeClass('ays_fa ays_fa_chevron_up');
1346 $(this).find('b[role="presentation"]').addClass('ays_fa ays_fa_chevron_down');
1347 }
1348 });
1349
1350 _this.$el.find('select.ays-select').on("select2:selecting", function(e){
1351 $(this).parents('.ays-quiz-container').find('b[role="presentation"]').addClass('ays_fa ays_fa_chevron_down');
1352 });
1353
1354 _this.$el.find('select.ays-select').on("select2:closing", function(e){
1355 $(this).parents('.ays-quiz-container').find('b[role="presentation"]').addClass('ays_fa ays_fa_chevron_down');
1356 });
1357
1358 _this.$el.find('select.ays-select').on("select2:select", function(e){
1359 $(this).parent().find('.ays-select-field-value').attr("value", $(this).val());
1360 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')) {
1361 $(this).parents('div[data-question-id]').find('.ays_next').trigger('click');
1362 }
1363 if($(this).parents(".ays-questions-container").find('form[id^="ays_finish_quiz"]').hasClass('enable_correction')) {
1364 if ($(this).find('option:selected').data("chisht") == 1) {
1365 $(this).parents('.ays-field').addClass('correct correct_div');
1366 $(this).parents('.ays-field').find('.select2-selection.select2-selection--single').css("border-bottom-color", "green");
1367 } else {
1368 $(this).parents('.ays-field').addClass('wrong wrong_div');
1369 $(this).parents('.ays-field').find('.select2-selection.select2-selection--single').css("border-bottom-color", "red");
1370 }
1371 if ($(this).find('option:selected').data("chisht") == 1) {
1372 $(e.target).parents().eq(3).find('.right_answer_text').fadeIn();
1373 }
1374 else {
1375 $(e.target).parents().eq(3).find('.wrong_answer_text').fadeIn();
1376 }
1377 $(this).attr("disabled", true);
1378 $(e.target).next().css("background-color", "#777");
1379 $(e.target).next().find('.selection').css("background-color", "#777");
1380 $(e.target).next().find('.select2-selection').css("background-color", "#777");
1381 }
1382 var this_select_value = $(this).val();
1383 $(this).find("option").removeAttr("selected");
1384 $(this).find("option[value='"+this_select_value+"']").attr("selected", true);
1385 });
1386 }
1387
1388 AysSurveyPlugin.prototype.answersField = function(){
1389 var _this = this;
1390
1391 _this.$el.on('change', 'input[name^="ays_questions"]', function (e) {
1392 var quizContainer = _this.$el;
1393 if(typeof myOptions != 'undefined'){
1394 var isRequiredQuestion = (_this.dbOptions.make_questions_required && _this.dbOptions.make_questions_required == "on") ? true : false;
1395 if(isRequiredQuestion === true){
1396 if($(e.target).attr('type') === 'radio' || $(e.target).attr('type') === 'checkbox'){
1397 if($(e.target).parents('div[data-question-id]').find('input[name^="ays_questions"]:checked').length != 0){
1398 if (!$(e.target).parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none')){
1399 $(e.target).parents('div[data-question-id]').find('input.ays_next').removeAttr('disabled');
1400 $(e.target).parents('div[data-question-id]').find('input.ays_early_finish').removeAttr('disabled');
1401 }else if(!$(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
1402 $(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').removeAttr('disabled');
1403 $(e.target).parents('div[data-question-id]').find('i.ays_early_finish').removeAttr('disabled');
1404 }
1405 }else{
1406 if (!$(e.target).parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none')){
1407 $(e.target).parents('div[data-question-id]').find('input.ays_next').attr('disabled', true);
1408 $(e.target).parents('div[data-question-id]').find('input.ays_early_finish').attr('disabled', true);
1409 }else if(!$(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
1410 $(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').attr('disabled', true);
1411 $(e.target).parents('div[data-question-id]').find('i.ays_early_finish').attr('disabled', true);
1412 }
1413 }
1414 }
1415 }
1416 }
1417
1418 if($(e.target).parents('.step').hasClass('not_influence_to_score')){
1419 if($(e.target).attr('type') === 'radio') {
1420 $(e.target).parents('.ays-quiz-answers').find('.checked_answer_div').removeClass('checked_answer_div');
1421 $(e.target).parents('.ays-field').addClass('checked_answer_div');
1422 }
1423 if($(e.target).attr('type') === 'checkbox') {
1424 if(!$(e.target).parents('.ays-field').hasClass('checked_answer_div')){
1425 $(e.target).parents('.ays-field').addClass('checked_answer_div');
1426 }else{
1427 $(e.target).parents('.ays-field').removeClass('checked_answer_div');
1428 }
1429 }
1430 var checked_inputs = $(e.target).parents().eq(1).find('input:checked');
1431 if (checked_inputs.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') &&
1432 checked_inputs.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
1433 if (checked_inputs.attr('type') === 'radio') {
1434 checked_inputs.parents('div[data-question-id]').find('.ays_next').trigger('click');
1435 }
1436 }
1437 if ($(e.target).parents().eq(4).hasClass('enable_correction')) {
1438 if (checked_inputs.attr('type') === "radio") {
1439 $(e.target).parents('div[data-question-id]').find('input[name^="ays_questions"]').attr('disabled', true);
1440 $(e.target).parents('div[data-question-id]').find('input[name^="ays_questions"]').off('change');
1441 } else if (checked_inputs.attr('type') === "checkbox") {
1442 $(e.target).attr('disabled', true);
1443 $(e.target).off('change');
1444 }
1445 }
1446 return false;
1447 }
1448
1449 if (quizContainer.find('form').hasClass('enable_correction')) {
1450 var right_answer_sound = quizContainer.find('.ays_quiz_right_ans_sound').get(0);
1451 var wrong_answer_sound = quizContainer.find('.ays_quiz_wrong_ans_sound').get(0);
1452 var finishAfterWrongAnswer = (_this.dbOptions.finish_after_wrong_answer && _this.dbOptions.finish_after_wrong_answer == "on") ? true : false;
1453 if ($(e.target).parents().eq(1).find('input[name="ays_answer_correct[]"]').length !== 0) {
1454 var checked_inputs = $(e.target).parents().eq(1).find('input:checked');
1455 if (checked_inputs.attr('type') === "radio") {
1456
1457 checked_inputs.nextAll().addClass('answered');
1458 checked_inputs.parent().addClass('checked_answer_div');
1459 if (checked_inputs.prev().val() == 1){
1460 checked_inputs.nextAll().addClass('correct')
1461 checked_inputs.parent().addClass('correct_div');
1462 }else{
1463 checked_inputs.nextAll().addClass('wrong');
1464 checked_inputs.parent().addClass('wrong_div');
1465 }
1466
1467 if (checked_inputs.prev().val() == 1) {
1468 if(_this.dbOptions.answers_rw_texts && (_this.dbOptions.answers_rw_texts == 'on_passing' || _this.dbOptions.answers_rw_texts == 'on_both')){
1469 var explanationTime = _this.dbOptions.explanation_time && _this.dbOptions.explanation_time != "" ? parseInt(_this.dbOptions.explanation_time) : 4;
1470 if(! $(e.target).parents('.step').hasClass('not_influence_to_score')){
1471 $(e.target).parents().eq(3).find('.right_answer_text').slideDown(250);
1472 }
1473 _this.explanationTimeout = setTimeout(function(){
1474 if (checked_inputs.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') &&
1475 checked_inputs.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
1476 checked_inputs.parents('div[data-question-id]').find('input.ays_next').trigger('click');
1477 }
1478 }, explanationTime * 1000);
1479 }else{
1480 if (checked_inputs.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') &&
1481 checked_inputs.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
1482 checked_inputs.parents('div[data-question-id]').find('input.ays_next').trigger('click');
1483 }
1484 }
1485 if((right_answer_sound)){
1486 resetPlaying([right_answer_sound, wrong_answer_sound]);
1487 setTimeout(function(){
1488 right_answer_sound.play();
1489 }, 10);
1490 }
1491 } else {
1492 $(e.target).parents('.ays-quiz-answers').find('input[name="ays_answer_correct[]"][value="1"]').parent().addClass('correct_div').addClass('checked_answer_div');
1493 $(e.target).parents('.ays-quiz-answers').find('input[name="ays_answer_correct[]"][value="1"]').nextAll().addClass('correct answered');
1494
1495 if(_this.dbOptions.answers_rw_texts && (_this.dbOptions.answers_rw_texts == 'on_passing' || _this.dbOptions.answers_rw_texts == 'on_both')){
1496 var explanationTime = _this.dbOptions.explanation_time && _this.dbOptions.explanation_time != "" ? parseInt(_this.dbOptions.explanation_time) : 4;
1497 if(! $(e.target).parents('.step').hasClass('not_influence_to_score')){
1498 $(e.target).parents().eq(3).find('.wrong_answer_text').slideDown(250);
1499 }
1500 _this.explanationTimeout = setTimeout(function(){
1501 if (checked_inputs.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') &&
1502 checked_inputs.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
1503 if(finishAfterWrongAnswer){
1504 goToLastPage(e);
1505 }else{
1506 checked_inputs.parents('div[data-question-id]').find('input.ays_next').trigger('click');
1507 }
1508 }else{
1509 if(finishAfterWrongAnswer){
1510 goToLastPage(e);
1511 }
1512 }
1513 }, explanationTime * 1000);
1514 }else{
1515 if (checked_inputs.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') &&
1516 checked_inputs.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
1517 if(finishAfterWrongAnswer){
1518 goToLastPage(e);
1519 }else{
1520 checked_inputs.parents('div[data-question-id]').find('input.ays_next').trigger('click');
1521 }
1522 }else{
1523 if(finishAfterWrongAnswer){
1524 goToLastPage(e);
1525 }
1526 }
1527 }
1528 if((wrong_answer_sound)){
1529 resetPlaying([right_answer_sound, wrong_answer_sound]);
1530 setTimeout(function(){
1531 wrong_answer_sound.play();
1532 }, 10);
1533 }
1534 }
1535 $(e.target).parents('div[data-question-id]').find('input[name^="ays_questions"]').attr('disabled', true);
1536 $(e.target).parents('div[data-question-id]').find('input[name^="ays_questions"]').off('change');
1537 $(e.target).parents('div[data-question-id]').find('.ays-field').css({
1538 'pointer-events': 'none'
1539 });
1540
1541 }else if(checked_inputs.attr('type') === "checkbox"){
1542 checked_inputs = $(e.target);
1543 if (checked_inputs.length === 1) {
1544 checked_inputs.parent().addClass('checked_answer_div');
1545 if(checked_inputs.prev().val() == 1){
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 checked_inputs.parent().addClass('correct_div');
1553 checked_inputs.nextAll().addClass('correct answered');
1554 }else{
1555 if((wrong_answer_sound)){
1556 resetPlaying([right_answer_sound, wrong_answer_sound]);
1557 setTimeout(function(){
1558 wrong_answer_sound.play();
1559 }, 10);
1560 }
1561 if(finishAfterWrongAnswer){
1562 goToLastPage(e);
1563 }
1564 checked_inputs.parent().addClass('wrong_div');
1565 checked_inputs.nextAll().addClass('wrong answered');
1566 }
1567 }else{
1568 for (var i = 0; i < checked_inputs.length; i++) {
1569 if(checked_inputs.eq(i).prev().val() == 1){
1570 if((right_answer_sound)){
1571 resetPlaying([right_answer_sound, wrong_answer_sound]);
1572 setTimeout(function(){
1573 right_answer_sound.play();
1574 }, 10);
1575 }
1576 checked_inputs.eq(i).nextAll().addClass('correct answered');
1577 checked_inputs.eq(i).parent().addClass('correct_div');
1578 checked_inputs.eq(i).parent().addClass('checked_answer_div');
1579 }else{
1580 if((wrong_answer_sound)){
1581 resetPlaying([right_answer_sound, wrong_answer_sound]);
1582 setTimeout(function(){
1583 wrong_answer_sound.play();
1584 }, 10);
1585 }
1586 if(finishAfterWrongAnswer){
1587 goToLastPage(e);
1588 }
1589 checked_inputs.eq(i).parent().addClass('checked_answer_div');
1590 checked_inputs.eq(i).nextAll().addClass('wrong answered');
1591 checked_inputs.eq(i).parent().addClass('wrong_div');
1592 }
1593 }
1594 if(checked_inputs.eq(i).prev().val() == 1){
1595 checked_inputs.eq(i).next().addClass('correct answered');
1596 if((right_answer_sound)){
1597 resetPlaying([right_answer_sound, wrong_answer_sound]);
1598 setTimeout(function(){
1599 right_answer_sound.play();
1600 }, 10);
1601 }
1602 }else{
1603 checked_inputs.eq(i).next().addClass('wrong answered');
1604 if((wrong_answer_sound)){
1605 resetPlaying([right_answer_sound, wrong_answer_sound]);
1606 setTimeout(function(){
1607 wrong_answer_sound.play();
1608 }, 10);
1609 }
1610 }
1611
1612 }
1613 $(e.target).attr('disabled', true);
1614 $(e.target).off('change');
1615 }
1616 }
1617 }else{
1618 if($(e.target).attr('type') === 'radio') {
1619 $(e.target).parents('.ays-quiz-answers').find('.checked_answer_div').removeClass('checked_answer_div');
1620 $(e.target).parents('.ays-field').addClass('checked_answer_div');
1621 }
1622 if($(e.target).attr('type') === 'checkbox') {
1623 if(!$(e.target).parents('.ays-field').hasClass('checked_answer_div')){
1624 $(e.target).parents('.ays-field').addClass('checked_answer_div');
1625 }else{
1626 $(e.target).parents('.ays-field').removeClass('checked_answer_div');
1627 }
1628 }
1629 var checked_inputs = $(e.target).parents().eq(1).find('input:checked');
1630 if (checked_inputs.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') &&
1631 checked_inputs.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
1632 if (checked_inputs.attr('type') === 'radio') {
1633 checked_inputs.parents('div[data-question-id]').find('input.ays_next').trigger('click');
1634 }
1635 }
1636 }
1637 });
1638
1639 _this.$el.find('button.ays_check_answer').on('click', function (e) {
1640 var thisAnswerOptions;
1641 var quizContainer = _this.$el;
1642 var right_answer_sound = quizContainer.find('.ays_quiz_right_ans_sound').get(0);
1643 var wrong_answer_sound = quizContainer.find('.ays_quiz_wrong_ans_sound').get(0);
1644 var questionId = $(this).parents('.step').data('questionId');
1645 var finishAfterWrongAnswer = (_this.dbOptions.finish_after_wrong_answer && _this.dbOptions.finish_after_wrong_answer == "on") ? true : false;
1646 thisAnswerOptions = _this.QuizQuestionsOptions[questionId];
1647 if($(this).parent().find('.ays-text-input').val() !== ""){
1648 if ($(e.target).parents('form[id^="ays_finish_quiz"]').hasClass('enable_correction')) {
1649 if($(e.target).parents('.step').hasClass('not_influence_to_score')){
1650 return false;
1651 }
1652 $(this).css({
1653 animation: "bounceOut .5s",
1654 });
1655 setTimeout(function(){
1656 $(e.target).parent().find('.ays-text-input').css('width', '100%');
1657 $(e.target).css("display", "none");
1658 },480);
1659 $(e.target).parent().find('.ays-text-input').css('background-color', '#eee');
1660 $(this).parent().find('.ays-text-input').attr('disabled', 'disabled');
1661 $(this).attr('disabled', 'disabled');
1662 $(this).off('change');
1663 $(this).off('click');
1664
1665 var input = $(this).parent().find('.ays-text-input');
1666 var type = input.attr('type');
1667 var userAnsweredText = input.val().trim();
1668
1669 var trueAnswered = false;
1670 var thisQuestionAnswer = thisAnswerOptions.question_answer.toLowerCase();
1671
1672 if(type == 'date'){
1673 var correctDate = new Date(thisAnswerOptions.question_answer),
1674 correctDateYear = correctDate.getFullYear(),
1675 correctDateMonth = correctDate.getMonth(),
1676 correctDateDay = correctDate.getDate();
1677 var userDate = new Date(userAnsweredText),
1678 userDateYear = userDate.getFullYear(),
1679 userDateMonth = userDate.getMonth(),
1680 userDateDay = userDate.getDate();
1681 if(correctDateYear == userDateYear && correctDateMonth == userDateMonth && correctDateDay == userDateDay){
1682 trueAnswered = true;
1683 }
1684 }else if(type != 'number'){
1685 thisQuestionAnswer = thisQuestionAnswer.split('%%%');
1686 for(var i = 0; i < thisQuestionAnswer.length; i++){
1687 if(userAnsweredText.toLowerCase() == thisQuestionAnswer[i].trim()){
1688 trueAnswered = true;
1689 break;
1690 }
1691 }
1692 }else{
1693 if(userAnsweredText.toLowerCase() == thisQuestionAnswer.trim()){
1694 trueAnswered = true;
1695 }
1696 }
1697
1698 if(trueAnswered){
1699 if((right_answer_sound)){
1700 resetPlaying([right_answer_sound, wrong_answer_sound]);
1701 setTimeout(function(){
1702 right_answer_sound.play();
1703 }, 10);
1704 }
1705 $(this).parent().find('.ays-text-input').css('background-color', 'rgba(39,174,96,0.5)');
1706 $(this).parent().find('input[name="ays_answer_correct[]"]').val(1);
1707 }else{
1708 if((wrong_answer_sound)){
1709 resetPlaying([right_answer_sound, wrong_answer_sound]);
1710 setTimeout(function(){
1711 wrong_answer_sound.play();
1712 }, 10);
1713 }
1714 $(this).parent().find('.ays-text-input').css('background-color', 'rgba(243,134,129,0.8)');
1715 $(this).parent().find('input[name="ays_answer_correct[]"]').val(0);
1716 var rightAnswerText = '<div class="ays-text-right-answer">';
1717
1718 if(type == 'date'){
1719 var correctDate = new Date(thisAnswerOptions.question_answer),
1720 correctDateYear = correctDate.getFullYear(),
1721 correctDateMonth = (correctDate.getMonth() + 1) < 10 ? "0"+(correctDate.getMonth() + 1) : (correctDate.getMonth() + 1),
1722 correctDateDay = (correctDate.getDate() < 10) ? "0"+correctDate.getDate() : correctDate.getDate();
1723 rightAnswerText += [correctDateMonth, correctDateDay, correctDateYear].join('/');
1724 }else if(type != 'number'){
1725 rightAnswerText += thisQuestionAnswer[0];
1726 }else{
1727 rightAnswerText += thisQuestionAnswer;
1728 }
1729
1730 rightAnswerText += '</div>';
1731 $(this).parents('.ays-quiz-answers').append(rightAnswerText);
1732 $(this).parents('.ays-quiz-answers').find('.ays-text-right-answer').slideDown(500);
1733 if(finishAfterWrongAnswer){
1734 goToLastPage(e);
1735 }
1736 }
1737 }
1738 }
1739 });
1740 }
1741
1742 AysSurveyPlugin.prototype.makeSurveyStyleInput = function( input ) {
1743 var _this = this;
1744
1745 var html = '<div class="' + _this.htmlClassPrefix + 'question-input-box">'+
1746 '<div class="' + _this.htmlClassPrefix + 'input-underline"></div>'+
1747 '<div class="' + _this.htmlClassPrefix + 'input-underline-animation"></div>'+
1748 '</div>';
1749 html = $( html );
1750
1751 html.insertAfter( input );
1752
1753 html.prepend( input );
1754
1755 input.addClass( _this.htmlClassPrefix + 'input' );
1756 input.addClass( _this.htmlClassPrefix + 'question-input' );
1757 }
1758
1759 AysSurveyPlugin.prototype.makeSurveyStyleCheckbox = function( input ) {
1760 var _this = this;
1761
1762 var html = '<div class="' + _this.htmlClassPrefix + 'answer-label-content">'+
1763 '<div class="' + _this.htmlClassPrefix + 'answer-icon-content">'+
1764 '<div class="' + _this.htmlClassPrefix + 'answer-icon-ink"></div>'+
1765 '<div class="' + _this.htmlClassPrefix + 'answer-icon-content-1">'+
1766 '<div class="' + _this.htmlClassPrefix + 'answer-icon-content-2">'+
1767 '<div class="' + _this.htmlClassPrefix + 'answer-icon-content-3"></div>'+
1768 '</div>'+
1769 '</div>'+
1770 '</div>'+
1771 '<span class=""></span>'+
1772 '</div>';
1773 html = $( html );
1774
1775 var inputCheckboxLabel = input.parents('label');
1776 var inputCheckbox = input;
1777
1778 inputCheckboxLabel.addClass('ays-survey-answer-label');
1779 html.find('span').text( inputCheckboxLabel.text() );
1780 inputCheckboxLabel.text('');
1781 input.remove();
1782 inputCheckboxLabel.prepend( inputCheckbox );
1783 html.insertAfter( inputCheckbox );
1784 }
1785
1786 AysSurveyPlugin.prototype.makeSurveyStyleRadio = function( input ) {
1787 var _this = this;
1788
1789 var html = '<div class="' + _this.htmlClassPrefix + 'answer-label-content">'+
1790 '<div class="' + _this.htmlClassPrefix + 'answer-icon-content">'+
1791 '<div class="' + _this.htmlClassPrefix + 'answer-icon-ink"></div>'+
1792 '<div class="' + _this.htmlClassPrefix + 'answer-icon-content-1">'+
1793 '<div class="' + _this.htmlClassPrefix + 'answer-icon-content-2">'+
1794 '<div class="' + _this.htmlClassPrefix + 'answer-icon-content-3"></div>'+
1795 '</div>'+
1796 '</div>'+
1797 '</div>'+
1798 '<span class=""></span>'+
1799 '</div>';
1800 html = $( html );
1801
1802 var inputCheckboxLabel = input.parents('label');
1803 var inputCheckbox = input;
1804
1805 inputCheckboxLabel.addClass('ays-survey-answer-label');
1806 html.find('span').text( inputCheckboxLabel.text() );
1807 inputCheckboxLabel.text('');
1808 input.remove();
1809 inputCheckboxLabel.prepend( inputCheckbox );
1810 html.insertAfter( inputCheckbox );
1811 }
1812
1813 AysSurveyPlugin.prototype.makeSurveyStyleSubmit = function( input ) {
1814 var _this = this;
1815
1816 var html = '<div class="' + _this.htmlClassPrefix + 'section-buttons">'+
1817 '<div class="' + _this.htmlClassPrefix + 'section-button-container">'+
1818 '<div class="' + _this.htmlClassPrefix + 'section-button-content">'+
1819 '</div>'+
1820 '</div>'+
1821 '</div>';
1822 html = $( html );
1823
1824 html.insertAfter( input );
1825
1826 html.find('.' + _this.htmlClassPrefix + 'section-button-content').append( input );
1827
1828 input.addClass('ays-survey-section-button');
1829 input.removeClass('button button-primary');
1830 }
1831
1832
1833 /**
1834 * @return {string}
1835 */
1836 AysSurveyPlugin.prototype.GetFullDateTime = function() {
1837 var now = new Date();
1838 var strDateTime = [[now.getFullYear(), AddZero(now.getMonth() + 1), AddZero(now.getDate())].join("-"), [AddZero(now.getHours()), AddZero(now.getMinutes()), AddZero(now.getSeconds())].join(":")].join(" ");
1839 return strDateTime;
1840 }
1841
1842 /**
1843 * @return {string}
1844 */
1845 AysSurveyPlugin.prototype.AddZero = function (num) {
1846 return (num >= 0 && num < 10) ? "0" + num : num + "";
1847 }
1848
1849 /**
1850 * @return {boolean}
1851 */
1852 AysSurveyPlugin.prototype.validatePhoneNumber = function (input) {
1853 var phoneno = /^[+ 0-9-]+$/;
1854 if (input.value.match(phoneno)) {
1855 return true;
1856 } else {
1857 return false;
1858 }
1859 }
1860
1861 AysSurveyPlugin.prototype.sendSurveyData = function(data, element){
1862 var _this = this;
1863 if(typeof _this.sendSurveyData.counter == 'undefined'){
1864 _this.sendSurveyData.counter = 0;
1865 }
1866 if(window.navigator.onLine){
1867 _this.sendSurveyData.counter++;
1868 $.ajax({
1869 url: window.aysSurveyMakerAjaxPublic.ajaxUrl,
1870 method: 'post',
1871 dataType: 'json',
1872 data: data,
1873 success: function(response){
1874 if(response.status === true){
1875 _this.doSurveyResult(response);
1876 }else{
1877 if(_this.sendSurveyData.counter >= 5){
1878 swal.fire({
1879 type: 'error',
1880 html: aysSurveyLangObj.sorry + ".<br>" + aysSurveyLangObj.unableStoreData + "."
1881 });
1882 // _this.goQuizFinishPage(element);
1883 }else{
1884 if(window.navigator.onLine){
1885 setTimeout(function(){
1886 _this.sendSurveyData(data, element);
1887 },3000);
1888 }else{
1889 _this.sendSurveyData(data, element);
1890 }
1891 }
1892 }
1893 },
1894 error: function(jqXHR, textStatus, errorThrown) {
1895 if(_this.sendSurveyData.counter >= 5){
1896 swal.fire({
1897 type: 'error',
1898 html: aysSurveyLangObj.sorry + ".<br>" + aysSurveyLangObj.unableStoreData + "."
1899 });
1900 // _this.goQuizFinishPage(element);
1901 }else{
1902 setTimeout(function(){
1903 _this.sendSurveyData(data, element);
1904 },3000);
1905 }
1906 }
1907 });
1908 }else{
1909 swal.fire({
1910 type: 'warning',
1911 html: aysSurveyLangObj.connectionLost + ".<br>" + aysSurveyLangObj.checkConnection + "."
1912 });
1913 _this.sendSurveyData.counter = 0;
1914 // _this.goQuizFinishPage(element);
1915 }
1916 }
1917
1918 AysSurveyPlugin.prototype.goQuizFinishPage = function(element){
1919 var _this = this;
1920 var currentFS = _this.$el.find('.step.active-step');
1921 var next_sibilings_count = _this.$el.find('.ays_question_count_per_page').val();
1922 if (parseInt(next_sibilings_count) > 0 &&
1923 (element.parents('.step').attr('data-question-id') ||
1924 element.parents('.step').next().attr('data-question-id'))) {
1925 currentFS = _this.$el.find('div[data-question-id]');
1926 }
1927 currentFS.prev().css('display', 'flex');
1928 _this.aysAnimateStep(_this.$el.data('questEffect'), currentFS, currentFS.prev());
1929
1930 if(_this.dbOptions.enable_correction == 'on'){
1931 if(currentFS.prev().find('input:checked').length > 0){
1932 currentFS.prev().find('.ays-field input').attr('disabled', 'disabled');
1933 currentFS.prev().find('.ays-field input').on('click', function(){
1934 return false;
1935 });
1936 currentFS.prev().find('.ays-field input').on('change', function(){
1937 return false;
1938 });
1939 }
1940 if(currentFS.prev().find('option:checked').length > 0){
1941 currentFS.prev().find('.ays-field select').attr('disabled', 'disabled');
1942 currentFS.prev().find('.ays-field select').on('click', function(){
1943 return false;
1944 });
1945 currentFS.prev().find('.ays-field select').on('change', function(){
1946 return false;
1947 });
1948 }
1949 if(currentFS.prev().find('textarea').length > 0){
1950 if(currentFS.prev().find('textarea').val() !== ''){
1951 currentFS.prev().find('.ays-field textarea').attr('disabled', 'disabled');
1952 currentFS.prev().find('.ays-field textarea').on('click', function(){
1953 return false;
1954 });
1955 currentFS.prev().find('.ays-field textarea').on('change', function(){
1956 return false;
1957 });
1958 }
1959 }
1960 }
1961 }
1962
1963 AysSurveyPlugin.prototype.doSurveyResult = function( response ){
1964 var _this = this;
1965 if( response.status ){
1966 var formResults = _this.$el.find('.' + _this.htmlClassPrefix + 'thank-you-page');
1967 if (_this.$el.hasClass('enable_questions_result')) {
1968
1969 }
1970
1971 var aysQuizLoader = _this.$el.find('div.ays-loader[data-role="loader"]');
1972 aysQuizLoader.addClass('ays-survey-loader');
1973 aysQuizLoader.removeClass(aysQuizLoader.data('class'));
1974 _this.$el.find('div.ays-survey-loader.ays-survey-loader-snake').hide();
1975 _this.$el.find('.ays-survey-loader-with-text').hide();
1976 _this.$el.find('.ays-survey-loader-with-custom-gif').hide();
1977 if( response.message ){
1978 formResults.prepend( $( '<div>' + response.message + '</div>' ) );
1979 }
1980
1981 if( response.socialHeading ){
1982 _this.$el.find(".ays-survey-social-shares-heading").append(response.socialHeading);
1983 }
1984
1985 if( _this.dbOptions[ _this.dbOptionsPrefix + 'redirect_after_submit' ] ){
1986 if(!( _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_delay' ] )){
1987 _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_delay' ] = 0;
1988 }
1989
1990 if( parseInt( _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_delay' ] ) > 0 ){
1991 if( _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_url' ] != '' ){
1992 var redirectAfterSubmitTimerHTML = '<div class="' + _this.htmlClassPrefix + 'redirect-timer ' + _this.htmlClassPrefix + 'countdown-timer">' +
1993 aysSurveyLangObj.redirectAfter + ' <span class="' + _this.htmlClassPrefix + 'countdown-time">' + _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_seconds' ] + '</span>' +
1994 '</div>';
1995 formResults.prepend( $( redirectAfterSubmitTimerHTML ) );
1996 var timer = parseInt( _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_delay' ] ) + 2;
1997 _this.timer( timer, {
1998 blockedContent: true,
1999 redirectUrl: _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_url' ],
2000 redirectNewTab: _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_new_tab' ]
2001 });
2002 }
2003 }
2004 else{
2005
2006 _this.timer( timer, {
2007 blockedContent: true,
2008 redirectUrl: _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_url' ],
2009 redirectNewTab: _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_new_tab' ]
2010 });
2011 }
2012 }
2013
2014 var popupContainer = _this.$el.parents('.ays-survey-popup-survey-window');
2015 if(typeof popupContainer != 'undefined' && popupContainer.length > 0){
2016 var dataClosePopup = popupContainer.attr('data-close-popup');
2017 if(typeof dataClosePopup != 'undefined' && dataClosePopup == 'true'){
2018 var dataClosePopupDelay = popupContainer.attr('data-close-popup-delay');
2019 if(typeof dataClosePopupDelay != 'undefined' && dataClosePopupDelay){
2020 var popupCloseButton = popupContainer.find('.ays-survey-popup-btn-close');
2021 popupCloseButton.addClass('ays-survey-popup-btn-close-timer');
2022 var dataClosePopupDelayCount = +dataClosePopupDelay;
2023 if(dataClosePopupDelay > 0){
2024 var popupCloser = setInterval(function(){
2025 popupCloseButton.text(dataClosePopupDelayCount);
2026 dataClosePopupDelayCount--;
2027 if(dataClosePopupDelayCount < 0){
2028 clearInterval(popupCloser);
2029 popupCloseButton.trigger('click');
2030 }
2031 }, 1000);
2032 }else{
2033 setInterval(function(){
2034 popupCloseButton.trigger('click');
2035 }, 1000);
2036 }
2037 }
2038 }
2039 }
2040
2041 formResults.css({'display':'block'});
2042 }else{
2043
2044 }
2045 }
2046
2047 AysSurveyPlugin.prototype.aysResetQuiz = function ($quizContainer){
2048 var cont = $quizContainer.find('div[data-question-id]');
2049 cont.find('input[type="text"], textarea, input[type="number"], input[type="url"], input[type="email"]').each(function(){
2050 $(this).val('');
2051 });
2052 cont.find('select').each(function(){
2053 $(this).val('');
2054 });
2055 cont.find('select.ays-select').each(function(){
2056 $(this).val(null).trigger('change');
2057 });
2058 cont.find('select option').each(function(){
2059 $(this).removeAttr('selected');
2060 });
2061 cont.find('input[type="radio"], input[type="checkbox"]').each(function(){
2062 $(this).removeAttr('checked');
2063 });
2064 }
2065
2066 AysSurveyPlugin.prototype.aysAutofillData = function (data, currentEl){
2067 $.ajax({
2068 url: window.aysSurveyMakerAjaxPublic.ajaxUrl,
2069 method: 'post',
2070 dataType: 'json',
2071 data: data,
2072 success: function (response) {
2073 if(response !== null){
2074 if( response.data ){
2075 currentEl.find(".ays-survey-question[data-type='name'] input.ays-survey-question-input").val(response.data.display_name);
2076 currentEl.find(".ays-survey-question[data-type='email'] input.ays-survey-question-email-input").val(response.data.user_email);
2077 }
2078 } //:last-of-type
2079 }
2080 });
2081 }
2082
2083 AysSurveyPlugin.prototype.checkMinVotes = function( item ){
2084 var _this = this;
2085 var options;
2086 var questionId = item.find('.' + _this.htmlClassPrefix + 'question-id').val();
2087 options = _this.dbOptions[ _this.dbOptionsPrefix + 'checkbox_options' ][questionId];
2088 if(options.enable_max_selection_count){
2089 var allVotesCount = item.find('.' + _this.htmlClassPrefix + 'answer input[type="checkbox"][name^="' + _this.htmlClassPrefix + 'answers"]').length;
2090 var checkedCount = item.find('.' + _this.htmlClassPrefix + 'answer input[type="checkbox"][name^="' + _this.htmlClassPrefix + 'answers"]:checked').length;
2091 var MinVotes = options.min_selection_count;
2092 var MaxVotes = options.max_selection_count;
2093 if(MinVotes > MaxVotes){
2094 MinVotes = MaxVotes;
2095 }
2096 if(MinVotes > allVotesCount){
2097 MinVotes = allVotesCount;
2098 }
2099 var errorMessage = '';
2100 if(MinVotes <= checkedCount){
2101 item.find('.' + _this.htmlClassPrefix + 'votes-count-validation-error').hide();
2102 }
2103 if(MinVotes > checkedCount){
2104 errorMessage += '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">';
2105 errorMessage += '<span>' + aysSurveyLangObj.minimumVotes + ' ' + MinVotes + '</span>';
2106 item.addClass('ays-has-error');
2107 item.find('.' + _this.htmlClassPrefix + 'votes-count-validation-error').html(errorMessage);
2108 item.find('.' + _this.htmlClassPrefix + 'votes-count-validation-error').show();
2109 _this.goToTop( item );
2110 return false;
2111 }
2112 else{
2113 return true;
2114 }
2115 }
2116 return true;
2117 }
2118
2119 AysSurveyPlugin.prototype.toggleFullscreen = function (elem) {
2120 var _this = this;
2121 elem = elem || document.documentElement;
2122 if (!document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement) {
2123 _this.aysSurveyFullScreenActivate( elem );
2124 _this.aysSurveyFullScreenWindowActivator( elem );
2125 }else{
2126 _this.aysSurveyFullScreenDeactivate( elem );
2127 _this.aysSurveyFullScreenWindowDeactivator();
2128 }
2129 }
2130
2131 AysSurveyPlugin.prototype.aysSurveyFullScreenActivate = function (elem) {
2132 $(elem).css({'background-color':'#fff'});
2133 $(elem).find('.ays-survey-full-screen-mode .ays-survey-close-full-screen').css({'display':'inline'});
2134 $(elem).find('.ays-survey-full-screen-mode .ays-survey-open-full-screen').css('display','none');
2135 $(elem).find('.ays-survey-full-screen-mode').css({'padding-right':'15px'});
2136 $(elem).css({'overflow':'auto'});
2137 }
2138
2139 AysSurveyPlugin.prototype.aysSurveyFullScreenDeactivate = function (elem) {
2140 $(elem).css({'background-color':'initial'});
2141 $(elem).find('.ays-survey-full-screen-mode .ays-survey-open-full-screen').css({'display':'inline'});
2142 $(elem).find('.ays-survey-full-screen-mode .ays-survey-close-full-screen').css('display','none');
2143 $(elem).find('.ays-survey-full-screen-mode').css({'padding-right':'0'});
2144 $(elem).css({'overflow':'initial'});
2145 }
2146
2147 AysSurveyPlugin.prototype.aysSurveyFullScreenDeactivateAll = function (elem) {
2148 var _this = this;
2149 document.addEventListener('fullscreenchange', function(event) {
2150 if (!document.fullscreenElement) {
2151 var eventTarget = event.target;
2152 if( $( eventTarget ).hasClass('ays-survey-container') ){
2153 _this.aysSurveyFullScreenDeactivate( eventTarget );
2154 }
2155 }
2156 }, false);
2157 }
2158
2159 AysSurveyPlugin.prototype.aysSurveyFullScreenWindowActivator = function (elem) {
2160 if (elem.requestFullscreen) {
2161 elem.requestFullscreen();
2162 }else if (elem.msRequestFullscreen) {
2163 elem.msRequestFullscreen();
2164 }else if (elem.mozRequestFullScreen) {
2165 elem.mozRequestFullScreen();
2166 }else if (elem.webkitRequestFullscreen) {
2167 elem.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
2168 }
2169 }
2170
2171 AysSurveyPlugin.prototype.aysSurveyFullScreenWindowDeactivator = function () {
2172 if(document.exitFullscreen) {
2173 document.exitFullscreen();
2174 }else if (document.msExitFullscreen) {
2175 document.msExitFullscreen();
2176 }else if (document.mozCancelFullScreen) {
2177 document.mozCancelFullScreen();
2178 }else if (document.webkitExitFullscreen) {
2179 document.webkitExitFullscreen();
2180 }
2181 }
2182
2183 AysSurveyPlugin.prototype.aysSurveyCheckTextLimit = function(question, options,e,current) {
2184 var $this = current;
2185 var _this = this;
2186 var box = question.find('.ays-survey-question-text-message');
2187 var questionTextMessage = question.find('.ays-survey-question-text-message-span');
2188 // Maximum length of a text field
2189 var enable_question_text_max_length = (options.enable_word_limitation && options.enable_word_limitation != "") ? options.enable_word_limitation : false;
2190 // Length
2191 var question_text_max_length = (options.limit_length && options.limit_length != "") ? parseInt(options.limit_length) : '';
2192 // Limit by
2193 var question_limit_text_type = (options.limit_by && options.limit_by != "") ? options.limit_by : '';
2194 // Show word/character counter
2195 var question_enable_text_message = (options.limit_counter && options.limit_counter != '') ? options.limit_counter : false;
2196
2197 var remainder = '';
2198 if(question_text_max_length != '' && question_text_max_length != 0){
2199 switch ( question_limit_text_type ) {
2200 case 'char':
2201 var tval = $this.val();
2202 var tlength = tval.length;
2203 var set = question_text_max_length;
2204 var remain = parseInt(set - tlength);
2205 if (remain <= 0 && e.which !== 0 && e.charCode !== 0) {
2206 $this.val((tval).substring(0, tlength - 1));
2207 }
2208 if (e.type=="keyup") {
2209 var tval = $this.val().trim();
2210 if(tval.length > 0 && tval != null){
2211 var wordsLength = $this[0].value.split('').length;
2212 if (wordsLength > question_text_max_length) {
2213 var trimmed = tval.split('', question_text_max_length).join("");
2214 $this.val(trimmed);
2215 }
2216 }
2217 }
2218 remainder = remain;
2219 break;
2220 case 'word':
2221 if (e.type=="keyup") {
2222 var tval = $this.val().trim();
2223 if(tval.length > 0 && tval != null){
2224 var wordsLength = $this[0].value.match(/\S+/g).length;
2225 if (wordsLength > question_text_max_length) {
2226 var trimmed = tval.split(/\s+/, question_text_max_length).join(" ");
2227 $this.val(trimmed + " ");
2228 }
2229 remainder = question_text_max_length - wordsLength;
2230 }
2231 }
2232 break;
2233 default:
2234 break;
2235 }
2236 if (e.type=="keyup") {
2237 if ( question_enable_text_message ) {
2238 if(question_text_max_length != '' && question_text_max_length != 0){
2239 if (remainder <= 0) {
2240 remainder = 0;
2241 if (! box.hasClass(_this.htmlClassPrefix + ' question-text-error-message') ) {
2242 box.addClass(_this.htmlClassPrefix + 'question-text-error-message')
2243 }
2244 }else{
2245 if ( box.hasClass(_this.htmlClassPrefix + 'question-text-error-message') ) {
2246 box.removeClass(_this.htmlClassPrefix + 'question-text-error-message')
2247 }
2248 }
2249 if (tval.length == 0 || tval == null) {
2250 if ( box.hasClass(_this.htmlClassPrefix + 'question-text-error-message') ) {
2251 box.removeClass(_this.htmlClassPrefix + 'question-text-error-message')
2252 }
2253 remainder = question_text_max_length;
2254 }
2255
2256 questionTextMessage.html( remainder );
2257 }
2258 }
2259 }
2260 }
2261 }
2262
2263 AysSurveyPlugin.prototype.aysSurveyCheckNumberLimit = function(question, options,e,current) {
2264 var $this = current;
2265 var _this = this;
2266 var errorBox = question.find('.ays-survey-number-limit-message-box');
2267 question.removeClass('ays-has-error');
2268 errorBox.hide();
2269 var limitBox = question.find('.ays-survey-question-text-message');
2270 var questionTextMessage = question.find('.ays-survey-question-text-message-span');
2271 // Enable Limitation
2272 var enableQuestionLimit = (options.enable_number_limitation && options.enable_number_limitation != "") ? options.enable_number_limitation : false;
2273 // Min Value
2274 var questionTextMinValue = (options.number_min_selection && options.number_min_selection != "") ? parseInt(options.number_min_selection) : '';
2275 // Max Value
2276 var questionTextMaxValue = (options.number_max_selection && options.number_max_selection != "") ? parseInt(options.number_max_selection) : '';
2277 // Show error message
2278 var enableTextMessage = (options.enable_number_error_message && options.enable_number_error_message != '') ? options.enable_number_error_message : false;
2279 // Max Length
2280 var questionTextMaxLength = (options.number_limit_length && options.number_limit_length != "") ? parseInt(options.number_limit_length) : '';
2281 // Show char length
2282 var questionEnableTextMessage = (options.enable_number_limit_counter && options.enable_number_limit_counter != '') ? options.enable_number_limit_counter : false;
2283 if(questionTextMinValue >= questionTextMaxValue){
2284 questionTextMaxValue = questionTextMinValue;
2285 }
2286 if(enableQuestionLimit){
2287 var remainder = '';
2288 var showErrorMessage = 0;
2289 if(questionTextMaxLength != '' && questionTextMaxLength != 0){
2290 var tval = $this.val();
2291 var tlength = tval.length;
2292 var set = questionTextMaxLength;
2293 var remain = parseInt(set - tlength);
2294 // if (remain <= 0 && e.which !== 0 && e.charCode !== 0) {
2295 // $this.val((tval).substring(0, tlength - 1));
2296 // }
2297 // if (e.type=="keyup") {
2298 var tval = $this.val().trim();
2299 if(tval.length > 0 && tval != null){
2300
2301 var wordsLength = $this[0].value.split('').length;
2302 if (wordsLength > questionTextMaxLength) {
2303 // var trimmed = tval.split('', questionTextMaxLength).join("");
2304 // $this.val(trimmed);
2305 showErrorMessage++;
2306 question.addClass('ays-has-error');
2307 } else {
2308 // Remove error class if length is within limit
2309 question.removeClass('ays-has-error');
2310 }
2311 }
2312 // }
2313 remainder = remain;
2314 }
2315 var enteredValue = $this.val().trim();
2316 var inputValue = parseInt( enteredValue );
2317
2318 // Check if min value exists and min value not 0
2319 if(questionTextMinValue != '' && questionTextMinValue != 0){
2320 if( ! isNaN(inputValue) ){
2321 // if (e.type=="keyup") {
2322 if ( inputValue < questionTextMinValue ) {
2323 // $this.val(questionTextMinValue);
2324 showErrorMessage++;
2325 question.addClass('ays-has-error');
2326 }
2327 // }
2328 }
2329 }
2330
2331 // Check if min value exists and max value not 0
2332 if(questionTextMaxValue != '' && questionTextMaxValue != 0){
2333 // if (e.type=="keyup") {
2334 if ( inputValue > questionTextMaxValue ) {
2335 // $this.val(questionTextMaxValue);
2336 showErrorMessage++;
2337 question.addClass('ays-has-error');
2338 }
2339 // }
2340 }
2341
2342 // Check if min value exists and min value <= 0
2343 if(questionTextMaxValue != '' && questionTextMinValue <= 0){
2344 if( ! isNaN(inputValue) ){
2345 // if (e.type=="keyup") {
2346 if ( inputValue < questionTextMinValue ) {
2347 // $this.val(questionTextMinValue);
2348 showErrorMessage++;
2349 question.addClass('ays-has-error');
2350 }
2351 // }
2352 }
2353 }
2354 // if (e.type=="keyup") {
2355 $this.val(tval.substring(0, questionTextMaxLength));
2356 // Remove error class after trimming text to valid length
2357 if ($this.val().length <= questionTextMaxLength) {
2358 question.removeClass('ays-has-error');
2359 }
2360 if ( questionEnableTextMessage ) {
2361 if(questionTextMaxLength != '' && questionTextMaxLength != 0){
2362 if (remainder <= 0) {
2363 remainder = 0;
2364 if (! limitBox.hasClass(_this.htmlClassPrefix + 'question-text-error-message') ) {
2365 limitBox.addClass(_this.htmlClassPrefix + 'question-text-error-message')
2366 }
2367 }else{
2368 if ( limitBox.hasClass(_this.htmlClassPrefix + 'question-text-error-message') ) {
2369 limitBox.removeClass(_this.htmlClassPrefix + 'question-text-error-message')
2370 }
2371 }
2372 if (tval.length == 0 || tval == null) {
2373 if ( limitBox.hasClass(_this.htmlClassPrefix + 'question-text-error-message') ) {
2374 limitBox.removeClass(_this.htmlClassPrefix + 'question-text-error-message')
2375 }
2376 remainder = questionTextMaxLength;
2377 }
2378
2379 questionTextMessage.html( remainder );
2380 }
2381 }
2382 // }
2383 if(enableTextMessage && showErrorMessage > 0){
2384 errorBox.show();
2385 }
2386
2387 }
2388 }
2389
2390 AysSurveyPlugin.prototype.aysSurveyonTabPress = function() {
2391 var _this = this;
2392 _this.$el.on('keydown', (e) => {
2393 var selectedBox = $(e.target);
2394 if( !selectedBox.hasClass( 'ays-survey-answer-text-inputs' ) ){
2395 if (e.keyCode === 32) {
2396 e.preventDefault();
2397 if(selectedBox.hasClass('ays-survey-section-button-container')){
2398 selectedBox.find('.ays-survey-section-button').trigger("click");
2399 }
2400 else{
2401 selectedBox.trigger("click");
2402 }
2403 }
2404 }
2405 });
2406 }
2407
2408 AysSurveyPlugin.prototype.aysAutoNext = function(button) {
2409 var _this = this;
2410 var checkedRadiosCount = 0;
2411 var activeSection = button.parents('.ays-survey-section.active-section');
2412
2413 var sectionQuestions = activeSection.find('.ays-survey-section-questions .ays-survey-question');
2414 var sectionQuestionsCount = sectionQuestions.length;
2415
2416 var checkedRadios = sectionQuestions.find('input[type="radio"]:checked');
2417 checkedRadiosCount += checkedRadios.length;
2418
2419 var changedDropdown = sectionQuestions.find('input.ays-survey-detect-selected-question-dropdown');
2420
2421 changedDropdown.each(function() {
2422 if ($(this).val().trim() !== '') {
2423 checkedRadiosCount++;
2424 }
2425 });
2426
2427 var nextButton = activeSection.find('.' + _this.htmlClassPrefix + 'next-button');
2428 if((checkedRadiosCount >= sectionQuestionsCount) && nextButton.hasClass('display_none_important')){
2429 nextButton.trigger('click');
2430 }
2431 }
2432
2433 /**
2434 * @return {string}
2435 */
2436 function AddZero(num) {
2437 return (num >= 0 && num < 10) ? "0" + num : num + "";
2438 }
2439
2440 /**
2441 * @return {string}
2442 */
2443 function aysEscapeHtml(text) {
2444 var map = {
2445 '&': '&amp;',
2446 '<': '&lt;',
2447 '>': '&gt;',
2448 '"': '&quot;',
2449 "'": '&#039;'
2450 };
2451 return text.replace(/[&<>\"']/g, function(m) { return map[m]; });
2452 }
2453
2454 function validatePhoneNumber(input) {
2455 var phoneno = /^[+ 0-9-]+$/;
2456 if (input.value.match(phoneno)) {
2457 return true;
2458 } else {
2459 return false;
2460 }
2461 }
2462
2463 function surveySanitizeSpecificContent(content) {
2464 // Pattern to match <script> tags and dangerous attributes
2465 const pattern = /<script.*?>.*?<\/script>|<[^>]+(?:\bon\w+\s*=|attributeName\s*=)[^>]*>/gis;
2466
2467 // Replace matched patterns with escaped HTML entities
2468 return content.replace(pattern, match =>
2469 match.replace(/[<>&"'`]/g, char => ({
2470 '<': '&lt;',
2471 '>': '&gt;',
2472 '&': '&amp;',
2473 '"': '&quot;',
2474 "'": '&#39;',
2475 '`': '&#96;'
2476 })[char] || char)
2477 );
2478 }
2479
2480
2481 $.fn.serializeFormJSON = function () {
2482 var o = {},
2483 a = this.serializeArray();
2484 $.each(a, function () {
2485 if (o[this.name]) {
2486 if (!o[this.name].push) {
2487 o[this.name] = [o[this.name]];
2488 }
2489 o[this.name].push(this.value || '');
2490 } else {
2491 o[this.name] = this.value || '';
2492 }
2493 });
2494 return o;
2495 };
2496
2497 $.fn.AysSurveyMaker = function(options) {
2498 return this.each(function() {
2499 if (!$.data(this, 'AysSurveyMaker')) {
2500 $.data(this, 'AysSurveyMaker', new AysSurveyPlugin(this, options));
2501 } else {
2502 try {
2503 $(this).data('AysSurveyMaker').init();
2504 } catch (err) {
2505 console.error('AysSurveyMaker has not initiated properly');
2506 }
2507 }
2508 });
2509 };
2510
2511 })(jQuery);
2512