PluginProbe
Survey Maker by AYS / 5.2.2.6
Survey Maker by AYS v5.2.2.6
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.6, at public/js/survey-maker-public-plugin.js

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