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.startDate; 26 this.endDate; 27 this.sectionsContainer; 28 this.sections; 29 this.current_fs; 30 this.next_fs; 31 this.previous_fs; //fieldsets 32 this.left; 33 this.opacity; 34 this.scale; //fieldset properties which we will animate 35 this.animating; 36 this.percentAnimate; //flag to prevent quick multi-click glitches 37 this.explanationTimeout; 38 this.maxCountTimeout; 39 this.confirmBeforeUnload = false; 40 this.calculationQuestionsOptions = {}; 41 this.calculationQuestionsValues = {}; 42 this.questionsValues = {}; 43 this.calculationRegexReplacements = { 44 '\\bpi\\b': 'Math.PI', 45 'Ï': 'Math.PI', 46 '\\be\\b': 'Math.E', 47 '\\bcos\\b': 'Math.cos', 48 '\\bsin\\b': 'Math.sin', 49 '\\bexp\\b': 'Math.exp', 50 '\\bsqrt\\b': 'Math.sqrt', 51 '\\btan\\b': 'Math.tan', 52 '(\\w+)\\^+(\\w+)': 'Math.pow($1, $2)', 53 '--(\\d+)': '-(-$1)', 54 }; 55 56 57 // new added email pattern 58 this.emailValidatePattern = /^[a-zA-Z0-9._+-]+@[a-zA-Z0-9._-]+\.\w{2,}$/; 59 60 // phone pattern 61 this.phoneValivatePattern = /^[0-9)(+ -]+$/; 62 63 // old email pattern(works slower) 64 // this.emailValidatePattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/; 65 66 this.logicJumpQuestionTypes = [ 'radio', 'select', 'yesorno', 'checkbox', 'nps' ]; 67 this.logicJumpQuestionSteps = {}; 68 this.logicJumpSectionSteps = {}; 69 70 this.init(); 71 72 return this; 73 } 74 75 AysSurveyPlugin.prototype.init = function() { 76 var _this = this; 77 _this.uniqueId = _this.$el.data('id'); 78 79 if( typeof window.aysSurveyOptions != 'undefined' ){ 80 _this.dbOptions = JSON.parse( atob( window.aysSurveyOptions[ _this.uniqueId ] ) ); 81 } 82 83 _this.$el.find('.ays-survey-wait-loading-loader').css("display" , "none"); 84 if( _this.$el.hasClass( _this.htmlClassPrefix + 'blocked-content' ) ){ 85 _this.blockedContent( true ); 86 return false; 87 } 88 89 _this.setup(); 90 _this.blockedContent( false ); 91 _this.setEvents(); 92 93 // if(_this.dbOptions.survey_enable_survey_start_loader){ 94 95 // } 96 97 // _this.share(); 98 _this.keydown(); 99 }; 100 101 AysSurveyPlugin.prototype.setup = function(e) { 102 var _this = this; 103 _this.sectionsContainer = _this.$el.find('.' + _this.htmlClassPrefix + 'sections'); 104 _this.sections = _this.sectionsContainer.find('.' + _this.htmlClassPrefix + 'section'); 105 _this.showAllSections = _this.sectionsContainer.find('.' + _this.htmlClassPrefix + 'show-all'); 106 107 _this.sections.first().addClass('active-section'); 108 var passwordCheck = _this.sectionsContainer.find('.' + _this.htmlClassPrefix + 'password'); 109 110 if(_this.sectionsContainer.find('.' + _this.htmlClassPrefix + 'section-start-page ').length <= 0 && _this.showAllSections.length > 0 && passwordCheck.length == 0){ 111 _this.showAllSections.addClass('active-section'); 112 _this.$el.find('.' + _this.htmlClassPrefix + 'show-all').not(':last').find('.' + _this.htmlClassPrefix + 'section-buttons').addClass( _this.htmlClassPrefix + 'display-none' ); 113 // _this.showAllSections.find('.' + _this.htmlClassPrefix + 'section-button.' + _this.htmlClassPrefix + 'next-button').addClass( _this.htmlClassPrefix + 'display-none' ); 114 _this.showAllSections.find('.' + _this.htmlClassPrefix + 'section-button.' + _this.htmlClassPrefix + 'prev-button').addClass( _this.htmlClassPrefix + 'display-none' ); 115 _this.showAllSections.find('.' + _this.htmlClassPrefix + 'promote-survey-content').not(':last').addClass( _this.htmlClassPrefix + 'display-none' ); 116 } 117 118 if( _this.$el.find("div.ays-survey-section[data-id]").length === 1 ){ 119 _this.sections.first().find('.' + _this.htmlClassPrefix + 'section-button.' + _this.htmlClassPrefix + 'finish-button').removeClass( _this.htmlClassPrefix + 'display-none' ); 120 _this.sections.first().find('.' + _this.htmlClassPrefix + 'section-button.' + _this.htmlClassPrefix + 'next-button').addClass( _this.htmlClassPrefix + 'display-none' ); 121 } 122 123 _this.logicJumpQuestionSteps[ _this.sections.first().data('id') ] = { 124 section: +_this.sections.first().data('id'), 125 prevSection: null, 126 active: true 127 }; 128 129 _this.logicJumpSectionSteps[ _this.sections.first().data('id') ] = { 130 section: +_this.sections.first().data('id'), 131 prevSection: null, 132 active: true 133 }; 134 135 var questionTypeText = $(document).find('textarea.' + _this.htmlClassPrefix + 'question-input-textarea'); 136 autosize(questionTypeText); 137 138 var questionTypeSelect = $(document).find('.' + _this.htmlClassPrefix + 'question-select'); 139 140 questionTypeSelect.each(function(){ 141 $(this).aysDropdown({ 142 duration: 150, 143 transition: 'scale', 144 onChange: function(value, text, $selectedItem) { 145 $selectedItem.parents('.' + _this.htmlClassPrefix + 'question').removeClass('ays-has-error'); 146 $selectedItem.parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-validation-error').html(''); 147 } 148 }); 149 }); 150 151 if( _this.dbOptions.options ){ 152 if( _this.dbOptions.options.survey_enable_i_autofill ){ 153 var checkAutoFill = _this.dbOptions.options.survey_enable_i_autofill.length > 0 && _this.dbOptions.options.survey_enable_i_autofill == "on" ? true : false; 154 if(checkAutoFill){ 155 var form = _this.$el.find('form'); 156 var data = form.serializeFormJSON(); 157 data.action = _this.ajaxAction; 158 data.function = 'ays_survey_get_user_information'; 159 data.end_date = _this.GetFullDateTime(); 160 data.unique_id = _this.uniqueId; 161 _this.aysAutofillData(data , _this.$el); 162 } 163 } 164 } 165 } 166 167 AysSurveyPlugin.prototype.setEvents = function(e) { 168 var _this = this; 169 170 _this.aysNext(); 171 _this.aysFinish(); 172 _this.setCalculationOptions(); 173 _this.updateCalculationValueOnLoad(); 174 175 176 _this.$el.on('click', '.' + _this.htmlClassPrefix + 'start-button', function(e){
177 _this.start(e); 178 }); 179 180 _this.$el.on('click', '.' + _this.htmlClassPrefix + 'section-button.ays-check-survey-password', function(e){ 181 var passwordSurvey = $(this).parents('.ays-survey-section,.ays-survey-chat-container').find("input.ays-survey-password").val(); 182 var activPsw = _this.dbOptions.options.survey_generated_passwords.survey_active_passwords; 183 var form = $(this).parents('form'); 184 if( _this.checkSurveyPassword( passwordSurvey, true ) !== false ){ 185 if(_this.dbOptions.options.survey_password_type == 'generated_password'){ 186 if( _this.dbOptions.options.survey_enable_password && activPsw.length != 0 ){ 187 var userData; 188 userData = form.serializeFormJSON() 189 userData.action = _this.ajaxAction; 190 userData.function = 'ays_survey_used_password_ajax'; 191 userData.userGeneratedPassword = passwordSurvey; 192 userData.uniqueId = _this.uniqueId; 193 194 $.ajax({
195 url: window.aysSurveyMakerAjaxPublic.ajaxUrl, 196 method: 'post', 197 dataType: 'json', 198 data: userData, 199 success: function(response){ 200 if(response.status){ 201 202 } 203 } 204 }); 205 } 206 } 207 }else{ 208 return false; 209 } 210 $(this).parents('.ays-survey-section').removeClass('active-section'); 211 $(this).parents('.ays-survey-section').next().addClass('active-section'); 212 var chatModeMainParent = $(this).parents('.ays-survey-chat-container') 213 chatModeMainParent.find('.ays-survey-chat-content').css("display", "block"); 214 chatModeMainParent.find('.ays-survey-section-password-content').css("display", "none"); 215 216 if( _this.$el.find("div.ays-survey-section[data-id]").length === 1 ){ 217 $(this).parents('.ays-survey-section').next().find('.' + _this.htmlClassPrefix + 'section-button.' + _this.htmlClassPrefix + 'finish-button').removeClass( _this.htmlClassPrefix + 'display-none' ); 218 $(this).parents('.ays-survey-section').next().find('.' + _this.htmlClassPrefix + 'section-button.' + _this.htmlClassPrefix + 'next-button').addClass( _this.htmlClassPrefix + 'display-none' ); 219 } 220 221 if(_this.sectionsContainer.find('.' + _this.htmlClassPrefix + 'section-start-page ').length <= 0 && _this.showAllSections.length > 0 ){ 222 _this.showAllSections.addClass('active-section'); 223 _this.showAllSections.find('.' + _this.htmlClassPrefix + 'section-button.' + _this.htmlClassPrefix + 'next-button').addClass( _this.htmlClassPrefix + 'display-none' ); 224 _this.showAllSections.find('.' + _this.htmlClassPrefix + 'section-button.' + _this.htmlClassPrefix + 'prev-button').addClass( _this.htmlClassPrefix + 'display-none' ); 225 _this.showAllSections.find('.' + _this.htmlClassPrefix + 'promote-survey-content').not(':last').addClass( _this.htmlClassPrefix + 'display-none' ); 226 } 227 228 }); 229 230 _this.$el.on('click', '.' + _this.htmlClassPrefix + 'single-submission-results-export', function(e){ 231 var $_this = $(this) 232 var type = $_this.attr('data-type'); 233 var surveyID = $_this.attr('survey-id'); 234 var submissionID = $_this.attr('data-submission'); 235 var action = _this.ajaxAction; 236 var afunction = 'ays_survey_single_submission_results_export_public'; 237 238 $_this.prop('disabled',true); 239 $_this.addClass('disabled'); 240 241 $.ajax({
242 url: window.aysSurveyMakerAjaxPublic.ajaxUrl, 243 method: 'post', 244 dataType: 'json', 245 data: { 246 action: action, 247 survey_id: surveyID, 248 submission_id: submissionID, 249 function: afunction, 250 type: type 251 }, 252 success: function (response) { 253 if (response.status) { 254 var options = { 255 fileName: "survey_single_submission_export", 256 header: true 257 }; 258 var tableData = [{ 259 "sheetName": "Survey submission", 260 "data": response.data 261 }]; 262 Jhxlsx.export(tableData, options); 263 }else{ 264 swal.fire({ 265 type: 'info', 266 html: "<h2>"+ aysSurveyLangObj.loadResource +"</h2><br><h6>"+ aysSurveyLangObj.dataDeleted +"</h6>" 267 }) 268 } 269 $_this.prop('disabled',false); 270 $_this.removeClass('disabled'); 271 }, 272 error: function() { 273 swal.fire({ 274 type: 'info', 275 html: "<h2>"+ aysSurveyLangObj.loadResource +"</h2><br><h6>"+ aysSurveyLangObj.dataDeleted +"</h6>" 276 }).then(function(res){ 277 $_this.prop('disabled',false); 278 $_this.removeClass('disabled'); 279 }); 280 } 281 }); 282 }); 283 284 _this.$el.on('click', '.' + _this.htmlClassPrefix + 'answer-label-other input', function(){ 285 $(this).parents('.' + _this.htmlClassPrefix + 'answer').find('.' + _this.htmlClassPrefix + 'answer-other-input').focus(); 286 _this.confirmBeforeUnload = true; 287 }); 288 289 _this.$el.on('input', '.' + _this.htmlClassPrefix + 'answer-other-input', function(){ 290 291 $(this).parents('.' + _this.htmlClassPrefix + 'question').removeClass('ays-has-error'); 292 $(this).parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-validation-error').html(''); 293 294 if( $(this).parents('.' + _this.htmlClassPrefix + 'question').data('type') == 'checkbox' ){ 295 var checkedCount = $(this).parents('.' + _this.htmlClassPrefix + 'question-answers').find('.' + _this.htmlClassPrefix + 'answer input[type="checkbox"][name^="' + _this.htmlClassPrefix + 'answers"]:checked').length; 296 var questionId = $(this).parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-id').val(); 297 questionId = parseInt( questionId ); 298 var options = _this.dbOptions[ _this.dbOptionsPrefix + 'checkbox_options' ][questionId]; 299 if(typeof options != "undefined"){ 300 if( options.enable_max_selection_count === true ){ 301 if( options.max_selection_count != null && ( options.max_selection_count < checkedCount + 1 ) ){ 302 }else{ 303 $(this).parents('.' + _this.htmlClassPrefix + 'answer').find('.' + _this.htmlClassPrefix + 'answer-label-other input').prop('checked', true); 304 } 305 }else{ 306 $(this).parents('.' + _this.htmlClassPrefix + 'answer').find('.' + _this.htmlClassPrefix + 'answer-label-other input').prop('checked', true); 307 } 308 } 309 }else{ 310 $(this).parents('.' + _this.htmlClassPrefix + 'answer').find('.' + _this.htmlClassPrefix + 'answer-label-other input').prop('checked', true); 311 } 312 _this.confirmBeforeUnload = true; 313 }); 314 315 _this.$el.on('input', 'textarea[name^="' + _this.htmlClassPrefix + 'answers"],'+ 316 'input[type="text"][name^="' + _this.htmlClassPrefix + 'answers"], input[type="number"][name^="' + _this.htmlClassPrefix + 'answers"]', function(){ 317 318 $(this).parents('.' + _this.htmlClassPrefix + 'question').removeClass('ays-has-error'); 319 $(this).parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-validation-error').html(''); 320 321 _this.confirmBeforeUnload = true; 322 }); 323 324 _this.$el.on('change', 'input[type="date"][name^="' + _this.htmlClassPrefix + 'answers"]', function(){ 325 326 $(this).parents('.' + _this.htmlClassPrefix + 'question').removeClass('ays-has-error'); 327 $(this).parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-validation-error').html(''); 328 329 _this.confirmBeforeUnload = true; 330 }); 331 332 _this.sectionsContainer.on('change', 'input[type="radio"][name^="' + _this.htmlClassPrefix + 'answers"]', function(){ 333 var check_required = $(this).parents('.' + _this.htmlClassPrefix + 'question').data('required'); 334 335 $(this).parents('.' + _this.htmlClassPrefix + 'question').removeClass('ays-has-error'); 336 $(this).parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-validation-error').html(''); 337 if(!check_required){ 338 $(this).parents('.' + _this.htmlClassPrefix + 'question-answers').find('.' + _this.htmlClassPrefix + 'answer-clear-selection-container').addClass('in'); 339 $(this).parents('.' + _this.htmlClassPrefix + 'question-answers').find('.' + _this.htmlClassPrefix + 'answer-clear-selection-container').removeClass('out'); 340 $(this).parents('.' + _this.htmlClassPrefix + 'question-answers').find('.' + _this.htmlClassPrefix + 'answer-clear-selection-container').removeClass(_this.htmlClassPrefix + 'visibility-none'); 341 } 342 _this.confirmBeforeUnload = true; 343 }); 344 345 _this.sectionsContainer.on('click', 'input[type="checkbox"][name^="' + _this.htmlClassPrefix + 'answers"]:not(.' + _this.htmlClassPrefix + 'matrix-scale-checbox-inputs)', function(){ 346 $(this).parents('.' + _this.htmlClassPrefix + 'question').removeClass('ays-has-error'); 347 $(this).parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-validation-error').html(''); 348 349 clearTimeout( _this.maxCountTimeout ); 350 var questionBox = $(this).parents('.' + _this.htmlClassPrefix + 'question'); 351 questionBox.removeClass('ays-has-error'); 352 var checkedCount = $(this).parents('.' + _this.htmlClassPrefix + 'question-answers').find('.' + _this.htmlClassPrefix + 'answer input[type="checkbox"][name^="' + _this.htmlClassPrefix + 'answers"]:checked').length; 353 var allVotesCount = $(this).parents('.' + _this.htmlClassPrefix + 'question-answers').find('.' + _this.htmlClassPrefix + 'answer input[type="checkbox"][name^="' + _this.htmlClassPrefix + 'answers"]').length; 354 var questionId = questionBox.data('id'); 355 356 questionId = parseInt( questionId ); 357 var options = _this.dbOptions[ _this.dbOptionsPrefix + 'checkbox_options' ][questionId]; 358 var minVotes = options.min_selection_count; 359 var maxVotes = options.max_selection_count != null ? options.max_selection_count : 0; 360 361 if( options.enable_max_selection_count === true ){ 362 var checkVotesCount = (maxVotes != null || minVotes != null) ? true : false; 363 if(checkVotesCount){ 364 if(maxVotes <= 0 ){ 365 maxVotes = allVotesCount; 366 } 367 368 if( maxVotes < checkedCount ){ 369 var errorMessage = '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">'; 370 errorMessage += '<span>' + aysSurveyLangObj.maximumVotes + ' ' + maxVotes + '</span>'; 371 questionBox.find('.' + _this.htmlClassPrefix + 'votes-count-validation-error').html(errorMessage); 372 373 questionBox.addClass('ays-has-error'); 374 questionBox.find('.' + _this.htmlClassPrefix + 'votes-count-validation-error').show(); 375 _this.maxCountTimeout = setTimeout(function() { 376 questionBox.find('.' + _this.htmlClassPrefix + 'votes-count-validation-error').hide(); 377 }, 3000); 378 return false; 379 } 380 381 if(minVotes > maxVotes){ 382 minVotes = maxVotes; 383 } 384 385 if(minVotes > allVotesCount){ 386 minVotes = allVotesCount; 387 } 388 389 if(minVotes <= checkedCount){ 390 questionBox.find('.' + _this.htmlClassPrefix + 'votes-count-validation-error').hide(); 391 }else{ 392 var errorMessage = '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">'; 393 errorMessage += '<span>' + aysSurveyLangObj.minimumVotes + ' ' + minVotes + '</span>'; 394 questionBox.addClass('ays-has-error'); 395 questionBox.find('.' + _this.htmlClassPrefix + 'votes-count-validation-error').html(errorMessage); 396 questionBox.find('.' + _this.htmlClassPrefix + 'votes-count-validation-error').show(); 397 } 398 } 399 } 400 }); 401 402 _this.sectionsContainer.on('click', '.' + _this.htmlClassPrefix + 'answer-clear-selection-container .' + _this.htmlClassPrefix + 'button', function(){ 403 var questionId = $(this).parents('.' + _this.htmlClassPrefix + 'question').attr('data-id'); 404 var sendData = { 405 questionId: questionId, 406 answerId: null, 407 value: null, 408 negative: true, 409 multiAns: false, 410 } 411 _this.updateCalculationValue(sendData); 412 413 var check_required = $(this).parents('.' + _this.htmlClassPrefix + 'question').data('required'); 414 if(!check_required){ 415 $(this).parents('.' + _this.htmlClassPrefix + 'question').removeClass('ays-has-error'); 416 $(this).parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-validation-error').html(''); 417 } 418 419 var clearContainer = $(this).parents('.' + _this.htmlClassPrefix + 'answer-clear-selection-container'); 420 $(this).parents('.' + _this.htmlClassPrefix + 'question-answers').find('input[type="radio"][name^="' + _this.htmlClassPrefix + 'answers"]').prop('checked', false); 421 clearContainer.removeClass('in'); 422 clearContainer.addClass('out'); 423 424 if( $(this).parents('.' + _this.htmlClassPrefix + 'question-answers').find('.' + _this.htmlClassPrefix + 'answer-star').length > 0 ){ 425 $(this).parents('.' + _this.htmlClassPrefix + 'question-answers').find('.' + _this.htmlClassPrefix + 'answer-star .' + _this.htmlClassPrefix + 'answer-label').each(function() { 426 $(this).find('i').removeClass('ays-fa-star').addClass('ays-fa-star-o').removeAttr('style'); 427 $(this).removeClass('active-answer'); 428 }); 429 } 430 431 if( $(this).parents('.' + _this.htmlClassPrefix + 'question-answers').find('.' + _this.htmlClassPrefix + 'answer-business-active').length > 0 ){ 432 $(this).parents('.' + _this.htmlClassPrefix + 'question-answers').find('.' + _this.htmlClassPrefix + 'answer-business-active').removeClass(_this.htmlClassPrefix + 'answer-business-active'); 433 } 434 435 if( $(this).parents('.' + _this.htmlClassPrefix + 'question-answers').find('.' + _this.htmlClassPrefix + 'answer-elegant-active-matrix-scale').length > 0 ){ 436 $(this).parents('.' + _this.htmlClassPrefix + 'question-answers').find('.' + _this.htmlClassPrefix + 'answer-elegant-active-matrix-scale').removeClass(_this.htmlClassPrefix + 'answer-elegant-active-matrix-scale'); 437 } 438 439 if( $(this).parents('.' + _this.htmlClassPrefix + 'question-answers').find('.' + _this.htmlClassPrefix + 'answer-elegant-active').length > 0 ){ 440 $(this).parents('.' + _this.htmlClassPrefix + 'question-answers').find('.' + _this.htmlClassPrefix + 'answer-elegant-active').removeClass(_this.htmlClassPrefix + 'answer-elegant-active'); 441 } 442 443 setTimeout(function(){ 444 clearContainer.addClass(_this.htmlClassPrefix + 'visibility-none'); 445 }, 200); 446 }); 447 448 if(_this.dbOptions.survey_question_text_to_speech){ 449 window.addEventListener('beforeunload', function(event) { 450 event.preventDefault(); 451 speechSynthesis.cancel(); 452 }); 453 454 this.voices = surveyGetVoices(); 455 var voiceAction = false; 456 _this.$el.on('click', '.' + _this.htmlClassPrefix + 'question-title-text-to-speech-icon', function(){ 457 voiceAction = !voiceAction; 458 var questionText = atob($(this).attr('data-question')); 459 if ('speechSynthesis' in window) { 460 461 this.voices = surveyGetVoices(); 462 var rate = 1, pitch = 1, volume = 1; 463 if(voiceAction){ 464 _this.listenQuestionText(questionText, this.voices[0], rate, pitch, volume, 'play' ); 465 } 466 else{ 467 _this.listenQuestionText(questionText, this.voices[0], rate, pitch, volume, 'cancel' ); 468 } 469 }else{ 470 console.log('Speech Synthesis Not Supported'); 471 } 472 }); 473 } 474 475 _this.radioCheckboxTypesChanges( this.$el, _this.htmlClassPrefix, _this.dbOptions ); 476 _this.makeThemeQuestionContentActive( this.$el, _this.htmlClassPrefix, _this.dbOptions ); 477 478 if( _this.dbOptions[ _this.dbOptionsPrefix + 'enable_leave_page' ] ){ 479 window.onbeforeunload = function (e) { 480 if( _this.confirmBeforeUnload === true ){ 481 return true; 482 }else{ 483 return null; 484 } 485 } 486 } 487 488 _this.$el.on('input', '.' + _this.htmlClassPrefix + 'question-email-input', function(){ 489 490 $(this).parents('.' + _this.htmlClassPrefix + 'question').removeClass('ays-has-error'); 491 $(this).parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-validation-error').html(''); 492 493 if($(this).val() != ''){ 494 if (!(_this.emailValidatePattern.test($(this).val()))) { 495 var errorMessage = '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">'; 496 errorMessage += '<span>' + aysSurveyLangObj.emailValidationError + '</span>'; 497 $(this).parents('.' + _this.htmlClassPrefix + 'question').addClass('ays-has-error'); 498 $(this).parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-validation-error').html(errorMessage); 499 $(this).parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-validation-error').show(); 500 }else{ 501 $(this).parents('.' + _this.htmlClassPrefix + 'question').removeClass('ays-has-error'); 502 $(this).parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-validation-error')
502.hide(); 503 $(this).parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-validation-error').html(''); 504 } 505 }else{ 506 $(this).parents('.' + _this.htmlClassPrefix + 'question').removeClass('ays-has-error'); 507 $(this).parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-validation-error').hide(); 508 $(this).parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-validation-error').html(''); 509 } 510 }); 511 512 _this.$el.on('keypress', '.' + _this.htmlClassPrefix + 'question-input[type="number"]', function(event){ 513 if (event.keyCode < 58 && event.keyCode > 47 || event.key > -1 && event.key < 10) { 514 /* nothing */ 515 } else if (event.keyCode == 8 || event.keyCode == 0) { 516 /* nothing */ 517 // } else if ( $(this).val().toLowerCase().indexOf( "e" ) == -1 && ( event.keyCode == 101 || event.keyCode == 69 ) ){ 518 /* nothing */ 519 } else { 520 event.preventDefault(); 521 } 522 }); 523 524 var active = false; 525 _this.$el.on('mouseout', '.' + _this.htmlClassPrefix + 'answer-star',function(){ 526 var surveyColor = _this.dbOptions[ _this.dbOptionsPrefix + 'text_color' ]; 527 var surveyActiveColor = _this.dbOptions[ _this.dbOptionsPrefix + 'color' ]; 528 var allRateLabels = $(this).find('label'); 529 530 if($(this).find(".ays-fa-star").length !== 0) { 531 active = true; 532 } 533 534 if (active) { 535 var index = -1; 536 allRateLabels.each(function() { 537 if ($(this).hasClass('active-answer')) { 538 index = allRateLabels.index(this); 539 } 540 }); 541 for (var i = 0; i < allRateLabels.length; i++) { 542 if( _this.dbOptions[ _this.dbOptionsPrefix+'is_business'] ){ 543 if (i > index) { 544 allRateLabels.eq(i).find('i').css('color','#ffffff'); 545 } else { 546 allRateLabels.eq(i).find('i').css('color','#fc0'); 547 } 548 }else{ 549 if (i > index) { 550 allRateLabels.eq(i).find('i').removeClass('ays-fa-star').addClass('ays-fa-star-o'); 551 } else { 552 allRateLabels.eq(i).find('i').removeClass('ays-fa-star-o').addClass('ays-fa-star'); 553 } 554 } 555 } 556 }else{ 557 allRateLabels.each(function() { 558 if( _this.dbOptions[ _this.dbOptionsPrefix+'is_business'] ){ 559 $(this).find('i').css('color','#ffffff'); 560 } 561 else{ 562 $(this).find('i').removeClass('ays-fa-star').addClass('ays-fa-star-o'); 563 } 564 }); 565 } 566 }); 567 568 _this.$el.on('click', '.' + _this.htmlClassPrefix + 'answer-star .'+ _this.htmlClassPrefix +'answer-label',function(){ 569 $(this).parents('.' + _this.htmlClassPrefix + 'question').removeClass('ays-has-error'); 570 $(this).parents('.' + _this.htmlClassPrefix + 'question').find('.' + _this.htmlClassPrefix + 'question-validation-error').html(''); 571 572 $(this).parent().find('label').each(function() { 573 $(this).removeClass('active-answer'); 574 }); 575 $(this).addClass('active-answer'); 576 active = true; 577 }); 578 579 _this.$el.on('mouseover', '.'+ _this.htmlClassPrefix + 'answer-star .'+ _this.htmlClassPrefix +'answer-label',function(){ 580 var surveyColor = _this.dbOptions[ _this.dbOptionsPrefix + 'color' ]; 581 var allRateLabels = $(this).parent().find('label'); 582 var index = allRateLabels.index(this); 583 allRateLabels.each(function() { 584 if( _this.dbOptions[ _this.dbOptionsPrefix+'is_business'] ){ 585 $(this).find('i').css('color','#ffffff'); 586 } 587 else{ 588 $(this).find('i').removeClass('ays-fa-star').addClass('ays-fa-star-o'); 589 } 590 591 }); 592 for (var i = 0; i <= index; i++) { 593 if( _this.dbOptions[ _this.dbOptionsPrefix+'is_business'] ){ 594 allRateLabels.eq(i).find('i').css('color','#fc0'); 595 } 596 else{ 597 allRateLabels.eq(i).find('i').removeClass('ays-fa-star-o').addClass('ays-fa-star'); 598 } 599 } 600 }); 601 602 _this.$el.on('click', '.' + _this.htmlClassPrefix + 'restart-button', function(){ 603 window.location.reload(); 604 }); 605 606 _this.$el.find(".ays-survey-range-type-input[data-type='just-range']").on('change' , function(){ 607 $(this).parents('.ays-survey-question').attr("data-required", false); 608 }); 609 610 _this.$el.find(".ays-survey-range-type-input-for-required").on('change' , function(){ 611 $(this).addClass("isChanged"); 612 }); 613 614 _this.$el.find(".ays-survey-range-type-input-for-required").on('input' , function(e){
615 var rangeCalcType = $(this).parents(".ays-survey-answer-slider-list-main").attr('data-calc-type'); 616 if(rangeCalcType == 'combined'){ 617 var rangeMaxLength = $(this).parents(".ays-survey-answer-slider-list-main").attr('data-max-length'); 618 619 var currentRangeName = $(this).attr("name"); 620 var allRanges = $(this).parents(".ays-survey-answer-slider-list-container").find('input:not([name="'+currentRangeName+'"])'); 621 622 var allRangesSum = 0; 623 allRanges.each(function(){ 624 allRangesSum += parseInt($(this).val()); 625 }); 626 627 var rangeMaxVal = rangeMaxLength - allRangesSum; 628 if( $(this).val() >= rangeMaxVal){ 629 $(this).val(rangeMaxVal); 630 $(this).addClass('ays-survey-range-type-input-disaled'); 631 } 632 else{ 633 $(this).removeClass('ays-survey-range-type-input-disaled'); 634 } 635 636 } 637 }); 638 639 _this.$el.find(".ays-survey-range-type-input").each(function(){ 640 var input = $(this).get(0); 641 var span = $(this).parents('.ays-survey-answer-range-type-main').find("span").get(0); 642 643 setBubble( input, span ); 644 }); 645 646 _this.$el.find(".ays-survey-range-type-input").on('input', function(){ 647 var input = $(this).get(0); 648 var span = $(this).parents('.ays-survey-answer-range-type-main').find("span").get(0); 649 650 setBubble( input, span ); 651 }); 652 653 _this.$el.find(".ays-survey-range-type-input").hover(function(){ 654 $(this).parents('.ays-survey-answer-range-type-main').find("span").addClass('ays-survey-answer-range-type-main-show'); 655 }, function(){ 656 $(this).parents('.ays-survey-answer-range-type-main').find("span").removeClass('ays-survey-answer-range-type-main-show'); 657 }); 658 659 _this.$el.find(".ays-survey-range-type-input").on("touchstart" , function(){ 660 $(this).parents('.ays-survey-answer-range-type-main').find("span").addClass('ays-survey-answer-range-type-main-show'); 661 }); 662 663 _this.$el.find(".ays-survey-range-type-input").on("touchend" , function(){ 664 $(this).parents('.ays-survey-answer-range-type-main').find("span").removeClass('ays-survey-answer-range-type-main-show'); 665 }); 666 667 // Social buttons 668 _this.$el.find(".ays-survey-share-btn").on("click" , function(e){ 669 e.preventDefault(); 670 var wWidth = 650, 671 wHeight = 450; 672 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); 673 window.open(this.href, "_blank", windowOptions); 674 }); 675 676 // Survey full screen 677 _this.$el.find('.ays-survey-close-full-screen, .ays-survey-open-full-screen').on('click', function() { 678 _this.toggleFullscreen(_this.el); 679 }); 680 _this.aysSurveyFullScreenDeactivateAll(); 681 682 // Text limit character/word 683 _this.$el.find('textarea.ays-survey-check-word-limit, input.ays-survey-check-word-limit').on('keyup keypress', function(e) { 684 var currentQuestion = $(this).parents(".ays-survey-question"); 685 var currentquestionId = currentQuestion.find('.' + _this.htmlClassPrefix + 'question-id').val(); 686 var questionTextLimitOptions = _this.dbOptions[ _this.dbOptionsPrefix + 'text_limit_options' ][currentquestionId]; 687 _this.aysSurveyCheckTextLimit(currentQuestion,questionTextLimitOptions,e,$(this)); 688 }); 689 690 // Number limit character/word 691 _this.$el.find('input.ays-survey-check-number-limit').on('keyup', function(e) { 692 var currentQuestion = $(this).parents(".ays-survey-question"); 693 var currentquestionId = currentQuestion.find('.' + _this.htmlClassPrefix + 'question-id').val(); 694 var questionTextLimitOptions = _this.dbOptions[ _this.dbOptionsPrefix + 'number_limit_options' ][currentquestionId]; 695 _this.aysSurveyCheckNumberLimit(currentQuestion,questionTextLimitOptions,e,$(this)); 696 }); 697 698 _this.$el.find('.ays-survey-section .ays-survey-answer-label input[type="radio"],.ays-survey-detect-selected-question-dropdown').on('change' , function(){ 699 _this.aysAutoNext($(this)); 700 }); 701 702 703 _this.aysSurveyonTabPress(); 704 705 // Number limit character/word 706 _this.$el.find('input.ays-survey-is-phone-type').on('keypress', function(e) { 707 var theEvent = e || window.event; 708 var key = theEvent.keyCode || theEvent.which; 709 key = String.fromCharCode( key ); 710 var checkingVal = _this.phoneValivatePattern.test(key); 711 if( !checkingVal ){ 712 theEvent.returnValue = false; 713 if(theEvent.preventDefault) e.preventDefault(); 714 715 } 716 }); 717 718 719 720 _this.$el.one("click" , function(){ 721 _this.startDate = _this.GetFullDateTime(); 722 }); 723 724 _this.$el.on('click', '.' + _this.htmlClassPrefix + 'collapse-question-action',function(){ 725 var $this = $(this); 726 _this.collapseQuestion( $this ); 727 }); 728 729 _this.$el.on('click', '.' + _this.htmlClassPrefix + 'action-expand-question' + ',' + '.'+ _this.htmlClassPrefix +'question-wrap-collapsed-action' ,function(){ 730 var $this = $(this); 731 _this.expandQuestion( $this ); 732 }); 733 734 _this.$el.on('change', '.' + _this.htmlClassPrefix + 'answer-upload-type-file',function(){ 735 var $this = $(this); 736 var thisParent = $this.parents('.' + _this.htmlClassPrefix + 'question'); 737 var typeError = thisParent.find('.' + _this.htmlClassPrefix + 'answer-upload-type-error-type'); 738 var sizeError = thisParent.find('.' + _this.htmlClassPrefix + 'answer-upload-type-error-size'); 739 var questionId = thisParent.data("id"); 740 var thisQuestionopts = _this.dbOptions[ _this.dbOptionsPrefix + 'questions' ][questionId].options; 741 742 var file = $this.prop("files")[0]; 743 if(typeof file != "undefined"){ 744 var currentFileName = file.name; 745 var currentFileType = currentFileName.split('.').pop(); 746 747 var fileSize = file.size; 748 var fileSizeMb = ((fileSize/1024)/1024).toFixed(4); 749 var fileAllowedSize = thisQuestionopts.file_upload_types_size; 750 751 var allExtentions = new Array("pdf", "doc", "docx", "png", "jpg","jpeg", "gif", "mp4"); 752 var allowedExtentions = new Array(); 753 if(thisQuestionopts.file_upload_toggle == "on"){ 754 for(var i = 0; i <= allExtentions.length - 1; i++){ 755 var checker = "file_upload_types_"+allExtentions[i]; 756 if(thisQuestionopts[checker] != "undefined" && thisQuestionopts[checker] == "on"){ 757 if(allExtentions[i] == "jpg"){ 758 allowedExtentions.push("jpg" , "jpeg"); 759 }else if(allExtentions[i] == "doc"){ 760 allowedExtentions.push("doc" , "docx"); 761 }else{ 762 allowedExtentions.push(allExtentions[i]); 763 } 764 } 765 } 766 }else{ 767 allowedExtentions = allExtentions; 768 } 769 770 if(allowedExtentions.indexOf(currentFileType.toLowerCase()) !== -1){ 771 typeError.hide(); 772 sizeError.hide(); 773 if(+fileSizeMb <= +fileAllowedSize){ 774 typeError.hide(); 775 sizeError.hide(); 776 $this.parents('.ays-survey-question').attr("data-required", false); 777 var formData = new FormData(); 778 var sFunction = 'ays_survey_upload_file'; 779 formData.append('file', file); 780 formData.append('function', sFunction); 781 formData.append('action', _this.ajaxAction); 782 thisParent.find('.' + _this.htmlClassPrefix + 'answer-upload-type-loader').show(); 783 _this.uploadFile(formData , thisParent , currentFileName); 784 }else{ 785 typeError.hide(); 786 sizeError.css("display" , "flex"); 787 788 } 789 }else{ 790 typeError.css("display" , "flex"); 791 sizeError.hide(); 792 } 793 thisParent.find('.' + _this.htmlClassPrefix + 'answer-upload-type-file').val(""); 794 setTimeout(function(){ 795 typeError.hide(); 796 sizeError.hide(); 797 thisParent.find('.' + _this.htmlClassPrefix + 'answer-upload-type-loader').hide(); 798 }, 6000); 799 } 800 }); 801 802 _this.$el.on('click', '.' + _this.htmlClassPrefix + 'answer-upload-ready-image-box',function(){ 803 var $this = $(this); 804 var isRequiredQuestion = $this.parents('.' + _this.htmlClassPrefix + 'answer-upload-type-main').attr("data-required"); 805 var $thisParent = $this.parents('.' + _this.htmlClassPrefix + 'answer-upload-type-main'); 806 var thisParent = $this.parents('.' + _this.htmlClassPrefix + 'question'); 807 $thisParent.find('.' + _this.htmlClassPrefix + 'answer-upload-ready').hide(); 808 $thisParent.find('.' + _this.htmlClassPrefix + 'answer-upload-type').show(); 809 $thisParent.find('.' + _this.htmlClassPrefix + 'answer-upload-ready-url-link').val(""); 810 $thisParent.find('.' + _this.htmlClassPrefix + 'answer-upload-type-file').val(""); 811 if(isRequiredQuestion == "true"){ 812 thisParent.attr("data-required", true); 813 } 814 }); 815 816 _this.$el.on('change', 'input[name^="' + _this.htmlClassPrefix + 'answers"]', function () { 817 var questionType = $(this).parents('.' + _this.htmlClassPrefix + 'question').attr('data-type'); 818 var questionId = $(this).parents('.' + _this.htmlClassPrefix + 'question').attr('data-id'); 819 var answerId = null, 820 value = null, 821 negative = false, 822 multi = false; 823 824 if (questionType == 'linear_scale' || questionType == 'range') { 825 value = $(this).val(); 826 } else if (questionType == 'radio' || questionType == 'checkbox' || questionType == 'select') { 827 answerId = $(this).val(); 828 if (questionType == 'checkbox') { 829 multi = true; 830 if (!$(this).is(":checked")) { 831 negative = true; 832 } 833 } 834 } else { 835 return false; 836 } 837 838 var sendData = { 839 questionId: questionId, 840 answerId: answerId, 841 value: value, 842 negative: negative, 843 multiAns: multi, 844 } 845 846 _this.updateCalculationValue(sendData); 847 }); 848 849 _this.$el.on('input', 'input[type="number"][name^="' + _this.htmlClassPrefix + 'answers"]', function () { 850 var questionId = $(this).parents('.' + _this.htmlClassPrefix + 'question').attr('data-id'); 851 var value = $(this).val(); 852 853 var sendData = { 854 questionId: questionId, 855 answerId: null, 856 value: value, 857 negative: false, 858 multiAns: false, 859 } 860 861 _this.updateCalculationValue(sendData); 862 }); 863 864 865 var timeInput = _this.$el.find('.' + _this.htmlClassPrefix + 'timepicker'); 866 if(timeInput.length > 0){ 867 _this.$el.find('.' + _this.htmlClassPrefix + 'timepicker').timepicker(); 868 } 869 _this.$el.find('.' + _this.htmlClassPrefix + 'answer-matrix-scale-main').scroll(function(e) { 870 if($(this).scrollLeft() > 0){ 871 $(this).find('.ays-survey-answer-matrix-scale-row:not(:first-child) .' + _this.htmlClassPrefix + 'answer-matrix-scale-column-row-header').addClass(_this.htmlClassPrefix + 'answer-matrix-scale-column-row-header-scrolled'); 872 } 873 else{ 874 $(this).find('.ays-survey-answer-matrix-scale-row:not(:first-child) .' + _this.htmlClassPrefix + 'answer-matrix-scale-column-row-header').removeClass(_this.htmlClassPrefix + 'answer-matrix-scale-column-row-header-scrolled'); 875 } 876 }); 877 878 _this.$el.on('click', '.ays-survey-edit-previous-submission-button',function(){ 879 _this.$el.addClass('ays-survey-activated-edit-prev-submission'); 880 var currentSurveyId = typeof _this.dbOptions.id != 'undefined' && _this.dbOptions.id ? _this.dbOptions.id : null; 881 $(this).addClass('display_none'); 882 $(this).parents('.ays-survey-edit-previous-submission-box').find('img.ays-survey-edit-previous-submission-loader').removeClass('display_none'); 883 if($(this).hasClass('ays-survey-edit-previous-submission-restricted')){ 884 _this.$el.find('.ays-survey-restricted-content.active-section').removeClass('active-section'); 885 _this.$el.find('.ays-survey-sections').removeClass('display_none'); 886 } 887 _this.requestForEditSubmission(currentSurveyId , $(this)); 888 }) 889 890 _this.$el.find('.ays-survey-question[data-type=ranking] .ays-survey-question-answers').sortable({ 891 opacity: 0.8, 892 axis: 'y', 893 placeholder: 'clone', 894 helper: "clone", 895 forcePlaceholderSize: true, 896 forceHelperSize: true, 897 update: function (item, event) { 898 _this.updateRankingType(item, event); 899 } 900 }); 901 902 903 // _this.$el.on('click' , '.ays-survey-submission-summary-question-change-results-view-button' , function(){ 904 // var thisButton = $(this); 905 // changeResultsView(thisButton); 906 // }); 907 908 _this.$el.on('change', '.' + _this.htmlClassPrefix + 'question[data-one-response="true"] .' + _this.htmlClassPrefix + 'answer-label-matrix-row input[type="radio"][name^="' + _this.htmlClassPrefix + 'answers"]', function(){ 909 var $this = $(this); 910 var parent = $this.parents('.' + _this.htmlClassPrefix + 'question'); 911 912 _this.checkOneResponsePerColumn( parent ); 913 }); 914 } 915 916 AysSurveyPlugin.prototype.setCalculationOptions = function () { 917 var _this = this; 918 919 var calcQuestions = _this.$el.find('.' + _this.htmlClassPrefix + 'question[data-type="calculation"]'); 920 var surveyId = _this.$el.find('input[name*="ays-survey-id"]').val(); 921 var uniqueId = _this.$el.attr('data-id'); 922 923 if (calcQuestions.length > 0) { 924 calcQuestions.each((key, question) => { 925 var questionId = $(question).attr('data-id'); 926 var options = JSON.parse( window.atob( window.aysSurveyCalculationOptions[ surveyId + '-' + uniqueId + '-' + questionId ] ) ); 927 928 var formula = options.calculationTypeContent;
929 var answersData = options.calculationTypeValue; 930 var isTotal = options.calculationTypeTotal; 931 var initialValues = options.calculationTypeQuestionInitialValues; 932 933 _this.calculationQuestionsOptions[questionId] = { 934 questionId: questionId, 935 formula: formula, 936 answersData: answersData, 937 isTotal: isTotal, 938 }; 939 940 _this.calculationQuestionsValues[questionId] = initialValues[questionId] ?? 0; 941 _this.questionsValues[questionId] = {...initialValues}; 942 943 }); 944 } 945 } 946 947 AysSurveyPlugin.prototype.updateCalculationValue = function (sendData) { 948 var _this = this; 949 950 if (sendData && _this.calculationQuestionsOptions && Object.keys(sendData).length !== 0 && Object.keys(_this.calculationQuestionsOptions).length !== 0) { 951 var changedQuestionId = sendData.questionId; 952 var chosenAnswerId = sendData.answerId; 953 var chosenAnswer = sendData.value; 954 var multiAnswer = sendData.multiAns; 955 var uncheckedAnswer = sendData.negative; 956 for (var id in _this.calculationQuestionsOptions) { 957 var calcInput = _this.$el.find('.ays-survey-question[data-id="'+id+'"]').find('#' + _this.htmlClassPrefix + 'answer-calculation-type-value-'+id); 958 var calcSpan = _this.$el.find('.ays-survey-question[data-id="'+id+'"]').find('#' + _this.htmlClassPrefix + 'answer-calculation-type-formula-'+id); 959 960 var formula = _this.calculationQuestionsOptions[id].formula; 961 var answersData = _this.calculationQuestionsOptions[id].answersData; 962 var valueToReplace = 0; 963 964 if (chosenAnswerId !== null) { 965 if (answersData.hasOwnProperty(changedQuestionId)) { 966 if (answersData[changedQuestionId].hasOwnProperty(chosenAnswerId)) { 967 if (uncheckedAnswer) { 968 valueToReplace -= +answersData[changedQuestionId][chosenAnswerId]['point']; 969 } else { 970 valueToReplace += +answersData[changedQuestionId][chosenAnswerId]['point']; 971 } 972 } 973 } 974 } else if (chosenAnswer !== null) { 975 if (chosenAnswer !== '') { 976 if (uncheckedAnswer) { 977 valueToReplace -= +chosenAnswer; 978 } else { 979 valueToReplace += +chosenAnswer; 980 } 981 } 982 } 983 984 if (multiAnswer && _this.questionsValues[id][changedQuestionId] != undefined) { 985 _this.questionsValues[id][changedQuestionId] += valueToReplace; 986 } else { 987 _this.questionsValues[id][changedQuestionId] = valueToReplace; 988 } 989 990 var finalFormula = formula.replace(/{(\d+)}/g, (match, key) => { 991 var value = _this.questionsValues[id][key] !== undefined ? _this.questionsValues[id][key] : 0; 992 993 if (value === 0 && formula[formula.indexOf(match) - 1] === '/') { 994 value = 1; 995 } 996 997 return value.toString(); 998 }); 999 1000 for (var pattern in _this.calculationRegexReplacements) { 1001 var regex = new RegExp(pattern, 'g'); 1002 finalFormula = finalFormula.replace(regex, _this.calculationRegexReplacements[pattern]); 1003 } 1004 var calculatedValue = _this.evaluateFormula(finalFormula); 1005 _this.calculationQuestionsValues[id] = isNaN(calculatedValue) ? _this.calculationQuestionsValues[id] : Math.round((calculatedValue + Number.EPSILON) * 100) / 100; 1006 1007 calcInput.val(_this.calculationQuestionsValues[id]); 1008 calcSpan.html(_this.calculationQuestionsValues[id]); 1009 } 1010 } 1011 } 1012 1013 AysSurveyPlugin.prototype.updateCalculationValueOnLoad = function () { 1014 var _this = this; 1015 1016 var surveyQuestions = _this.$el.find('input[name^="' + _this.htmlClassPrefix + 'answers"]:checked'); 1017 $.each(surveyQuestions, function(){ 1018 var questionType = $(this).parents('.' + _this.htmlClassPrefix + 'question').attr('data-type'); 1019 var questionId = $(this).parents('.' + _this.htmlClassPrefix + 'question').attr('data-id'); 1020 var answerId = null, 1021 value = null, 1022 negative = false, 1023 multi = false; 1024 1025 if (questionType == 'linear_scale' || questionType == 'range') { 1026 value = $(this).val(); 1027 } else if (questionType == 'radio' || questionType == 'checkbox' || questionType == 'select') { 1028 answerId = $(this).val(); 1029 if (questionType == 'checkbox') { 1030 multi = true; 1031 if (!$(this).is(":checked")) { 1032 negative = true; 1033 } 1034 } 1035 } else { 1036 return; 1037 } 1038 1039 var sendData = { 1040 questionId: questionId, 1041 answerId: answerId, 1042 value: value, 1043 negative: negative, 1044 multiAns: multi, 1045 } 1046 1047 _this.updateCalculationValue(sendData); 1048 }); 1049 } 1050 1051 AysSurveyPlugin.prototype.evaluateFormula = function(formula) { 1052 try { 1053 var calculate = new Function('return ' + formula); 1054 var result = calculate(); 1055 return result; 1056 } catch (error) { 1057 console.error('Error in formula:', error); 1058 return false; 1059 } 1060 } 1061 1062 1063 AysSurveyPlugin.prototype.start = function(e) { 1064 var _this = this; 1065 var $this = _this.$el.find('.' + _this.htmlClassPrefix + 'start-button'); 1066 1067 if(_this.showAllSections.length > 0){ 1068 _this.showAllSections.addClass('active-section'); 1069 _this.$el.find('.' + _this.htmlClassPrefix + 'show-all').not(':last').find('.' + _this.htmlClassPrefix + 'section-buttons').addClass( _this.htmlClassPrefix + 'display-none' ); 1070 // _this.showAllSections.find('.' + _this.htmlClassPrefix + 'section-button.' + _this.htmlClassPrefix + 'next-button').addClass( _this.htmlClassPrefix + 'display-none' ); 1071 _this.showAllSections.find('.' + _this.htmlClassPrefix + 'section-button.' + _this.htmlClassPrefix + 'prev-button').addClass( _this.htmlClassPrefix + 'display-none' ); 1072 _this.showAllSections.find('.' + _this.htmlClassPrefix + 'promote-survey-content').not(':last').addClass( _this.htmlClassPrefix + 'display-none' ); 1073 } 1074 1075 _this.current_fs = $(e.target).parents('.' + _this.htmlClassPrefix + 'section'); 1076 _this.next_fs = $(e.target).parents('.' + _this.htmlClassPrefix + 'section').next(); 1077 // _this.aysResetQuiz( _this.$el ); 1078 1079 var sectionsData = _this.dbOptions[ _this.dbOptionsPrefix + 'sections' ]; 1080 var logicJumpSectionsGoTo = {}; 1081 1082 $.each(sectionsData, function(i){ 1083 var logicSection = sectionsData[i]; 1084 1085 if( typeof logicSection.options != 'undefined' ){ 1086 var logicSecOptions = logicSection.options; 1087 if( typeof logicSecOptions.go_to_section != 'undefined' ){ 1088 logicJumpSectionsGoTo[ logicSection.id ] = logicSecOptions.go_to_section; 1089 } 1090 } 1091 }); 1092 1093 var whatToDoSection = null; 1094 var thisSectionId = null; 1095 var whereToJumpSection = parseInt( logicJumpSectionsGoTo[ thisSectionId ] ); 1096 if( whereToJumpSection == thisSectionId ){ 1097 whatToDoSection = 'go_to_same_section'; 1098 }else if( whereToJumpSection == -1 ){ 1099 whatToDoSection = null; 1100 }else if( whereToJumpSection == -2 ){ 1101 whatToDoSection = 'submit_form'; 1102 }else{ 1103 whatToDoSection = 'go_to_section'; 1104 } 1105 1106 if( $.isEmptyObject( logicJumpSectionsGoTo ) ){ 1107 whereToJumpSection = null; 1108 } 1109 1110 if( isNaN( whereToJumpSection ) ){ 1111 whereToJumpSection = null; 1112 } 1113 1114 var whatToDoSectionNext = null; 1115 var nextSectionId = null; 1116 var whereToJumpSectionNext = parseInt( logicJumpSectionsGoTo[ nextSectionId ] ); 1117 if( whereToJumpSectionNext == nextSectionId ){ 1118 whatToDoSectionNext = 'go_to_same_section'; 1119 }else if( whereToJumpSectionNext == -1 ){ 1120 whatToDoSectionNext = 'go_to_next_section'; 1121 }else if( whereToJumpSectionNext == -2 ){ 1122 whatToDoSectionNext = 'submit_form'; 1123 }else{ 1124 whatToDoSectionNext = 'go_to_section'; 1125 } 1126 1127 if( $.isEmptyObject( logicJumpSectionsGoTo ) ){ 1128 whatToDoSectionNext = 'go_to_next_section'; 1129 } 1130 1131 if( isNaN( whereToJumpSectionNext ) ){ 1132 whatToDoSectionNext = 'go_to_next_section'; 1133 } 1134 1135 if( ( whatToDoSectionNext == 'go_to_next_section' ) && _this.$el.find("div.ays-survey-section[data-id]").length - 1 == _this.$el.find("div.ays-survey-section[data-id]").index( _this.next_fs ) ){ 1136 whatToDoSectionNext = null; 1137 } 1138 1139 if( whatToDoSectionNext == 'submit_form' || whatToDoSectionNext == null ){ 1140 _this.next_fs.find('.' + _this.htmlClassPrefix + 'section-button.' + _this.htmlClassPrefix + 'finish-button').removeClass( _this.htmlClassPrefix + 'display-none' ); 1141 _this.next_fs.find('.' + _this.htmlClassPrefix + 'section-button.' + _this.htmlClassPrefix + 'next-button').addClass( _this.htmlClassPrefix + 'display-none' ); 1142 } 1143 1144 _this.activeStep( $(e.target), 'next', null); 1145 }; 1146 1147 AysSurveyPlugin.prototype.startTime = function (e) { 1148 var _this = this; 1149 var $this = $(e.target); 1150 var thisStep = $this.parents('.step'); 1151 _this.$el.find('.ays-live-bar-wrap').css({'display': 'block'});
1152 _this.$el.find('.ays-live-bar-percent').css({'display': 'inline-block'}); 1153 _this.$el.find('input.ays-start-date').val(_this.GetFullDateTime()); 1154 if (_this.dbOptions.enable_timer == 'on') { 1155 _this.$el.find('div.ays-survey-timer').hide(); 1156 var timer = parseInt(_this.$el.find('div.ays-survey-timer').attr('data-timer')); 1157 if (!isNaN(timer) && _this.dbOptions.timer !== undefined) { 1158 if (_this.dbOptions.timer === timer && timer !== 0) { 1159 timer += 2; 1160 if (timer !== undefined) { 1161 _this.timer(timer, { 1162 isTimer: true, 1163 blockedContent: false, 1164 blockedElement: null, 1165 }); 1166 } 1167 } else { 1168 alert('Wanna cheat??'); 1169 window.location.reload(); 1170 } 1171 } 1172 } 1173 } 1174 1175 AysSurveyPlugin.prototype.timer = function(timer, args) { 1176 if(typeof args == "undefined"){ 1177 args = {}; 1178 } 1179 var _this = this; 1180 var addTime = 0; 1181 if(timer >= 0){ 1182 addTime = (timer * 1000); 1183 } 1184 var countDownDate = new Date().getTime() + addTime; 1185 var timeForShow; 1186 if(addTime > 0){ 1187 var x = setInterval(function (){ 1188 var now = new Date().getTime(); 1189 var distance = countDownDate - Math.ceil(now/1000)*1000; 1190 var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); 1191 var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); 1192 var seconds = Math.floor((distance % (1000 * 60)) / 1000); 1193 if(hours <= 0){ 1194 hours = null; 1195 }else if (hours < 10) { 1196 hours = '0' + hours; 1197 } 1198 if (minutes < 10) { 1199 minutes = '0' + minutes; 1200 } 1201 if (seconds < 10) { 1202 seconds = '0' + seconds; 1203 } 1204 timeForShow = ((hours == null)? "" : (hours + ":")) + minutes + ":" + seconds; 1205 if(distance <= 1000){ 1206 timeForShow = ((hours == null) ? "" : "00:") + "00:00"; 1207 }else{ 1208 timeForShow = timeForShow; 1209 } 1210 _this.$el.find('.' + _this.htmlClassPrefix + 'countdown-time').html(timeForShow); 1211 // _this.$el.find('.' + _this.htmlClassPrefix + 'countdown-time').show(500); 1212 if(_this.$el.find('.' + _this.htmlClassPrefix + 'countdown-time').length === 0){ 1213 clearInterval(x); 1214 } 1215 1216 if (distance <= 1000) { 1217 clearInterval(x); 1218 if(args.blockedContent){ 1219 if(args.redirectNewTab){ 1220 window.open( args.redirectUrl , "_blank"); 1221 } 1222 else{ 1223 window.location.assign( args.redirectUrl ); 1224 } 1225 } 1226 } 1227 }, 1000); 1228 } 1229 else{ 1230 if(args.blockedContent){ 1231 if(args.redirectNewTab){ 1232 window.open( args.redirectUrl , "_blank"); 1233 } 1234 else{ 1235 window.location.assign( args.redirectUrl ); 1236 } 1237 } 1238 } 1239 }; 1240 1241 AysSurveyPlugin.prototype.ratingAvg = function() { 1242 var _this = this; 1243 _this.$el.find('.for_quiz_rate_avg.ui.rating').rating('disable'); 1244 }; 1245 1246 AysSurveyPlugin.prototype.aysNext = function() { 1247 var _this = this; 1248 1249 var questionsData = _this.dbOptions[ _this.dbOptionsPrefix + 'questions' ]; 1250 var sectionsData = _this.dbOptions[ _this.dbOptionsPrefix + 'sections' ]; 1251 var logicJumpQuestionsAnswersGoTo = {};
1252 var logicJumpQuestionCheckboxGoTo = {}; 1253 var logicJumpQuestionNPSGoTo = {}; 1254 var logicJumpQuestionsGoTo = {}; 1255 var logicJumpSectionsGoTo = {}; 1256 1257 $.each(sectionsData, function(i){ 1258 var logicSection = sectionsData[i]; 1259 1260 if( typeof logicSection.options != 'undefined' ){ 1261 var logicSecOptions = logicSection.options; 1262 if( typeof logicSecOptions.go_to_section != 'undefined' ){ 1263 logicJumpSectionsGoTo[ logicSection.id ] = logicSecOptions.go_to_section; 1264 } 1265 } 1266 }); 1267 1268 $.each(questionsData, function(i){ 1269 var logicQuestion = questionsData[i]; 1270 var logicAnswers = logicQuestion.answers; 1271 var qOptions = logicQuestion.options; 1272 var isLogicJump = typeof qOptions.is_logic_jump != 'undefined' ? qOptions.is_logic_jump : false; 1273 1274 if( (isLogicJump === true && logicAnswers.length > 0) || logicQuestion.type === 'nps'){ 1275 if( $.inArray( logicQuestion.type, _this.logicJumpQuestionTypes ) !== -1 ){ 1276 if ( logicQuestion.type === 'checkbox' ){ 1277 if (typeof qOptions.other_logic_jump != 'undefined') { 1278 logicJumpQuestionCheckboxGoTo[logicQuestion.id] = []; 1279 $.each(qOptions.other_logic_jump, function (j) { 1280 var logicAns = qOptions.other_logic_jump[j]; 1281 if (typeof logicAns.go_to_section != 'undefined') { 1282 logicJumpQuestionCheckboxGoTo[logicQuestion.id].push({ 1283 'go_to_section': parseInt( logicAns.go_to_section ), 1284 'selected_options': logicAns.selected_options, 1285 'otherwise': typeof qOptions.other_logic_jump_otherwise != 'undefined' ? parseInt( qOptions.other_logic_jump_otherwise ) : -1 1286 }); 1287 } 1288 }); 1289 } 1290 }else if( logicQuestion.type === 'nps'){ 1291 if (typeof qOptions.other_logic_jump != 'undefined') { 1292 logicJumpQuestionNPSGoTo[logicQuestion.id] = []; 1293 $.each(qOptions.other_logic_jump, function (j) { 1294 var logicAns = qOptions.other_logic_jump[j]; 1295 if (typeof logicAns.go_to_section != 'undefined') { 1296 logicJumpQuestionNPSGoTo[logicQuestion.id].push({ 1297 'go_to_section': parseInt( logicAns.go_to_section ), 1298 'selected_options': logicAns.selected_options, 1299 'otherwise': typeof qOptions.other_logic_jump_otherwise != 'undefined' ? parseInt( qOptions.other_logic_jump_otherwise ) : -1 1300 }); 1301 } 1302 }); 1303 } 1304 }else { 1305 $.each(logicAnswers, function (j) { 1306 var logicAns = logicAnswers[j]; 1307 if (typeof logicAns.options != 'undefined') { 1308 var logicAnsOptions = logicAns.options; 1309 if (typeof logicAnsOptions.go_to_section != 'undefined') { 1310 logicJumpQuestionsAnswersGoTo[logicAns.id] = logicAnsOptions.go_to_section; 1311 } 1312 } 1313 }); 1314 1315 if ( qOptions.other_answer_logic_jump !== "off" ) { 1316 logicJumpQuestionsGoTo[logicQuestion.id] = qOptions.other_answer_logic_jump; 1317 } 1318 } 1319 } 1320 } 1321 }); 1322 1323 _this.$el.on('click', '.' + _this.htmlClassPrefix + 'next-button', function (e){ 1324 _this.confirmBeforeUnload = true; 1325 e.preventDefault(); 1326 if (_this.animating) return false; 1327 _this.animating = true; 1328 if( _this.checkForm( $( e.target ) ) ){ 1329 var section = $(this).parents('.ays-survey-section'); 1330 var nextSection = section.next(); 1331 var thisSectionQuestions = section.find('.ays-survey-question'); 1332 1333 var whereToJump = null; 1334 var whereToJumpOtherAnswer = null; 1335 var thisSectionId = section.data('id'); 1336 // var nextSectionId = section.next().data('id'); 1337 var nextSectionId = nextSection.data('id'); 1338 var currentPage = _this.$el.find("div.ays-survey-section.active-section").data("pageNumber") + 1; 1339 1340 thisSectionQuestions.each(function(){ 1341 var questionType = $(this).data('type'); 1342 var questionId = $(this).data('id'); 1343 if( $.inArray( questionType, _this.logicJumpQuestionTypes ) !== -1 ){ 1344 var checkedElement = null; 1345 switch( questionType ){ 1346 case 'radio': 1347 checkedElement = $(this).find('.ays-survey-answer input[type="radio"]:checked'); 1348 break; 1349 case 'checkbox': 1350 checkedElement = $(this).find('.ays-survey-answer input[type="checkbox"]:checked'); 1351 break; 1352 case 'nps': 1353 checkedElement = $(this).find('.ays-survey-nps-label-answers-main-box input[type="radio"]:checked'); 1354 break; 1355 case 'select': 1356 checkedElement = $(this).find('.ays-survey-answer .ays-survey-question-select input[type="hidden"]'); 1357 break; 1358 default: 1359 break; 1360 } 1361 if( questionType === 'checkbox' && checkedElement.length > 0){ 1362 var selectedOptions = []; 1363 $.each(checkedElement, function (i) { 1364 if( $(this).val() == '0' ){ 1365 if( $(this).parents('.ays-survey-answer').find('.ays-survey-answer-other-input').val() !== '' ) { 1366 selectedOptions.push('other'); 1367 } 1368 }else { 1369 selectedOptions.push($(this).val()); 1370 } 1371 }); 1372 1373 if ( typeof logicJumpQuestionCheckboxGoTo[questionId] != 'undefined' ) { 1374 var ljChceckboxQuestion = logicJumpQuestionCheckboxGoTo[questionId]; 1375 var ljChceckboxConditions = {}; 1376 for ( var i = 0; i < ljChceckboxQuestion.length; i++ ){ 1377 if ( typeof ljChceckboxQuestion[i].selected_options != 'undefined' ) { 1378 if (ljChceckboxQuestion[i].selected_options.equals(selectedOptions)) { 1379 ljChceckboxConditions.go_to_section = ljChceckboxQuestion[i].go_to_section; 1380 ljChceckboxConditions.otherwise = null; 1381 break; 1382 } else { 1383 ljChceckboxConditions.go_to_section = null; 1384 ljChceckboxConditions.otherwise = ljChceckboxQuestion[i].otherwise; 1385 } 1386 }else if( typeof ljChceckboxQuestion[i].otherwise != 'undefined' ){ 1387 ljChceckboxConditions.go_to_section = null; 1388 ljChceckboxConditions.otherwise = ljChceckboxQuestion[i].otherwise; 1389 } 1390 } 1391 1392 if( ljChceckboxConditions.go_to_section !== null ){ 1393 whereToJump = ljChceckboxConditions.go_to_section; 1394 if (whereToJump !== -1) { 1395 currentPage = _this.$el.find("div.ays-survey-section[data-id=" + whereToJump + "]").data("pageNumber"); 1396 } 1397 }else if( ljChceckboxConditions.otherwise !== null ){ 1398 whereToJump = ljChceckboxConditions.otherwise; 1399 if (whereToJump !== -1) { 1400 currentPage = _this.$el.find("div.ays-survey-section[data-id=" + whereToJump + "]").data("pageNumber"); 1401 } 1402 } 1403 } 1404 }else if(questionType === 'nps' && checkedElement.length > 0){ 1405 var checkedNpsValue = checkedElement.val(); 1406 if ( typeof logicJumpQuestionNPSGoTo[questionId] != 'undefined' ) { 1407 $.each(logicJumpQuestionNPSGoTo[questionId], function (index, hello){ 1408 if(checkedNpsValue){ 1409 if($.inArray( checkedNpsValue, hello.selected_options ) !== -1){ 1410 if( hello.go_to_section !== null ){ 1411 whereToJump = hello.go_to_section; 1412 if (whereToJump !== -1 && whereToJump !== -2) { 1413 if( _this.$el.find("div.ays-survey-section[data-id=" + whereToJump + "]").length > 0 ){ 1414 currentPage = _this.$el.find("div.ays-survey-section[data-id=" + whereToJump + "]").data("pageNumber"); 1415 } else { 1416 whereToJump = -1; 1417 } 1418 } 1419 return false; 1420 } 1421 } 1422 else{ 1423 if( hello.otherwise !== null ){ 1424 whereToJump = hello.otherwise; 1425 if (whereToJump !== -1 && whereToJump !== -2) { 1426 if(_this.$el.find("div.ays-survey-section[data-id=" + whereToJump + "]").length > 0){ 1427 currentPage = _this.$el.find("div.ays-survey-section[data-id=" + whereToJump + "]").data("pageNumber"); 1428 } else { 1429 whereToJump = -1; 1430 return false; 1431 } 1432 } 1433 } 1434 } 1435 } 1436 }); 1437 } 1438 }else { 1439 var checkedValue = checkedElement.val(); 1440 var otherAnswerCheckedValue = checkedElement.data('logicjump'); 1441 if( typeof logicJumpQuestionsAnswersGoTo[ checkedValue ] != 'undefined' ){ 1442 whereToJump = logicJumpQuestionsAnswersGoTo[ checkedValue ]; 1443 if( whereToJump != -1 ){ 1444 currentPage = _this.$el.find("div.ays-survey-section[data-id=" + whereToJump + "]").data("pageNumber"); 1445 } 1446 } 1447 1448 if( typeof logicJumpQuestionsGoTo[ otherAnswerCheckedValue ] != 'undefined' ) { 1449 whereToJump = logicJumpQuestionsGoTo[ otherAnswerCheckedValue ]; 1450 if( whereToJump != -1 ) { 1451 currentPage = _this.$el.find("div.ays-survey-section[data-id=" + whereToJump + "]").data("pageNumber"); 1452 } 1453 } 1454 } 1455 } 1456 }); 1457 1458 var whatToDo = null; 1459 if( whereToJump == thisSectionId ){ 1460 whatToDo = 'go_to_same_section'; 1461 }else if( whereToJump == -1 ){ 1462 whatToDo = null; 1463 }else if( whereToJump == -2 ){ 1464 whatToDo = 'submit_form'; 1465 }else{ 1466 whatToDo = 'go_to_section'; 1467 } 1468 1469 if( whereToJump === null ){ 1470 whatToDo = null; 1471 } 1472 1473 if( isNaN( whereToJump ) ){ 1474 whatToDo = null; 1475 } 1476 1477 var whatToDoSectionNext = null; 1478 var whereToJumpSectionNext = parseInt( logicJumpSectionsGoTo[ nextSectionId ] ); 1479 if( whereToJumpSectionNext == nextSectionId ){ 1480 whatToDoSectionNext = 'go_to_same_section'; 1481 }else if( whereToJumpSectionNext == -1 ){ 1482 whatToDoSectionNext = 'go_to_next_section'; 1483 }else if( whereToJumpSectionNext == -2 ){ 1484 whatToDoSectionNext = 'submit_form'; 1485 }else{ 1486 whatToDoSectionNext = 'go_to_section'; 1487 } 1488 1489 if( $.isEmptyObject( logicJumpSectionsGoTo ) ){ 1490 whatToDoSectionNext = 'go_to_next_section'; 1491 } 1492 1493 if( isNaN( whereToJumpSectionNext ) ){ 1494 whatToDoSectionNext = 'go_to_next_section'; 1495 } 1496 1497 if( ( whatToDoSectionNext == 'go_to_next_section' ) && _this.$el.find("div.ays-survey-section[data-id]").length - 1 == _this.$el.find("div.ays-survey-section[data-id]").index( nextSection ) ){ 1498 whatToDoSectionNext = null; 1499 } 1500 1501 if( whatToDoSectionNext == 'submit_form' || whatToDoSectionNext == null ){ 1502 section.next().find('.' + _this.htmlClassPrefix + 'section-button.' + _this.htmlClassPrefix + 'finish-button').removeClass( _this.htmlClassPrefix + 'display-none' ); 1503 section.next().find('.' + _this.htmlClassPrefix + 'section-button.' + _this.htmlClassPrefix + 'next-button').addClass( _this.htmlClassPrefix + 'display-none' ); 1504 } 1505 1506 if( whatToDo !== null ){ 1507 if( whatToDo == 'submit_form' ){ 1508 section.find('input.' + _this.htmlClassPrefix + 'finish-button').trigger('click'); 1509 }else if( whatToDo == 'go_to_section' ){ 1510 _this.activeStep($(e.target), 'next', whereToJump); 1511 _this.aysAnimateStep('fade', _this.current_fs, _this.next_fs); 1512 1513 $.each( _this.logicJumpQuestionSteps, function(){ 1514 this.active = false; 1515 }); 1516 1517 _this.logicJumpQuestionSteps[ whereToJump ] = { 1518 section: +whereToJump, 1519 prevSection: thisSectionId, 1520 active: true 1521 }; 1522 1523 i
1523f( _this.$el.parents('.ays-survey-popup-survey-window').length > 0 ){ 1524 _this.goToTop( _this.next_fs, 'start'); 1525 }else{ 1526 _this.goTo(); 1527 } 1528 }else if( whatToDo == 'go_to_same_section' ){ 1529 _this.activeStep($(e.target), 'next', whereToJump); 1530 _this.aysAnimateStep('fade', _this.current_fs, _this.next_fs, 200); 1531 1532 if( _this.$el.parents('.ays-survey-popup-survey-window').length > 0 ){ 1533 _this.goToTop( _this.next_fs, 'start'); 1534 }else{ 1535 _this.goTo(); 1536 } 1537 } 1538 }else{ 1539 var whatToDoSection = null; 1540 var whereToJumpSection = parseInt( logicJumpSectionsGoTo[ thisSectionId ] ); 1541 if( whereToJumpSection == thisSectionId ){ 1542 whatToDoSection = 'go_to_same_section'; 1543 }else if( whereToJumpSection == -1 ){ 1544 whatToDoSection = null; 1545 }else if( whereToJumpSection == -2 ){ 1546 whatToDoSection = 'submit_form'; 1547 }else{ 1548 whatToDoSection = 'go_to_section'; 1549 } 1550 1551 if( $.isEmptyObject( logicJumpSectionsGoTo ) ){ 1552 whereToJumpSection = null; 1553 } 1554 1555 if( isNaN( whereToJumpSection ) ){ 1556 whereToJumpSection = null; 1557 } 1558 1559 var whatToDoSectionNext = null; 1560 var whereToJumpSectionNext = parseInt( logicJumpSectionsGoTo[ nextSectionId ] ); 1561 if( whereToJumpSectionNext == nextSectionId ){ 1562 whatToDoSectionNext = 'go_to_same_section'; 1563 }else if( whereToJumpSectionNext == -1 ){ 1564 whatToDoSectionNext = 'go_to_next_section'; 1565 if( whereToJumpSection != -1 && whereToJumpSection != -2 && whereToJumpSection !== null && whereToJumpSection != thisSectionId ) { 1566 nextSection = _this.$el.find("div.ays-survey-section[data-id='" + whereToJumpSection + "']"); 1567 } 1568 }else if( whereToJumpSectionNext == -2 ){ 1569 whatToDoSectionNext = 'submit_form'; 1570 }else{ 1571 whatToDoSectionNext = 'go_to_section'; 1572 if( whereToJumpSection != -1 && whereToJumpSection != -2 && whereToJumpSection !== null && whereToJumpSection != thisSectionId ) { 1573 nextSection = _this.$el.find("div.ays-survey-section[data-id='" + whereToJumpSection + "']"); 1574 } 1575 } 1576 1577 if( $.isEmptyObject( logicJumpSectionsGoTo ) ){ 1578 whatToDoSectionNext = 'go_to_next_section'; 1579 } 1580 1581 if( isNaN( whereToJumpSectionNext ) ){ 1582 whatToDoSectionNext = 'go_to_next_section'; 1583 } 1584 1585 if( ( whatToDoSectionNext == 'go_to_next_section' ) && _this.$el.find("div.ays-survey-section[data-id]").length - 1 == _this.$el.find("div.ays-survey-section[data-id]").index( nextSection ) ){ 1586 whatToDoSectionNext = null; 1587 } 1588 1589 if( whatToDoSectionNext == 'submit_form' || whatToDoSectionNext == null ){ 1590 nextSection.find('.' + _this.htmlClassPrefix + 'section-button.' + _this.htmlClassPrefix + 'finish-button').removeClass( _this.htmlClassPrefix + 'display-none' ); 1591 nextSection.find('.' + _this.htmlClassPrefix + 'section-button.' + _this.htmlClassPrefix + 'next-button').addClass( _this.htmlClassPrefix + 'display-none' ); 1592 } 1593 1594 if( whatToDoSection !== null ){ 1595 if( whatToDoSection == 'submit_form' ){ 1596 section.find('input.' + _this.htmlClassPrefix + 'finish-button').trigger('click'); 1597 }else if( whatToDoSection == 'go_to_section' ){ 1598 _this.activeStep($(e.target), 'next', whereToJumpSection); 1599 _this.aysAnimateStep('fade', _this.current_fs, _this.next_fs); 1600 1601 $.each( _this.logicJumpSectionSteps, function(){ 1602 this.active = false; 1603 }); 1604 1605 _this.logicJumpSectionSteps[ whereToJumpSection ] = { 1606 section: whereToJumpSection, 1607 prevSection: thisSectionId, 1608 active: true 1609 }; 1610 1611 currentPage = _this.$el.find("div.ays-survey-section[data-id=" + whereToJumpSection + "]").data("pageNumber"); 1612 1613 if( _this.$el.parents('.ays-survey-popup-survey-window').length > 0 ){ 1614 _this.goToTop( _this.next_fs, 'start'); 1615 }else{ 1616 _this.goTo(); 1617 } 1618 1619 }else if( whatToDoSection == 'go_to_same_section' ){ 1620 _this.activeStep($(e.target), 'next', whereToJumpSection); 1621 _this.aysAnimateStep('fade', _this.current_fs, _this.next_fs, 200); 1622 1623 if( _this.$el.parents('.ays-survey-popup-survey-window').length > 0 ){ 1624 _this.goToTop( _this.next_fs, 'start'); 1625 }else{ 1626 _this.goTo(); 1627 } 1628 } 1629 }else{ 1630 // _this.actionLiveProgressBar($(e.target), 'next'); 1631 _this.activeStep($(e.target), 'next', null); 1632 1633 // _this.validateButtonsVisibility(); 1634 1635 if( thisSectionId ){ 1636 if( _this.logicJumpQuestionSteps && _this.logicJumpQuestionSteps[ nextSectionId ] && typeof _this.logicJumpQuestionSteps[ nextSectionId ] != "undefined" ){ 1637 _this.logicJumpQuestionSteps[ nextSectionId ] = { 1638 section: +thisSectionId, 1639 prevSection: null, 1640 active: true 1641 }; 1642 } 1643 } 1644 1645 _this.aysAnimateStep('fade', _this.current_fs, _this.next_fs); 1646 1647 if( _this.$el.parents('.ays-survey-popup-survey-window').length > 0 ){ 1648 _this.goToTop( _this.next_fs, 'start'); 1649 }else{ 1650 _this.goTo(); 1651 } 1652 } 1653 } 1654 1655 if( _this.dbOptions.survey_cover_only_first_section && currentPage == 2){
1656 _this.$el.find(".ays-survey-cover-photo-title-wrap").css('height' , 'auto'); 1657 _this.$el.find(".ays-survey-cover-photo-title-wrap").css('background-image' , 'unset'); 1658 } 1659 1660 var pageCount = _this.$el.find("div.ays-survey-section[data-id]").length; 1661 var fillWidth = ( currentPage * 100 ) / pageCount; 1662 _this.$el.find("div.ays-survey-live-bar-fill").animate({ 'width': fillWidth+"%" }, 1000); 1663 _this.$el.find("span.ays-survey-live-bar-changeable-text").text(currentPage); 1664 _this.current_fs?.find('.' + _this.htmlClassPrefix + 'next-button').removeClass('display_none_important'); 1665 }else{ 1666 1667 } 1668 }); 1669 1670 _this.$el.on('click', '.' + _this.htmlClassPrefix + 'prev-button', function (e){ 1671 _this.confirmBeforeUnload = true; 1672 e.preventDefault(); 1673 1674 var section = $(this).parents('.ays-survey-section'); 1675 var thisSectionId = section.data('id'); 1676 1677 var currentPage = _this.$el.find("div.ays-survey-section.active-section").data("pageNumber") - 1; 1678 1679 if (_this.animating) return false; 1680 _this.animating = true; 1681 if( _this.dbOptions.survey_cover_only_first_section && currentPage == 1){ 1682 _this.$el.find(".ays-survey-cover-photo-title-wrap").css('height' , _this.dbOptions.survey_cover_photo_height); 1683 _this.$el.find(".ays-survey-cover-photo-title-wrap").css('background-image' , "url(" + (_this.dbOptions.survey_cover_photo) + ")"); 1684 } 1685 1686 //if( _this.checkForm( $( e.target ) ) ){ 1687 // _this.actionLiveProgressBar($(e.target), 'next'); 1688 // _this.activeStep($(e.target), 'prev'); 1689 1690 var logicJumpPrevQuestion = -1; 1691 $.each( _this.logicJumpQuestionSteps, function(){ 1692 if( this.section === thisSectionId ){ 1693 logicJumpPrevQuestion = this.prevSection; 1694 } 1695 }); 1696 1697 if( logicJumpPrevQuestion !== -1 ){ 1698 currentPage = _this.$el.find("div.ays-survey-section[data-id=" + logicJumpPrevQuestion + "]").data("pageNumber"); 1699 1700 _this.activeStep($(e.target), 'prev', logicJumpPrevQuestion ); 1701 _this.aysAnimateStep('fade', _this.current_fs, _this.next_fs); 1702 1703 $.each( _this.logicJumpQuestionSteps, function(){ 1704 this.active = false; 1705 }); 1706 1707 if( typeof _this.logicJumpQuestionSteps[ logicJumpPrevQuestion ] != 'undefined' ){ 1708 _this.logicJumpQuestionSteps[ logicJumpPrevQuestion ].active = true; 1709 } 1710 1711 if( _this.$el.parents('.ays-survey-popup-survey-window').length > 0 ){ 1712 _this.goToTop( _this.next_fs, 'start'); 1713 }else{ 1714 _this.goTo(); 1715 } 1716 }else{ 1717 1718 var logicJumpPrevSection = -1; 1719 $.each( _this.logicJumpSectionSteps, function(){ 1720 if( this.section === thisSectionId ){ 1721 logicJumpPrevSection = this.prevSection; 1722 } 1723 }); 1724 1725 if( logicJumpPrevSection !== -1 ){ 1726 currentPage = _this.$el.find("div.ays-survey-section[data-id=" + logicJumpPrevSection + "]").data("pageNumber"); 1727 1728 $.each( _this.logicJumpSectionSteps, function(){ 1729 this.active = false; 1730 }); 1731 1732 if( typeof _this.logicJumpSectionSteps[ logicJumpPrevSection ] != 'undefined' ){ 1733 _this.logicJumpSectionSteps[ logicJumpPrevSection ].active = true; 1734 } 1735 1736 _this.activeStep( $(e.target), 'prev', logicJumpPrevSection ); 1737 _this.aysAnimateStep('fade', _this.current_fs, _this.next_fs); 1738 1739 if( _this.$el.parents('.ays-survey-popup-survey-window').length > 0 ){ 1740 _this.goToTop( _this.next_fs, 'start'); 1741 }else{ 1742 _this.goTo(); 1743 } 1744 }else{ 1745 // _this.validateButtonsVisibility(); 1746 1747 // _this.next_fs.find('.ays-text-input').trigger( "focus" ); 1748 1749 // _this.aysAnimateStep(_this.$el.data('questEffect'), _this.current_fs, _this.next_fs); 1750 1751 _this.activeStep( $(e.target), 'prev', null ); 1752 _this.aysAnimateStep('fade', _this.current_fs, _this.next_fs); 1753 1754 if( _this.$el.parents('.ays-survey-popup-survey-window').length > 0 ){ 1755 _this.goToTop( _this.next_fs, 'start'); 1756 }else{ 1757 _this.goTo(); 1758 } 1759 } 1760 } 1761 1762 var pageCount = _this.$el.find("div.ays-survey-section[data-id]").length; 1763 var fillWidth = ( currentPage * 100 ) / pageCount; 1764 _this.$el.find("div.ays-survey-live-bar-fill").animate({ 'width': fillWidth+"%" }, 500); 1765 _this.$el.find("span.ays-survey-live-bar-changeable-text").text( currentPage ); 1766 // _this.goToTop(); 1767 //}else{ 1768 1769 //} 1770 }); 1771 1772 }; 1773 1774 AysSurveyPlugin.prototype.aysFinish = function() { 1775 var _this = this; 1776 var fButtonSelector = 'input.' + _this.htmlClassPrefix + 'finish-button'; 1777 1778 _this.$el.on('click', fButtonSelector, function (e) { 1779 e.preventDefault(); 1780 1781 var form = _this.$el.find('form'); 1782 1783 if(_this.showAllSections.length > 0 && ! _this.checkFormAllSections()){ 1784 return ; 1785 } 1786 1787 var surveyRecaptcha = _this.dbOptions.options.enable_recaptcha && _this.dbOptions.options.enable_recaptcha == "on" ? true : false; 1788 1789 var formCaptchaValidation = null; 1790 if( surveyRecaptcha ){ 1791 if( form.attr('data-recaptcha-validate') ){ 1792 formCaptchaValidation = form.attr('data-recaptcha-validate') == 'true' ? true : false; 1793 } 1794 } 1795 1796 if( surveyRecaptcha && formCaptchaValidation === null && _this.checkForm( $( e.target ) )){ 1797 var cEvent = new CustomEvent('afterSurveySubmission', { 1798 detail: { 1799 _this: _this, 1800 thisButton: $( e.target ) 1801 } 1802 }); 1803 form.get(0).dispatchEvent(cEvent); 1804 } 1805 1806 if( surveyRecaptcha === false ){ 1807 formCaptchaValidation = true; 1808 } 1809 1810 _this.confirmBeforeUnload = false; 1811 _this.endDate = _this.GetFullDateTime(); 1812 1813 if( _this.dbOptions.survey_edit_previous_submission ){ 1814 var editPreviousSubmissionButton = _this.$el.find('.ays-survey-edit-previous-submission-box'); 1815 if( editPreviousSubmissionButton.length > 0 ){ 1816 editPreviousSubmissionButton.remove(); 1817 } 1818 } 1819 // if(_this.$el.find('.ays_music_sound').length !== 0){ 1820 // _this.$el.find('.ays_music_sound').fadeOut(); 1821 // setTimeout(function() { 1822 // audioVolumeOut(_this.$el.find('.ays_quiz_music').get(0)); 1823 // },4000); 1824 // setTimeout(function() { 1825 // _this.$el.find('.ays_quiz_music').get(0).pause(); 1826 // },6000); 1827 // } 1828 // if(_this.$el.find('audio').length > 0){ 1829 // _this.$el.find('audio').each(function(e, el){ 1830 // el.pause(); 1831 // }); 1832 // } 1833 // if(_this.$el.find('video').length > 0){ 1834 // _this.$el.find('video').each(function(e, el){ 1835 // el.pause(); 1836 // }); 1837 // } 1838 // _this.$el.find('.ays-live-bar-wrap').addClass('bounceOut'); 1839 // setTimeout(function () { 1840 // _this.$el.find('.ays-live-bar-wrap').css('display','none'); 1841 // },300); 1842 1843 if( _this.checkForm( $( e.target ) ) && formCaptchaValidation === true ){ 1844 1845 1846 // var next_sibilings_count = $(this).parents('form').find('.ays_question_count_per_page').val(); 1847 // _this.$el.find('input[name^="ays_questions"]').attr('disabled', false); 1848 // _this.$el.find('div.ays-quiz-timer').slideUp(500); 1849 // if(_this.$el.find('div.ays-quiz-after-timer').hasClass('empty_after_timer_text')){ 1850 // _this.$el.find('div.ays-quiz-timer').parent().slideUp(500); 1851 // } 1852 1853 // _this.activeStep($(this), 'next'); 1854 1855 // _this.next_fs = $(this).parents('.step').next(); 1856 // _this.current_fs = $(this).parents('.step'); 1857 // _this.next_fs.addClass('active-step'); 1858 // _this.current_fs.removeClass('active-step'); 1859 1860 // var form = _this.$el.find('form'); 1861 1862 var data = form.serializeFormJSON(); 1863 // var questionsIds = data.ays_quiz_questions.split(','); 1864 1865 // for(var i = 0; i < questionsIds.length; i++){ 1866 // if(! data['ays_questions[ays-question-'+questionsIds[i]+']']){ 1867 // data['ays_questions[ays-question-'+questionsIds[i]+']'] = ""; 1868 // } 1869 // } 1870 var surveyCurrentPageLink = form.find('input[name="ays-survey-curent_page_link"]').val(); 1871 data.action = _this.ajaxAction; 1872 data.function = 'ays_finish_survey'; 1873 data.start_date = _this.startDate; 1874 data.end_date = _this.endDate; 1875 data.unique_id = _this.uniqueId; 1876 data.survey_current_page_link = surveyCurrentPageLink; 1877 1878 var sections = _this.$el.find('.' + _this.htmlClassPrefix + 'sections > .' + _this.htmlClassPrefix + 'section:not(:last-child)'); 1879 // sections.hide(100); 1880 setTimeout( function(){ 1881 sections.remove(); 1882 }, 100 ); 1883 1884 _this.$el.find('.' + _this.htmlClassPrefix + 'sections > .' + _this.htmlClassPrefix + 'section.' + _this.htmlClassPrefix + 'results-content').show(150); 1885 1886 var aysQuizLoader = form.find('div[data-role="loader"]'); 1887 aysQuizLoader.addClass(aysQuizLoader.data('class')); 1888 aysQuizLoader.removeClass('ays-loader'); 1889 1890 setTimeout(function () { 1891 _this.sendSurveyData(data, $(e.target)); 1892 }, 2000); 1893 1894 if(!_this.dbOptions.survey_enable_chat_mode){ 1895 if( _this.$el.parents('.ays-survey-popup-survey-window').length > 0 ){ 1896 _this.goToTop( _this.next_fs, 'start'); 1897 }else{ 1898 _this.goTo(); 1899 } 1900 } 1901 // if (parseInt(next_sibilings_count) > 0 && ($(this).parents('.step').attr('data-question-id') || $(this).parents('.step').next().attr('data-question-id'))) { 1902 // current_fs = $(this).parents('form').find('div[data-question-id]'); 1903 // } 1904 1905 // aysAnimateStep(ays_quiz_container.data('questEffect'), current_fs, next_fs); 1906 } 1907 }); 1908 } 1909 1910 AysSurveyPlugin.prototype.validateButtonsVisibility = function() { 1911 var _this = this; 1912 var nextQuestionType = _this.next_fs.find('input[name^="ays_questions"]').attr('type'); 1913 var buttonsDiv = _this.next_fs.find('.ays_buttons_div'); 1914 var enableArrows = _this.$el.find(".ays_qm_enable_arrows").val(); 1915 1916 if(_this.dbOptions.enable_arrows){ 1917 enableArrows = _this.dbOptions.enable_arrows == 'on' ? true : false; 1918 }else{ 1919 enableArrows = parseInt(enableArrows) == 1 ? true : false; 1920 } 1921 var nextArrowIsDisabled = buttonsDiv.find('i.ays_next_arrow').hasClass('ays_display_none'); 1922 var nextButtonIsDisabled = buttonsDiv.find('input.ays_next').hasClass('ays_display_none'); 1923 1924 if(_this.next_fs.find('textarea[name^="ays_questions"]').attr('type')==='text' && nextArrowIsDisabled && nextButtonIsDisabled){ 1925 buttonsDiv.find('input.ays_next').removeClass('ays_display_none'); 1926 } 1927 if(_this.next_fs.find('textarea[name^="ays_questions"]').attr('type')==='text' && enableArrows){ 1928 buttonsDiv.find('input.ays_next').addClass('ays_display_none'); 1929 buttonsDiv.find('i.ays_next_arrow').removeClass('ays_display_none'); 1930 } 1931 1932 if(nextQuestionType === 'checkbox' && nextArrowIsDisabled && nextButtonIsDisabled){ 1933 buttonsDiv.find('input.ays_next').removeClass('ays_display_none'); 1934 } 1935 if(nextQuestionType === 'checkbox' && enableArrows){ 1936 buttonsDiv.find('input.ays_next').addClass('ays_display_none'); 1937 buttonsDiv.find('i.ays_next_arrow').removeClass('ays_display_none'); 1938 } 1939 1940 if(nextQuestionType === 'number' && nextArrowIsDisabled && nextButtonIsDisabled){ 1941 buttonsDiv.find('input.ays_next').removeClass('ays_display_none'); 1942 } 1943 if(nextQuestionType === 'number' && enableArrows){ 1944 buttonsDiv.find('input.ays_next').addClass('ays_display_none'); 1945 buttonsDiv.find('i.ays_next_arrow').removeClass('ays_display_none'); 1946 } 1947 1948 if(nextQuestionType === 'text' && nextArrowIsDisabled && nextButtonIsDisabled){ 1949 next_fs.find('.ays_buttons_div').find('input.ays_next').removeClass('ays_display_none'); 1950 } 1951 if(nextQuestionType === 'text' && enableArrows){ 1952 next_fs.find('.ays_buttons_div').find('input.ays_next').addClass('ays_display_none'); 1953 next_fs.find('.ays_buttons_div').find('i.ays_next_arrow').removeClass('ays_display_none'); 1954 } 1955 1956 if(nextQuestionType === 'date' && nextArrowIsDisabled && nextButtonIsDisabled){ 1957 buttonsDiv.find('input.ays_next').removeClass('ays_display_none'); 1958 } 1959 if(nextQuestionType === 'date' && enableArrows){ 1960 buttonsDiv.find('input.ays_next').addClass('ays_display_none');
1961 buttonsDiv.find('.ays_next_arrow').removeClass('ays_display_none'); 1962 } 1963 1964 var isRequiredQuestion = (_this.dbOptions.make_questions_required && _this.dbOptions.make_questions_required == "on") ? true : false; 1965 if(isRequiredQuestion === true){ 1966 if(_this.next_fs.find('.information_form').length === 0){ 1967 if(enableArrows){ 1968 buttonsDiv.find('i.ays_next_arrow').attr('disabled', 'disabled'); 1969 }else{ 1970 buttonsDiv.find('input.ays_next').attr('disabled', 'disabled'); 1971 } 1972 } 1973 } 1974 } 1975 1976 AysSurveyPlugin.prototype.goToTop = function( el, position = "center" ) { 1977 if(typeof el !== 'undefined'){ 1978 el.get(0).scrollIntoView({ 1979 block: position, 1980 behavior: "smooth" 1981 }); 1982 } 1983 1984 } 1985 1986 AysSurveyPlugin.prototype.goTo = function() { 1987 var surveyAnimationTop; 1988 var mobileOffset = 0; var checkmobile = $('*[data-bt_bb_screen_resolution]').attr('data-bt_bb_screen_resolution'); 1989 if(this.dbOptions != 'undefined'){ 1990 surveyAnimationTop = (this.dbOptions.survey_animation_top && this.dbOptions.survey_animation_top != 0) ? parseInt(this.dbOptions.survey_animation_top) : 200; 1991 }else{ 1992 surveyAnimationTop = 200; 1993 } 1994 if(checkmobile == 'sm'){ mobileOffset = 1340; }; if(checkmobile == 'xs'){ mobileOffset = 1150; }; if (mobileOffset != 0){ mobileOffset = mobileOffset - this.$el.offset().top; } 1995 if(this.dbOptions.survey_enable_animation_top){ 1996 $('html, body').animate({ 1997 scrollTop: this.$el.offset().top + mobileOffset - surveyAnimationTop + 'px' 1998 }, 'fast'); 1999 } 2000 2001 return this; // for chaining... 2002 } 2003 2004 AysSurveyPlugin.prototype.keydown = function(){ 2005 var _this = this, $this = _this.$el; 2006 $this.find('input').on('focus', function () { 2007 $(window).on('keydown', function (event) { 2008 if (event.keyCode === 13) { 2009 return false; 2010 } 2011 }); 2012 }); 2013 2014 $this.find('input').on('blur', function () { 2015 $(window).off('keydown'); 2016 }); 2017 } 2018 2019 AysSurveyPlugin.prototype.aysAnimateStep = function(animation, current_fs, next_fs, duration){ 2020 var _this = this; 2021 if(typeof duration == "undefined"){ 2022 duration = 500; 2023 } 2024 2025 if(typeof next_fs !== "undefined"){ 2026 switch(animation){ 2027 case "lswing": 2028 current_fs.parents('.ays-questions-container').css({ 2029 perspective: '800px', 2030 }); 2031 2032 current_fs.addClass('swing-out-right-bck'); 2033 current_fs.css({ 2034 'pointer-events': 'none' 2035 }); 2036 setTimeout(function(){ 2037 current_fs.css({ 2038 'position': 'absolute', 2039 }); 2040 next_fs.css('display', 'flex'); 2041 next_fs.addClass('swing-in-left-fwd'); 2042 },400); 2043 setTimeout(function(){ 2044 current_fs.hide(); 2045 current_fs.css({ 2046 'pointer-events': 'auto', 2047 'position': 'static' 2048 }); 2049 next_fs.css({ 2050 'position':'relative', 2051 'pointer-events': 'auto' 2052 }); 2053 current_fs.removeClass('swing-out-right-bck'); 2054 next_fs.removeClass('swing-in-left-fwd'); 2055 _this.animating = false; 2056 },1000); 2057 break; 2058 case "rswing": 2059 current_fs.parents('.ays-questions-container').css({ 2060 perspective: '800px', 2061 }); 2062 2063 current_fs.addClass('swing-out-left-bck'); 2064 current_fs.css({ 2065 'pointer-events': 'none' 2066 }); 2067 setTimeout(function(){ 2068 current_fs.css({ 2069 'position': 'absolute', 2070 }); 2071 next_fs.css('display', 'flex'); 2072 next_fs.addClass('swing-in-right-fwd'); 2073 },400); 2074 setTimeout(function(){ 2075 current_fs.hide(); 2076 current_fs.css({ 2077 'pointer-events': 'auto', 2078 'position': 'static' 2079 }); 2080 next_fs.css({ 2081 'position':'relative', 2082 'pointer-events': 'auto' 2083 }); 2084 current_fs.removeClass('swing-out-left-bck'); 2085 next_fs.removeClass('swing-in-right-fwd'); 2086 _this.animating = false; 2087 },1000); 2088 break; 2089 case "shake": 2090 current_fs.animate({opacity: 0}, { 2091 step: function (now, mx) { 2092 _this.scale = 1 - (1 - now) * 0.2; 2093 _this.left = (now * 50) + "%"; 2094 _this.opacity = 1 - now; 2095 current_fs.css({ 2096 'transform': 'scale(' + _this.scale + ')', 2097 'position': 'absolute', 2098 'top':0, 2099 'opacity': 1, 2100 'pointer-events': 'none' 2101 }); 2102 next_fs.css({ 2103 'left': _this.left, 2104 'opacity': _this.opacity, 2105 'display':'flex', 2106 'position':'relative', 2107 'pointer-events': 'none' 2108 }); 2109 },
2110 duration: 800, 2111 complete: function () { 2112 current_fs.hide(); 2113 current_fs.css({ 2114 'pointer-events': 'auto', 2115 'opacity': 1, 2116 'position': 'static' 2117 }); 2118 next_fs.css({ 2119 'display':'flex', 2120 'position':'relative', 2121 'transform':'scale(1)', 2122 'opacity': 1, 2123 'pointer-events': 'auto' 2124 }); 2125 _this.animating = false; 2126 }, 2127 easing: 'easeInOutBack' 2128 }); 2129 break; 2130 case "fade": 2131 current_fs.animate({opacity: 0}, { 2132 step: function (now, mx) { 2133 _this.opacity = 1 - now; 2134 current_fs.css({ 2135 'position': 'absolute', 2136 'width': '100%', 2137 'pointer-events': 'none' 2138 }); 2139 next_fs.css({ 2140 'opacity': _this.opacity, 2141 'position':'relative', 2142 'display':'block', 2143 'pointer-events': 'none' 2144 }); 2145 }, 2146 duration: duration, 2147 complete: function () { 2148 current_fs.hide(); 2149 current_fs.css({ 2150 'pointer-events': 'auto', 2151 'position': 'static' 2152 }); 2153 next_fs.css({ 2154 'display':'block', 2155 'position':'relative', 2156 'opacity': 1, 2157 'pointer-events': 'auto' 2158 }); 2159 _this.animating = false; 2160 } 2161 }); 2162 break; 2163 default: 2164 current_fs.animate({}, { 2165 step: function (now, mx) { 2166 current_fs.css({ 2167 'pointer-events': 'none' 2168 }); 2169 next_fs.css({ 2170 'position':'relative', 2171 'pointer-events': 'none' 2172 }); 2173 }, 2174 duration: 0, 2175 complete: function () { 2176 current_fs.hide(); 2177 current_fs.css({ 2178 'pointer-events': 'auto' 2179 }); 2180 next_fs.css({ 2181 'display':'block', 2182 'position':'relative', 2183 'transform':'scale(1)', 2184 'pointer-events': 'auto' 2185 }); 2186 _this.animating = false; 2187 } 2188 }); 2189 break; 2190 } 2191 }else{ 2192 switch(animation){ 2193 case "lswing": 2194 current_fs.parents('.ays-questions-container').css({ 2195 perspective: '800px', 2196 }); 2197 current_fs.addClass('swing-out-right-bck'); 2198 current_fs.css({ 2199 'pointer-events': 'none' 2200 }); 2201 setTimeout(function(){ 2202 current_fs.css({ 2203 'position': 'absolute', 2204 }); 2205 },400); 2206 setTimeout(function(){ 2207 current_fs.hide(); 2208 current_fs.css({ 2209 'pointer-events': 'auto', 2210 'position': 'static' 2211 }); 2212 current_fs.removeClass('swing-out-right-bck'); 2213 _this.animating = false; 2214 },1000); 2215 break; 2216 case "rswing": 2217 current_fs.parents('.ays-questions-container').css({ 2218 perspective: '800px', 2219 }); 2220 current_fs.addClass('swing-out-left-bck'); 2221 current_fs.css({ 2222 'pointer-events': 'none' 2223 }); 2224 setTimeout(function(){ 2225 current_fs.css({ 2226 'position': 'absolute', 2227 }); 2228 },400); 2229 setTimeout(function(){ 2230 current_fs.hide(); 2231 current_fs.css({ 2232 'pointer-events': 'auto', 2233 'position': 'static' 2234 }); 2235 current_fs.removeClass('swing-out-left-bck'); 2236 _this.animating = false; 2237 },1000); 2238 case "shake": 2239 current_fs.animate({opacity: 0}, { 2240 step: function (now, mx) { 2241 _this.scale = 1 - (1 - now) * 0.2; 2242 _this.left = (now * 50) + "%"; 2243 _this.opacity = 1 - now; 2244 current_fs.css({ 2245 'transform': 'scale(' + _this.scale + ')', 2246 }); 2247 },
2248 duration: 800, 2249 complete: function () { 2250 current_fs.hide(); 2251 _this.animating = false; 2252 }, 2253 easing: 'easeInOutBack' 2254 }); 2255 break; 2256 case "fade": 2257 current_fs.animate({opacity: 0}, { 2258 step: function (now, mx) { 2259 _this.opacity = 1 - now; 2260 }, 2261 duration: 500, 2262 complete: function () { 2263 current_fs.hide(); 2264 _this.animating = false; 2265 }, 2266 easing: 'easeInOutBack' 2267 }); 2268 break; 2269 default: 2270 current_fs.animate({}, { 2271 step: function (now, mx) { 2272 2273 }, 2274 duration: 0, 2275 complete: function () { 2276 current_fs.hide(); 2277 _this.animating = false; 2278 } 2279 }); 2280 break; 2281 } 2282 } 2283 } 2284 2285 AysSurveyPlugin.prototype.activeStep = function(button, action, where) { 2286 var _this = this; 2287 _this.current_fs = button.parents('.' + _this.htmlClassPrefix + 'section'); 2288 if(action == 'next'){ 2289 if( where !== null ){ 2290 _this.next_fs = _this.$el.find( '.' + _this.htmlClassPrefix + 'section[data-id="'+ where +'"]' ); 2291 }else{ 2292 _this.next_fs = button.parents('.' + _this.htmlClassPrefix + 'section').next(); 2293 } 2294 } 2295 if(action == 'prev'){ 2296 if( where !== null ){ 2297 _this.next_fs = _this.$el.find( '.' + _this.htmlClassPrefix + 'section[data-id="'+ where +'"]' ); 2298 }else{ 2299 _this.next_fs = button.parents('.' + _this.htmlClassPrefix + 'section').prev(); 2300 } 2301 } 2302 _this.current_fs.removeClass('active-section'); 2303 _this.next_fs.addClass('active-section'); 2304 } 2305 2306 AysSurveyPlugin.prototype.startLiveProgressBar = function(button) { 2307 var _this = this; 2308 if (button.parents('.step').next().find('.information_form').length === 0 ){ 2309 var questions_count = _this.$el.find('form').find('div[data-question-id]').length; 2310 var curent_number = _this.$el.find('form').find('div[data-question-id]').index(button.parents('div[data-question-id]')) + 1; 2311 var final_width = ((curent_number+1) / questions_count * 100) + "%"; 2312 if(button.parents('.ays-quiz-container').find('.ays-live-bar-percent').hasClass('ays-live-bar-count')){ 2313 button.parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(curent_number+1)); 2314 }else{ 2315 button.parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(final_width)); 2316 } 2317 button.parents('.ays-quiz-container').find('.ays-live-bar-fill').animate({'width': final_width}, 500); 2318 } 2319 } 2320 2321 AysSurveyPlugin.prototype.actionLiveProgressBar = function(button, action) { 2322 var _this = this; 2323 var questions_count = _this.$el.find('form').find('div[data-question-id]').length; 2324 var curent_number; 2325 if(action == 'next'){c 2326 curent_number = _this.$el.find('form').find('div[data-question-id]').index(button.parents('div[data-question-id]')) + 1; 2327 } 2328 if(action == 'prev'){ 2329 curent_number = _this.$el.find('form').find('div[data-question-id]').index(button.parents('div[data-question-id]')) - 1; 2330 } 2331 if(curent_number != questions_count){ 2332 if((button.hasClass('ays_finish')) == false){ 2333 if (!($(this).hasClass('start_button'))) { 2334 var current_width = button.parents('.ays-quiz-container').find('.ays-live-bar-fill').width(); 2335 var final_width = ((curent_number+1) / questions_count * 100) + "%"; 2336 if(button.parents('.ays-quiz-container').find('.ays-live-bar-percent').hasClass('ays-live-bar-count')){ 2337 button.parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(curent_number+1)); 2338 }else{ 2339 button.parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(final_width)); 2340 } 2341 button.parents('.ays-quiz-container').find('.ays-live-bar-fill').animate({'width': final_width}, 500); 2342 } 2343 } 2344 }else{ 2345 button.parents('.ays-quiz-container').find('.ays-live-bar-wrap').removeClass('rubberBand').addClass('bounceOut'); 2346 setTimeout(function () { 2347 button.parents('.ays-quiz-container').find('.ays-live-bar-wrap').css('display','none'); 2348 },300) 2349 } 2350 2351 if(questions_count === curent_number){
2352 if(_this.current_fs.hasClass('.information_form').length !== 0){ 2353 _this.current_fs.parents('.ays-quiz-container').find('.ays-quiz-timer').parent().slideUp(500); 2354 setTimeout(function () { 2355 _this.current_fs.parents('.ays-quiz-container').find('.ays-quiz-timer').parent().remove(); 2356 },500); 2357 } 2358 } 2359 } 2360 2361 AysSurveyPlugin.prototype.checkForm = function( button ){ 2362 var _this = this; 2363 _this.animating = false; 2364 2365 var section = button.parents('.' + _this.htmlClassPrefix + 'section'); 2366 var requiredQuestions = section.find('[data-required="true"],[data-is-min="true"]'); 2367 if ( requiredQuestions.length !== 0) { 2368 var empty_inputs = 0; 2369 var errorQuestions = section.find('.ays-has-error'); 2370 section.find('.ays-has-error').removeClass('ays-has-error'); 2371 for (var i = 0; i < requiredQuestions.length; i++) { 2372 var item = requiredQuestions.eq(i); 2373 var checkMinVotes = item.data('isMin'); 2374 var checkAllTermsAndConds = item.data('allTermsCheck'); 2375 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' ){ 2376 var errorMessage = '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">'; 2377 if(item.data('type') == 'date_time'){ 2378 var dateTimeInps = item.find( '.' + _this.htmlClassPrefix + 'input' ); 2379 var dateTimeInps = item.find( '.' + _this.htmlClassPrefix + 'input:not(.' + _this.htmlClassPrefix + 'not-required-field)' ); 2380 var dateTimeChecker = true; 2381 dateTimeInps.each(function(e,i){ 2382 if($(i).val() == ''){ 2383 dateTimeChecker = false; 2384 2385 if($(dateTimeInps[0]).val() == ''){ 2386 $(dateTimeInps[0]).focus(); 2387 } 2388 else{ 2389 $(dateTimeInps[e]).focus(); 2390 } 2391 errorMessage += '<span>' + _this.dbOptions.survey_required_questions_message + '</span>'; 2392 item.addClass('ays-has-error'); 2393 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').html(errorMessage); 2394 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').show(); 2395 _this.goToTop( item ); 2396 2397 empty_inputs++; 2398 } 2399 }); 2400 if(!dateTimeChecker){ 2401 break; 2402 } 2403 } 2404 if( item.find( '.' + _this.htmlClassPrefix + 'input' ).val() == '' ){ 2405 errorMessage += '<span>' + _this.dbOptions.survey_required_questions_message + '</span>'; 2406 item.addClass('ays-has-error'); 2407 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').html(errorMessage); 2408 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').show(); 2409 _this.goToTop( item ); 2410 item.find( '.' + _this.htmlClassPrefix + 'input:not(.' + _this.htmlClassPrefix + 'not-required-field)' ).focus(); 2411 empty_inputs++; 2412 break; 2413 }else{ 2414 if( item.data('type') == 'email' ){ 2415 if ( ! (_this.emailValidatePattern.test( item.find( '.' + _this.htmlClassPrefix + 'input' ).val() ) ) ) { 2416 errorMessage += '<span>' + aysSurveyLangObj.emailValidationError + '</span>'; 2417 item.addClass('ays-has-error'); 2418 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').html(errorMessage); 2419 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').show(); 2420 _this.goToTop( item ); 2421 item.find( '.' + _this.htmlClassPrefix + 'input:not(.' + _this.htmlClassPrefix + 'not-required-field)' ).focus(); 2422 empty_inputs++; 2423 } 2424 }else{ 2425 if( item.data('type') != 'number' ){ 2426 continue; 2427 } 2428 } 2429 } 2430 } 2431 2432 var errorFlag = false; 2433 var checker = false; 2434 if ( item.data('type') == 'radio' || item.data('type') == 'checkbox' || item.data('type') == 'linear_scale' || item.data('type') == 'nps' || item.data('type') == 'ranking' || item.data('type') == 'star' || item.data('type') == 'matrix_scale' || item.data('type') == 'matrix_scale_checkbox' || item.data('type') == 'star_list' || item.data('type') == 'slider_list' || item.data('type') == 'range' || item.data('type') == 'upload' ) { 2435 var questType = item.data('type'); 2436 if(questType == 'linear_scale' || questType == 'star' || questType == 'nps'){ 2437 questType = "radio"; 2438 } 2439 2440 if( questType == 'matrix_scale' || questType == 'star_list' || questType == 'matrix_scale_checkbox'){ 2441 var checkedFlag = 0; 2442 var checkedInputs = ""; 2443 var checkableinputType = "radio"; 2444 if(questType == 'matrix_scale' || questType == 'matrix_scale_checkbox'){ 2445 checkedInputs = item.find( '.ays-survey-answer-matrix-scale-row:not(:first-child)'); 2446 } 2447 else if(questType == 'star_list'){ 2448 checkedInputs = item.find( '.ays-survey-answer-star-list-row'); 2449 } 2450 var checkedInputsLength = checkedInputs.length; 2451 if(questType == 'matrix_scale_checkbox'){ 2452 checkableinputType = "checkbox"; 2453 } 2454 checkedInputs.each(function(){ 2455 var getCheckedInputs = $(this).find('input[type="'+checkableinputType+'"]:checked'); 2456 if(getCheckedInputs.length > 0){ 2457 checkedFlag++; 2458 } 2459 }); 2460 2461 if(checkedFlag < checkedInputsLength){ 2462 errorFlag = true; 2463 } 2464 } 2465 else if( questType == 'slider_list' ){ 2466 var checkedFlag = 0; 2467 var checkedInputs = item.find( '.ays-survey-answer-slider-list-row:not(:first-child)'); 2468 var checkedInputsLength = checkedInputs.length; 2469 var x = checkedInputs.find('input.isChanged'); 2470 2471 checkedInputs.each(function(){ 2472 var getCheckedInputs = $(this).find('input.isChanged'); 2473 if(getCheckedInputs.length > 0){ 2474 checkedFlag++; 2475 } 2476 }); 2477 2478 if(checkedFlag < checkedInputsLength){ 2479 errorFlag = true; 2480 } 2481 } 2482 else{ 2483 if( item.find('input[type="'+ questType +'"]:checked').length == 0 ){ 2484 errorFlag = true; 2485 } 2486 } 2487 2488 if(questType == 'ranking'){ 2489 errorFlag = true; 2490 } 2491 2492 if(typeof checkMinVotes != 'undefined' && checkMinVotes){ 2493 checker = _this.checkMinVotes( item ); 2494 if( ! checker ){ 2495 return false; 2496 } 2497 } 2498 2499 if(typeof checkAllTermsAndConds != 'undefined' && checkAllTermsAndConds){ 2500 checker = _this.checkTermsAndConds( item ); 2501 if( ! checker ){ 2502 return false; 2503 } 2504 } 2505 2506 2507 if( item.find('.' + _this.htmlClassPrefix + 'answer-other-input').length != 0 && 2508 item.find('.' + _this.htmlClassPrefix + 'answer-label-other input[value="0"]:checked').length > 0 ){ 2509 if( item.find('.' + _this.htmlClassPrefix + 'answer-other-input').val() == '' ){ 2510 errorFlag = true; 2511 item.find('.' + _this.htmlClassPrefix + 'answer-other-input').focus(); 2512 } 2513 } 2514 2515 if( errorFlag ){ 2516 var errorMessage = '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">'; 2517 errorMessage += '<span>' + _this.dbOptions.survey_required_questions_message + '</span>'; 2518 item.addClass('ays-has-error'); 2519 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').html(errorMessage); 2520 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').show(); 2521 _this.goToTop( item ); 2522 empty_inputs++; 2523 break; 2524 }else{ 2525 continue; 2526 } 2527 } 2528 2529 if ( item.data('type') == 'select' ) { 2530 if( item.find('.' + _this.htmlClassPrefix + 'question-select').aysDropdown('get value') == '' ){ 2531 var errorMessage = '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">'; 2532 errorMessage += '<span>' + _this.dbOptions.survey_required_questions_message + '</span>'; 2533 item.addClass('ays-has-error'); 2534 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').html(errorMessage); 2535 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').show(); 2536 _this.goToTop( item ); 2537 empty_inputs++; 2538 break; 2539 }else{ 2540 continue; 2541 } 2542 } 2543 2544 if( item.data('type') == 'number' ){ 2545 var numberInput = item.find('input.ays-survey-check-number-limit'); 2546 var currentQuestion = item; 2547 var currentquestionId = currentQuestion.find('.' + _this.htmlClassPrefix + 'question-id').val(); 2548 var questionTextLimitOptions = _this.dbOptions[ _this.dbOptionsPrefix + 'number_limit_options' ][currentquestionId]; 2549 _this.aysSurveyCheckNumberLimit(currentQuestion,questionTextLimitOptions,numberInput,$(numberInput)); 2550 2551 if( item.hasClass('ays-has-error') ){ 2552 _this.goToTop( item ); 2553 item.find( '.' + _this.htmlClassPrefix + 'input' ).focus(); 2554 empty_inputs++; 2555 break; 2556 }else{ 2557 continue; 2558 } 2559 } 2560 } 2561 2562 var matrixQuestions = section.find('.' + _this.htmlClassPrefix + 'question[data-one-response="true"]'); 2563 if(matrixQuestions.length > 0 && typeof errorFlag != "undefined" && !errorFlag){ 2564 for(var i = 0; i < matrixQuestions.length; i++){ 2565 var checker = _this.checkOneResponsePerColumn( matrixQuestions.eq(i) ); 2566 if( ! checker ){ 2567 empty_inputs++; 2568 break; 2569 } 2570 } 2571 } 2572 for (var i = 0; i < errorQuestions.length; i++) { 2573 var item = errorQuestions.eq(i); 2574 if( item.data('type') == 'email' ){ 2575 if( ! (_this.emailValidatePattern.test( item.find( '.' + _this.htmlClassPrefix + 'input' ).val() ) ) ){ 2576 var errorMessage = '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">'; 2577 errorMessage += '<span>' + aysSurveyLangObj.emailValidationError + '</span>'; 2578 2579 item.addClass('ays-has-error'); 2580 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').html(errorMessage); 2581 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').show(); 2582 _this.goToTop( item ); 2583 item.find( '.' + _this.htmlClassPrefix + 'input:not(.' + _this.htmlClassPrefix + 'not-required-field)' ).focus(); 2584 empty_inputs++; 2585 break; 2586 }else{ 2587 continue; 2588 } 2589 } 2590 } 2591 2592 if (empty_inputs !== 0) { 2593 return false; 2594 }else{ 2595 return true; 2596 } 2597 }else{ 2598 var empty_inputs = 0; 2599 // section.find('.ays-has-error').removeClass('ays-has-error'); 2600 var errorQuestions = section.find('.ays-has-error'); 2601 for (var i = 0; i < errorQuestions.length; i++) { 2602 var item = errorQuestions.eq(i); 2603 if( item.data('type') == 'email' ){ 2604 if( ! (_this.emailValidatePattern.test( item.find( '.' + _this.htmlClassPrefix + 'input' ).val() ) ) ){ 2605 var errorMessage = '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">'; 2606 errorMessage += '<span>' + aysSurveyLangObj.emailValidationError + '</span>'; 2607 2608 item.addClass('ays-has-error'); 2609 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').html(errorMessage); 2610 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').show(); 2611 _this.goToTop( item ); 2612 item.find( '.' + _this.htmlClassPrefix + 'input:not(.' + _this.htmlClassPrefix + 'not-required-field)' ).focus(); 2613 empty_inputs++; 2614 break; 2615 }else{ 2616 continue; 2617 } 2618 } 2619 if( item.data('type') == 'number' ){ 2620 if( item.hasClass('ays-has-error') ){ 2621 _this.goToTop( item ); 2622 item.find( '.' + _this.htmlClassPrefix + 'input' ).focus(); 2623 empty_inputs++; 2624 break; 2625 }else{ 2626 continue; 2627 } 2628 } 2629 } 2630 2631 var matrixQuestions = section.find('.' + _this.htmlClassPrefix + 'question[data-one-response="true"]'); 2632 if(matrixQuestions.length > 0){ 2633 for(var i = 0; i < matrixQuestions.length; i++){ 2634 var checker = _this.checkOneResponsePerColumn( matrixQuestions.eq(i) ); 2635 if( ! checker ){ 2636
2636 return false; 2637 } 2638 } 2639 } 2640 2641 var questions = section.find('.' + _this.htmlClassPrefix + 'question[data-is-min="true"]'); 2642 if(questions.length > 0){ 2643 for(var i = 0; i < questions.length; i++){ 2644 var checker = _this.checkMinVotes( questions.eq(i) ); 2645 if( ! checker ){ 2646 return false; 2647 } 2648 } 2649 } 2650 2651 if (empty_inputs !== 0) { 2652 return false; 2653 }else{ 2654 return true; 2655 } 2656 } 2657 2658 return true; 2659 } 2660 2661 AysSurveyPlugin.prototype.blockedContent = function( blocked ) { 2662 var _this = this; 2663 if( blocked ){ 2664 var blockedContent = _this.$el.hasClass( _this.htmlClassPrefix + 'blocked-content' ); 2665 if ( blockedContent ) { 2666 var limitAttemptCount = _this.dbOptions[ _this.dbOptionsPrefix + 'limit_users' ]; 2667 var redirectUrl = _this.dbOptions[ _this.dbOptionsPrefix + 'redirect_url' ]; 2668 if( limitAttemptCount && redirectUrl != ''){ 2669 var redirectTimerHTML = '<div class="' + _this.htmlClassPrefix + 'redirect-timer ' + _this.htmlClassPrefix + 'countdown-timer">' + 2670 aysSurveyLangObj.redirectAfter + ' <span class="' + _this.htmlClassPrefix + 'countdown-time">' + _this.dbOptions[ _this.dbOptionsPrefix + 'redirect_delay_seconds' ] + '</span>' + 2671 '</div>'; 2672 2673 _this.$el.find('.' + _this.htmlClassPrefix + 'section-header').prepend( $( redirectTimerHTML ) ); 2674 2675 var timer = _this.dbOptions[ _this.dbOptionsPrefix + 'redirect_delay' ] + 2; 2676 _this.timer( timer, { 2677 blockedContent: true, 2678 redirectUrl: _this.dbOptions[ _this.dbOptionsPrefix + 'redirect_url' ] 2679 }); 2680 } 2681 } 2682 } 2683 2684 if( _this.$el.find('.ays_survey_login_form').length > 0 ){ 2685 var surveyLoginForm = _this.$el.find('.ays_survey_login_form'); 2686 var usernameInput = surveyLoginForm.find('input[type="text"]'); 2687 var passwordInput = surveyLoginForm.find('input[type="password"]'); 2688 var checkboxInput = surveyLoginForm.find('input[type="checkbox"]'); 2689 var submitInput = surveyLoginForm.find('input[type="submit"]'); 2690 _this.makeSurveyStyleInput( usernameInput ); 2691 _this.makeSurveyStyleInput( passwordInput ); 2692 _this.makeSurveyStyleSubmit( submitInput ); 2693 if( checkboxInput.length > 0 ){ 2694 _this.makeSurveyStyleCheckbox( checkboxInput ); 2695 } 2696 } 2697 2698 if(_this.dbOptions[ _this.dbOptionsPrefix + 'enable_survey_start_loader' ]){ 2699 _this.$el.find('.ays-survey-wait-loading-loader').css("display" , "none"); 2700 } 2701 2702 } 2703 2704 AysSurveyPlugin.prototype.selects = function(){ 2705 var _this = this; 2706 _this.$el.find('.ays-field').on('click', function() { 2707 if ($(this).find(".select2").hasClass('select2-container--open')) { 2708 $(this).find('b[role="presentation"]').removeClass('ays_fa ays_fa_chevron_down'); 2709 $(this).find('b[role="presentation"]').addClass('ays_fa ays_fa_chevron_up'); 2710 } else { 2711 $(this).find('b[role="presentation"]').removeClass('ays_fa ays_fa_chevron_up'); 2712 $(this).find('b[role="presentation"]').addClass('ays_fa ays_fa_chevron_down'); 2713 } 2714 }); 2715 2716 _this.$el.find('select.ays-select').on("select2:selecting", function(e){ 2717 $(this).parents('.ays-quiz-container').find('b[role="presentation"]').addClass('ays_fa ays_fa_chevron_down'); 2718 }); 2719 2720 _this.$el.find('select.ays-select').on("select2:closing", function(e){ 2721 $(this).parents('.ays-quiz-container').find('b[role="presentation"]').addClass('ays_fa ays_fa_chevron_down'); 2722 }); 2723 2724 _this.$el.find('select.ays-select').on("select2:select", function(e){
2725 $(this).parent().find('.ays-select-field-value').attr("value", $(this).val()); 2726 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')) { 2727 $(this).parents('div[data-question-id]').find('.ays_next').trigger('click'); 2728 } 2729 if($(this).parents(".ays-questions-container").find('form[id^="ays_finish_quiz"]').hasClass('enable_correction')) { 2730 if ($(this).find('option:selected').data("chisht") == 1) { 2731 $(this).parents('.ays-field').addClass('correct correct_div'); 2732 $(this).parents('.ays-field').find('.select2-selection.select2-selection--single').css("border-bottom-color", "green"); 2733 } else { 2734 $(this).parents('.ays-field').addClass('wrong wrong_div'); 2735 $(this).parents('.ays-field').find('.select2-selection.select2-selection--single').css("border-bottom-color", "red"); 2736 } 2737 if ($(this).find('option:selected').data("chisht") == 1) { 2738 $(e.target).parents().eq(3).find('.right_answer_text').fadeIn(); 2739 } 2740 else { 2741 $(e.target).parents().eq(3).find('.wrong_answer_text').fadeIn(); 2742 } 2743 $(this).attr("disabled", true); 2744 $(e.target).next().css("background-color", "#777"); 2745 $(e.target).next().find('.selection').css("background-color", "#777"); 2746 $(e.target).next().find('.select2-selection').css("background-color", "#777"); 2747 } 2748 var this_select_value = $(this).val(); 2749 $(this).find("option").removeAttr("selected"); 2750 $(this).find("option[value='"+this_select_value+"']").attr("selected", true); 2751 }); 2752 } 2753 2754 AysSurveyPlugin.prototype.answersField = function(){ 2755 var _this = this; 2756 2757 _this.$el.on('change', 'input[name^="ays_questions"]', function (e) { 2758 var quizContainer = _this.$el; 2759 if(typeof myOptions != 'undefined'){ 2760 var isRequiredQuestion = (_this.dbOptions.make_questions_required && _this.dbOptions.make_questions_required == "on") ? true : false; 2761 if(isRequiredQuestion === true){ 2762 if($(e.target).attr('type') === 'radio' || $(e.target).attr('type') === 'checkbox'){ 2763 if($(e.target).parents('div[data-question-id]').find('input[name^="ays_questions"]:checked').length != 0){ 2764 if (!$(e.target).parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none')){ 2765 $(e.target).parents('div[data-question-id]').find('input.ays_next').removeAttr('disabled'); 2766 $(e.target).parents('div[data-question-id]').find('input.ays_early_finish').removeAttr('disabled'); 2767 }else if(!$(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) { 2768 $(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').removeAttr('disabled'); 2769 $(e.target).parents('div[data-question-id]').find('i.ays_early_finish').removeAttr('disabled'); 2770 } 2771 }else{ 2772 if (!$(e.target).parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none')){ 2773 $(e.target).parents('div[data-question-id]').find('input.ays_next').attr('disabled', true); 2774 $(e.target).parents('div[data-question-id]').find('input.ays_early_finish').attr('disabled', true); 2775 }else if(!$(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) { 2776 $(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').attr('disabled', true); 2777 $(e.target).parents('div[data-question-id]').find('i.ays_early_finish').attr('disabled', true); 2778 } 2779 } 2780 } 2781 } 2782 } 2783 2784 if($(e.target).parents('.step').hasClass('not_influence_to_score')){ 2785 if($(e.target).attr('type') === 'radio') { 2786 $(e.target).parents('.ays-quiz-answers').find('.checked_answer_div').removeClass('checked_answer_div'); 2787 $(e.target).parents('.ays-field').addClass('checked_answer_div'); 2788 } 2789 if($(e.target).attr('type') === 'checkbox') { 2790 if(!$(e.target).parents('.ays-field').hasClass('checked_answer_div')){ 2791 $(e.target).parents('.ays-field').addClass('checked_answer_div'); 2792 }else{ 2793 $(e.target).parents('.ays-field').removeClass('checked_answer_div'); 2794 } 2795 } 2796 var checked_inputs = $(e.target).parents().eq(1).find('input
2796:checked'); 2797 if (checked_inputs.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') && 2798 checked_inputs.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) { 2799 if (checked_inputs.attr('type') === 'radio') { 2800 checked_inputs.parents('div[data-question-id]').find('.ays_next').trigger('click'); 2801 } 2802 } 2803 if ($(e.target).parents().eq(4).hasClass('enable_correction')) { 2804 if (checked_inputs.attr('type') === "radio") { 2805 $(e.target).parents('div[data-question-id]').find('input[name^="ays_questions"]').attr('disabled', true); 2806 $(e.target).parents('div[data-question-id]').find('input[name^="ays_questions"]').off('change'); 2807 } else if (checked_inputs.attr('type') === "checkbox") { 2808 $(e.target).attr('disabled', true); 2809 $(e.target).off('change'); 2810 } 2811 } 2812 return false; 2813 } 2814 2815 if (quizContainer.find('form').hasClass('enable_correction')) { 2816 var right_answer_sound = quizContainer.find('.ays_quiz_right_ans_sound').get(0); 2817 var wrong_answer_sound = quizContainer.find('.ays_quiz_wrong_ans_sound').get(0); 2818 var finishAfterWrongAnswer = (_this.dbOptions.finish_after_wrong_answer && _this.dbOptions.finish_after_wrong_answer == "on") ? true : false; 2819 if ($(e.target).parents().eq(1).find('input[name="ays_answer_correct[]"]').length !== 0) { 2820 var checked_inputs = $(e.target).parents().eq(1).find('input:checked'); 2821 if (checked_inputs.attr('type') === "radio") { 2822 2823 checked_inputs.nextAll().addClass('answered'); 2824 checked_inputs.parent().addClass('checked_answer_div'); 2825 if (checked_inputs.prev().val() == 1){ 2826 checked_inputs.nextAll().addClass('correct') 2827 checked_inputs.parent().addClass('correct_div'); 2828 }else{ 2829 checked_inputs.nextAll().addClass('wrong'); 2830 checked_inputs.parent().addClass('wrong_div'); 2831 } 2832 2833 if (checked_inputs.prev().val() == 1) { 2834 if(_this.dbOptions.answers_rw_texts && (_this.dbOptions.answers_rw_texts == 'on_passing' || _this.dbOptions.answers_rw_texts == 'on_both')){ 2835 var explanationTime = _this.dbOptions.explanation_time && _this.dbOptions.explanation_time != "" ? parseInt(_this.dbOptions.explanation_time) : 4; 2836 if(! $(e.target).parents('.step').hasClass('not_influence_to_score')){ 2837 $(e.target).parents().eq(3).find('.right_answer_text').slideDown(250); 2838 } 2839 _this.explanationTimeout = setTimeout(function(){ 2840 if (checked_inputs.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') && 2841 checked_inputs.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) { 2842 checked_inputs.parents('div[data-question-id]').find('input.ays_next').trigger('click'); 2843 } 2844 }, explanationTime * 1000); 2845 }else{ 2846 if (checked_inputs.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') && 2847 checked_inputs.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) { 2848 checked_inputs.parents('div[data-question-id]').find('input.ays_next').trigger('click'); 2849 } 2850 } 2851 if((right_answer_sound)){ 2852 resetPlaying([right_answer_sound, wrong_answer_sound]); 2853 setTimeout(function(){ 2854 right_answer_sound.play(); 2855 }, 10); 2856 } 2857 } else { 2858 $(e.target).parents('.ays-quiz-answers').find('input[name="ays_answer_
2858correct[]"][value="1"]').parent().addClass('correct_div').addClass('checked_answer_div'); 2859 $(e.target).parents('.ays-quiz-answers').find('input[name="ays_answer_correct[]"][value="1"]').nextAll().addClass('correct answered'); 2860 2861 if(_this.dbOptions.answers_rw_texts && (_this.dbOptions.answers_rw_texts == 'on_passing' || _this.dbOptions.answers_rw_texts == 'on_both')){ 2862 var explanationTime = _this.dbOptions.explanation_time && _this.dbOptions.explanation_time != "" ? parseInt(_this.dbOptions.explanation_time) : 4; 2863 if(! $(e.target).parents('.step').hasClass('not_influence_to_score')){ 2864 $(e.target).parents().eq(3).find('.wrong_answer_text').slideDown(250); 2865 } 2866 _this.explanationTimeout = setTimeout(function(){ 2867 if (checked_inputs.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') && 2868 checked_inputs.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) { 2869 if(finishAfterWrongAnswer){ 2870 goToLastPage(e); 2871 }else{ 2872 checked_inputs.parents('div[data-question-id]').find('input.ays_next').trigger('click'); 2873 } 2874 }else{ 2875 if(finishAfterWrongAnswer){ 2876 goToLastPage(e); 2877 } 2878 } 2879 }, explanationTime * 1000); 2880 }else{ 2881 if (checked_inputs.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') && 2882 checked_inputs.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) { 2883 if(finishAfterWrongAnswer){ 2884 goToLastPage(e); 2885 }else{ 2886 checked_inputs.parents('div[data-question-id]').find('input.ays_next').trigger('click'); 2887 } 2888 }else{ 2889 if(finishAfterWrongAnswer){ 2890 goToLastPage(e); 2891 } 2892 } 2893 } 2894 if((wrong_answer_sound)){ 2895 resetPlaying([right_answer_sound, wrong_answer_sound]); 2896 setTimeout(function(){ 2897 wrong_answer_sound.play(); 2898 }, 10); 2899 } 2900 } 2901 $(e.target).parents('div[data-question-id]').find('input[name^="ays_questions"]').attr('disabled', true); 2902 $(e.target).parents('div[data-question-id]').find('input[name^="ays_questions"]').off('change'); 2903 $(e.target).parents('div[data-question-id]').find('.ays-field').css({ 2904 'pointer-events': 'none' 2905 }); 2906 2907 }else if(checked_inputs.attr('type') === "checkbox"){ 2908 checked_inputs = $(e.target); 2909 if (checked_inputs.length === 1) { 2910 checked_inputs.parent().addClass('checked_answer_div'); 2911 if(checked_inputs.prev().val() == 1){ 2912 if((right_answer_sound)){ 2913 resetPlaying([right_answer_sound, wrong_answer_sound]); 2914 setTimeout(function(){ 2915 right_answer_sound.play(); 2916 }, 10); 2917 } 2918 checked_inputs.parent().addClass('correct_div'); 2919 checked_inputs.nextAll().addClass('correct answered'); 2920 }else{ 2921 if((wrong_answer_sound)){ 2922 resetPlaying([right_answer_sound, wrong_answer_sound]); 2923 setTimeout(function(){ 2924 wrong_answer_sound.play(); 2925 }, 10); 2926 } 2927 if(finishAfterWrongAnswer){ 2928 goToLastPage(e); 2929 } 2930 checked_inputs.parent().addClass('wrong_div'); 2931 checked_inputs.nextAll().addClass('wrong answered'); 2932 } 2933 }else{ 2934 for (var i = 0; i < checked_inputs.length; i++) { 2935 if(checked_inputs.eq(i).prev().val() == 1){ 2936 if((right_answer_sound)){ 2937 resetPlaying([right_answer_sound, wrong_answer_sound]); 2938 setTimeout(function(){ 2939 right_answer_sound.play(); 2940 }, 10); 2941 } 2942 checked_inputs.eq(i).nextAll().addClass('correct answered'); 2943 checked_inputs.eq(i).parent().addClass('correct_div'); 2944 checked_inputs.eq(i).parent().addClass('checked_answer_div'); 2945 }else{ 2946 if((wrong_answer_sound)){ 2947 resetPlaying([right_answer_sound, wrong_answer_sound]); 2948 setTimeout(function(){ 2949 wrong_answer_sound.play(); 2950 }, 10); 2951 } 2952 if(finishAfterWrongAnswer){ 2953 goToLastPage(e); 2954 } 2955 checked_inputs.eq(i).parent().addClass('checked_answer_div'); 2956 checked_inputs.eq(i).nextAll().addClass('wrong answered'); 2957 checked_inputs.eq(i).parent().addClass('wrong_div'); 2958 } 2959 } 2960 if(checked_inputs.eq(i).prev().val() == 1){ 2961 checked_inputs.eq(i).next().addClass('correct answered'); 2962 if((right_answer_sound)){ 2963 resetPlaying([right_answer_sound, wrong_answer_sound]); 2964 setTimeout(function(){ 2965 right_answer_sound.play(); 2966 }, 10); 2967 } 2968 }else{ 2969 checked_inputs.eq(i).next().addClass('wrong answered'); 2970 if((wrong_answer_sound)){ 2971 resetPlaying([right_answer_sound, wrong_answer_sound]); 2972 setTimeout(function(){ 2973 wrong_answer_sound.play(); 2974 }, 10); 2975 } 2976 } 2977 2978 } 2979 $(e.target).attr('disabled', true); 2980 $(e.target).off('change'); 2981 } 2982 } 2983 }else{ 2984 if($(e.target).attr('type') === 'radio') { 2985 $(e.target).parents('.ays-quiz-answers').find('.checked_answer_div').removeClass('checked_answer_div'); 2986 $(e.target).parents('.ays-field').addClass('checked_answer_div'); 2987 } 2988 if($(e.target).attr('type') === 'checkbox') { 2989 if(!$(e.target).parents('.ays-field').hasClass('checked_answer_div')){ 2990 $(e.target).parents('.ays-field').addClass('checked_answer_div'); 2991 }else{ 2992 $(e.target).parents('.ays-field').removeClass('checked_answer_div'); 2993 } 2994 } 2995 var checked_inputs = $(e.target).parents().eq(1).find('input
2995:checked'); 2996 if (checked_inputs.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') && 2997 checked_inputs.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) { 2998 if (checked_inputs.attr('type') === 'radio') { 2999 checked_inputs.parents('div[data-question-id]').find('input.ays_next').trigger('click'); 3000 } 3001 } 3002 } 3003 }); 3004 3005 _this.$el.find('button.ays_check_answer').on('click', function (e) { 3006 var thisAnswerOptions; 3007 var quizContainer = _this.$el; 3008 var right_answer_sound = quizContainer.find('.ays_quiz_right_ans_sound').get(0); 3009 var wrong_answer_sound = quizContainer.find('.ays_quiz_wrong_ans_sound').get(0); 3010 var questionId = $(this).parents('.step').data('questionId'); 3011 var finishAfterWrongAnswer = (_this.dbOptions.finish_after_wrong_answer && _this.dbOptions.finish_after_wrong_answer == "on") ? true : false; 3012 thisAnswerOptions = _this.QuizQuestionsOptions[questionId]; 3013 if($(this).parent().find('.ays-text-input').val() !== ""){ 3014 if ($(e.target).parents('form[id^="ays_finish_quiz"]').hasClass('enable_correction')) { 3015 if($(e.target).parents('.step').hasClass('not_influence_to_score')){ 3016 return false; 3017 } 3018 $(this).css({ 3019 animation: "bounceOut .5s", 3020 }); 3021 setTimeout(function(){ 3022 $(e.target).parent().find('.ays-text-input').css('width', '100%'); 3023 $(e.target).css("display", "none"); 3024 },480); 3025 $(e.target).parent().find('.ays-text-input').css('background-color', '#eee'); 3026 $(this).parent().find('.ays-text-input').attr('disabled', 'disabled'); 3027 $(this).attr('disabled', 'disabled'); 3028 $(this).off('change'); 3029 $(this).off('click'); 3030 3031 var input = $(this).parent().find('.ays-text-input'); 3032 var type = input.attr('type'); 3033 var userAnsweredText = input.val().trim(); 3034 3035 var trueAnswered = false; 3036 var thisQuestionAnswer = thisAnswerOptions.question_answer.toLowerCase(); 3037 3038 if(type == 'date'){ 3039 var correctDate = new Date(thisAnswerOptions.question_answer), 3040 correctDateYear = correctDate.getFullYear(), 3041 correctDateMonth = correctDate.getMonth(), 3042 correctDateDay = correctDate.getDate(); 3043 var userDate = new Date(userAnsweredText), 3044 userDateYear = userDate.getFullYear(), 3045 userDateMonth = userDate.getMonth(), 3046 userDateDay = userDate.getDate(); 3047 if(correctDateYear == userDateYear && correctDateMonth == userDateMonth && correctDateDay == userDateDay){ 3048 trueAnswered = true; 3049 } 3050 }else if(type != 'number'){ 3051 thisQuestionAnswer = thisQuestionAnswer.split('%%%'); 3052 for(var i = 0; i < thisQuestionAnswer.length; i++){ 3053 if(userAnsweredText.toLowerCase() == thisQuestionAnswer[i].trim()){ 3054 trueAnswered = true; 3055 break; 3056 } 3057 } 3058 }else{ 3059 if(userAnsweredText.toLowerCase() == thisQuestionAnswer.trim()){ 3060 trueAnswered = true; 3061 } 3062 } 3063 3064 if(trueAnswered){ 3065 if((right_answer_sound)){ 3066 resetPlaying([right_answer_sound, wrong_answer_sound]); 3067 setTimeout(function(){ 3068 right_answer_sound.play(); 3069 }, 10); 3070 } 3071 $(this).parent().find('.ays-text-input').css('background-color', 'rgba(39,174,96,0.5)'); 3072 $(this).parent().find('input[name="ays_answer_
3072correct[]"]').val(1); 3073 }else{ 3074 if((wrong_answer_sound)){ 3075 resetPlaying([right_answer_sound, wrong_answer_sound]); 3076 setTimeout(function(){ 3077 wrong_answer_sound.play(); 3078 }, 10); 3079 } 3080 $(this).parent().find('.ays-text-input').css('background-color', 'rgba(243,134,129,0.8)'); 3081 $(this).parent().find('input[name="ays_answer_correct[]"]').val(0); 3082 var rightAnswerText = '<div class="ays-text-right-answer">'; 3083 3084 if(type == 'date'){ 3085 var correctDate = new Date(thisAnswerOptions.question_answer), 3086 correctDateYear = correctDate.getFullYear(), 3087 correctDateMonth = (correctDate.getMonth() + 1) < 10 ? "0"+(correctDate.getMonth() + 1) : (correctDate.getMonth() + 1), 3088 correctDateDay = (correctDate.getDate() < 10) ? "0"+correctDate.getDate() : correctDate.getDate(); 3089 rightAnswerText += [correctDateMonth, correctDateDay, correctDateYear].join('/'); 3090 }else if(type != 'number'){ 3091 rightAnswerText += thisQuestionAnswer[0]; 3092 }else{ 3093 rightAnswerText += thisQuestionAnswer; 3094 } 3095 3096 rightAnswerText += '</div>'; 3097 $(this).parents('.ays-quiz-answers').append(rightAnswerText); 3098 $(this).parents('.ays-quiz-answers').find('.ays-text-right-answer').slideDown(500); 3099 if(finishAfterWrongAnswer){ 3100 goToLastPage(e); 3101 } 3102 } 3103 } 3104 } 3105 }); 3106 } 3107 3108 AysSurveyPlugin.prototype.makeSurveyStyleInput = function( input ) { 3109 var _this = this; 3110 3111 var html = '<div class="' + _this.htmlClassPrefix + 'question-input-box">'+ 3112 '<div class="' + _this.htmlClassPrefix + 'input-underline"></div>'+ 3113 '<div class="' + _this.htmlClassPrefix + 'input-underline-animation"></div>'+ 3114 '</div>'; 3115 html = $( html ); 3116 3117 html.insertAfter( input ); 3118 3119 html.prepend( input ); 3120 3121 input.addClass( _this.htmlClassPrefix + 'input' ); 3122 input.addClass( _this.htmlClassPrefix + 'question-input' ); 3123 } 3124 3125 AysSurveyPlugin.prototype.makeSurveyStyleCheckbox = function( input ) { 3126 var _this = this; 3127 3128 var html = '<div class="' + _this.htmlClassPrefix + 'answer-label-content">'+ 3129 '<div class="' + _this.htmlClassPrefix + 'answer-icon-content">'+ 3130 '<div class="' + _this.htmlClassPrefix + 'answer-icon-ink"></div>'+ 3131 '<div class="' + _this.htmlClassPrefix + 'answer-icon-content-1">'+ 3132 '<div class="' + _this.htmlClassPrefix + 'answer-icon-content-2">'+ 3133 '<div class="' + _this.htmlClassPrefix + 'answer-icon-content-3"></div>'+ 3134 '</div>'+ 3135 '</div>'+ 3136 '</div>'+ 3137 '<span class=""></span>'+ 3138 '</div>'; 3139 html = $( html ); 3140 3141 var inputCheckboxLabel = input.parents('label'); 3142 var inputCheckbox = input; 3143 3144 inputCheckboxLabel.addClass('ays-survey-answer-label'); 3145 html.find('span').text( inputCheckboxLabel.text() ); 3146 inputCheckboxLabel.text(''); 3147 input.remove(); 3148 inputCheckboxLabel.prepend( inputCheckbox ); 3149 html.insertAfter( inputCheckbox ); 3150 } 3151 3152 AysSurveyPlugin.prototype.makeSurveyStyleRadio = function( input ) { 3153 var _this = this; 3154 3155 var html = '<div class="' + _this.htmlClassPrefix + 'answer-label-content">'+ 3156 '<div class="' + _this.htmlClassPrefix + 'answer-icon-content">'+ 3157 '<div class="' + _this.htmlClassPrefix + 'answer-icon-ink"></div>'+ 3158 '<div class="' + _this.htmlClassPrefix + 'answer-icon-content-1">'+ 3159 '<div class="' + _this.htmlClassPrefix + 'answer-icon-content-2">'+ 3160 '<div class="' + _this.htmlClassPrefix + 'answer-icon-content-3"></div>'+ 3161 '</div>'+ 3162 '</div>'+ 3163 '</div>'+ 3164 '<span class=""></span>'+ 3165 '</div>'; 3166 html = $( html ); 3167 3168 var inputCheckboxLabel = input.parents('label'); 3169 var inputCheckbox = input; 3170 3171 inputCheckboxLabel.addClass('ays-survey-answer-label'); 3172 html.find('span').text( inputCheckboxLabel.text() ); 3173 inputCheckboxLabel.text(''); 3174 input.remove(); 3175 inputCheckboxLabel.prepend( inputCheckbox ); 3176 html.insertAfter( inputCheckbox ); 3177 } 3178 3179 AysSurveyPlugin.prototype.makeSurveyStyleSubmit = function( input ) { 3180 var _this = this; 3181 3182 var html = '<div class="' + _this.htmlClassPrefix + 'section-buttons">'+ 3183 '<div class="' + _this.htmlClassPrefix + 'section-button-container">'+ 3184 '<div class="' + _this.htmlClassPrefix + 'section-button-content">'+ 3185 '</div>'+ 3186 '</div>'+ 3187 '</div>'; 3188 html = $( html ); 3189 3190 html.insertAfter( input ); 3191 3192 html.find('.' + _this.htmlClassPrefix + 'section-button-content').append( input ); 3193 3194 input.addClass('ays-survey-section-button'); 3195 input.removeClass('button button-primary'); 3196 } 3197 3198 /** 3199 * @return {string} 3200 */ 3201 AysSurveyPlugin.prototype.GetFullDateTime = function() { 3202 var now = new Date(); 3203 var strDateTime = [[now.getFullYear(), AddZero(now.getMonth() + 1), AddZero(now.getDate())].join("-"), [AddZero(now.getHours()), AddZero(now.getMinutes()), AddZero(now.getSeconds())].join(":")].join(" "); 3204 return strDateTime; 3205 } 3206 3207 /** 3208 * @return {string} 3209 */ 3210 AysSurveyPlugin.prototype.AddZero = function (num) { 3211 return (num >= 0 && num < 10) ? "0" + num : num + ""; 3212 } 3213 3214 /** 3215 * @return {boolean} 3216 */ 3217 AysSurveyPlugin.prototype.validatePhoneNumber = function (input) { 3218 var phoneno = /^[+ 0-9-]+$/; 3219 if (input.value.match(phoneno)) { 3220 return true; 3221 } else { 3222 return false; 3223 } 3224 } 3225 3226 AysSurveyPlugin.prototype.sendSurveyData = function(data, element){ 3227 var _this = this; 3228 if(typeof _this.sendSurveyData.counter == 'undefined'){ 3229 _this.sendSurveyData.counter = 0; 3230 } 3231 if(window.navigator.onLine){ 3232 _this.sendSurveyData.counter++; 3233 $.ajax({
3234 url: window.aysSurveyMakerAjaxPublic.ajaxUrl, 3235 method: 'post', 3236 dataType: 'json', 3237 data: data, 3238 success: function(response){ 3239 if(response.status === true){ 3240 _this.doSurveyResult(response); 3241 }else{ 3242 if(_this.sendSurveyData.counter >= 5){ 3243 swal.fire({ 3244 type: 'error', 3245 html: aysSurveyLangObj.sorry + ".<br>" + aysSurveyLangObj.unableStoreData + "." 3246 }); 3247 // _this.goQuizFinishPage(element); 3248 }else{ 3249 if(window.navigator.onLine){ 3250 setTimeout(function(){ 3251 _this.sendSurveyData(data, element); 3252 },3000); 3253 }else{ 3254 _this.sendSurveyData(data, element); 3255 } 3256 } 3257 } 3258 }, 3259 error: function(jqXHR, textStatus, errorThrown) { 3260 if(_this.sendSurveyData.counter >= 5){ 3261 swal.fire({ 3262 type: 'error', 3263 html: aysSurveyLangObj.sorry + ".<br>" + aysSurveyLangObj.unableStoreData + "." 3264 }); 3265 // _this.goQuizFinishPage(element); 3266 }else{ 3267 setTimeout(function(){ 3268 _this.sendSurveyData(data, element); 3269 },3000); 3270 } 3271 } 3272 }); 3273 }else{ 3274 swal.fire({ 3275 type: 'warning', 3276 html: aysSurveyLangObj.connectionLost + ".<br>" + aysSurveyLangObj.checkConnection + "." 3277 }); 3278 _this.sendSurveyData.counter = 0; 3279 // _this.goQuizFinishPage(element); 3280 } 3281 } 3282 3283 AysSurveyPlugin.prototype.goQuizFinishPage = function(element){ 3284 var _this = this; 3285 var currentFS = _this.$el.find('.step.active-step'); 3286 var next_sibilings_count = _this.$el.find('.ays_question_count_per_page').val(); 3287 if (parseInt(next_sibilings_count) > 0 && 3288 (element.parents('.step').attr('data-question-id') || 3289 element.parents('.step').next().attr('data-question-id'))) { 3290 currentFS = _this.$el.find('div[data-question-id]'); 3291 } 3292 currentFS.prev().css('display', 'flex'); 3293 _this.aysAnimateStep(_this.$el.data('questEffect'), currentFS, currentFS.prev()); 3294 // currentFS.animate({opacity: 0}, { 3295 // step: function(now, mx) { 3296 // options.scale = 1 - (1 - now) * 0.2; 3297 // options.left = (now * 50)+"%"; 3298 // options.opacity = 1 - now; 3299 // currentFS.css({ 3300 // 'transform': 'scale('+options.scale+')', 3301 // 'position': '', 3302 // 'pointer-events': 'none' 3303 // }); 3304 // currentFS.prev().css({ 3305 // 'left': options.left, 3306 // 'opacity': options.opacity, 3307 // 'pointer-events': 'none' 3308 // }); 3309 // }, 3310 // duration: 800, 3311 // complete: function(){ 3312 // currentFS.hide(); 3313 // currentFS.css({ 3314 // 'opacity': '1', 3315 // 'pointer-events': 'auto', 3316 // }); 3317 // currentFS.prev().css({ 3318 // 'transform': 'scale(1)', 3319 // 'position': 'relative', 3320 // 'opacity': '1', 3321 // 'pointer-events': 'auto' 3322 // }); 3323 // options.animating = false; 3324 // }, 3325 // easing: 'easeInOutBack' 3326 // }); 3327 if(_this.dbOptions.enable_correction == 'on'){
3328 if(currentFS.prev().find('input:checked').length > 0){ 3329 currentFS.prev().find('.ays-field input').attr('disabled', 'disabled'); 3330 currentFS.prev().find('.ays-field input').on('click', function(){ 3331 return false; 3332 }); 3333 currentFS.prev().find('.ays-field input').on('change', function(){ 3334 return false; 3335 }); 3336 } 3337 if(currentFS.prev().find('option:checked').length > 0){ 3338 currentFS.prev().find('.ays-field select').attr('disabled', 'disabled'); 3339 currentFS.prev().find('.ays-field select').on('click', function(){ 3340 return false; 3341 }); 3342 currentFS.prev().find('.ays-field select').on('change', function(){ 3343 return false; 3344 }); 3345 } 3346 if(currentFS.prev().find('textarea').length > 0){ 3347 if(currentFS.prev().find('textarea').val() !== ''){ 3348 currentFS.prev().find('.ays-field textarea').attr('disabled', 'disabled'); 3349 currentFS.prev().find('.ays-field textarea').on('click', function(){ 3350 return false; 3351 }); 3352 currentFS.prev().find('.ays-field textarea').on('change', function(){ 3353 return false; 3354 }); 3355 } 3356 } 3357 } 3358 } 3359 3360 AysSurveyPlugin.prototype.doSurveyResult = function( response ){ 3361 var _this = this; 3362 if( response.status ){ 3363 // var formResultsContainer = _this.$el.find('.' + _this.htmlClassPrefix + 'results-content'); 3364 var formResults = _this.$el.find('.' + _this.htmlClassPrefix + 'thank-you-page'); 3365 if (_this.$el.hasClass('enable_questions_result')) { 3366 3367 } 3368 3369 _this.$el.find('.'+_this.htmlClassPrefix+'chat-footer').css({'display':'flex'}); 3370 3371 var aysQuizLoader = _this.$el.find('div[data-role="loader"]'); 3372 aysQuizLoader.addClass('ays-loader'); 3373 aysQuizLoader.removeClass(aysQuizLoader.data('class')); 3374 3375 var conditionPageMessage = ""; 3376 var conditionEmailMessage = ""; 3377 var conditionRedirectDelay = ""; 3378 var conditionRedirectUrl = ""; 3379 var conditionRedirectCountDown = ""; 3380 var trueConditionsCount = ""; 3381 3382 if(typeof response.conditionData != "undefined"){ 3383 if(response.conditionData.pageMessage){ 3384 conditionPageMessage = response.conditionData.pageMessage; 3385 } 3386 if(response.conditionData.emailMessage){ 3387 conditionEmailMessage = response.conditionData.emailMessage; 3388 } 3389 if(response.conditionData.redirectDelay){ 3390 conditionRedirectDelay = response.conditionData.redirectDelay; 3391 } 3392 if(response.conditionData.redirectUrl){ 3393 conditionRedirectUrl = response.conditionData.redirectUrl; 3394 } 3395 if(response.conditionData.redirectCountDown){ 3396 conditionRedirectCountDown = response.conditionData.redirectCountDown; 3397 } 3398 if(response.conditionData.trueConditionsCount){ 3399 trueConditionsCount = response.conditionData.trueConditionsCount; 3400 } 3401 } 3402 3403 if(trueConditionsCount){ 3404 console.log("You have more than one ("+trueConditionsCount+") true condition. Note that the program will take only the latest condition as true."); 3405 } 3406 3407 if(conditionRedirectUrl){ 3408 if(conditionRedirectDelay && +conditionRedirectDelay == 0){ 3409 if( conditionRedirectDelay == 0 && conditionRedirectUrl != "" ){ 3410 window.location = conditionRedirectUrl; 3411 return; 3412 } 3413 } 3414 } 3415 3416 if(conditionPageMessage){ 3417 if(typeof conditionPageMessage == 'string'){ 3418 formResults.prepend( $( '<div>' + conditionPageMessage + '</div>' ) ); 3419 } 3420 else{ 3421 var conditionsBox = $("<div></div>"); 3422 $.each(conditionPageMessage , function(index , conditionResMessage){ 3423 conditionsBox.append(conditionResMessage); 3424 }) 3425 formResults.prepend( conditionsBox ); 3426 } 3427 } 3428 3429 var chatSurveyMessage = null; 3430 if( response.message ){ 3431 var checkResType = _this.dbOptions[ _this.dbOptionsPrefix + 'show_summary_after_submission' ] ? 'ays-survey-show-results-no-flex' : ''; 3432 formResults.prepend( $( '<div>' + response.message + '</div>' ) ); 3433 _this.$el.find('.'+_this.htmlClassPrefix+'chat-header').find('.'+_this.htmlClassPrefix+'chat-final-message-loader').removeClass('active-chat-loader'); 3434 var thankYouMessageChatSurvey = '<div class="' + _this.htmlClassPrefix + 'chat-thank-you-message ' + _this.htmlClassPrefix +'chat-question-title ' + _this.htmlClassPrefix +'chat-thank-you-page '+checkResType+'">'+response.message + '<br>' + conditionPageMessage+'</div>'; 3435 _this.$el.find('.'+_this.htmlClassPrefix+'chat-header-main').append(thankYouMessageChatSurvey) 3436 chatSurveyMessage = _this.$el.find('.' + _this.htmlClassPrefix + 'chat-thank-you-message'); 3437 setTimeout(function(){ 3438 if( _this.$el.find('.ays-survey-chat-thank-you-message').length > 0 ){ 3439 _this.$el.find('.ays-survey-chat-thank-you-message').get(0).scrollIntoView({ 3440 block: 'center', 3441 behavior: "smooth" 3442 }); 3443 } 3444 }, 100); 3445 } 3446 3447 if( _this.dbOptions[ _this.dbOptionsPrefix + 'show_summary_after_submission' ] ){ 3448 3449 var surveySubmissionSummaryContainers = _this.$el.find( '.' + _this.htmlClassPrefix + 'submission-summary-container' ); 3450 3451 surveySubmissionSummaryContainers.each(function(){ 3452 var uniqueId = $(this).data('id'); 3453 3454 // Survey per answer count 3455 var thisAysSurveyPublicChartData = JSON.parse( atob( window.aysSurveyPublicChartData[ uniqueId ] ) ); 3456 3457 if ( typeof thisAysSurveyPublicChartData.surveyColor === 'undefined' ) { 3458 thisAysSurveyPublicChartData.surveyColor = '#FF5722'; 3459 } 3460 3461 $.each( thisAysSurveyPublicChartData.perAnswerData, function(){ 3462 switch( this.question_type ){ 3463 case "radio": 3464 case "yesorno": 3465 forRadioType( this, thisAysSurveyPublicChartData ); 3466 break; 3467 case "checkbox": 3468 forCheckboxType( this, thisAysSurveyPublicChartData ); 3469 break; 3470 case "select": 3471 forRadioType( this, thisAysSurveyPublicChartData ); 3472 break; 3473 case "linear_scale": 3474 forLinearScaleType( this, thisAysSurveyPublicChartData ); 3475 break; 3476 case "nps": 3477 forNPSType( this , thisAysSurveyPublicChartData); 3478 break; 3479 case "star": 3480 forLinearScaleType( this, thisAysSurveyPublicChartData ); 3481 break; 3482 case "matrix_scale": 3483 case "matrix_scale_checkbox": 3484 var checkModal = $('body').find('#ays-survey-matrix-scale-likert-detailed-calc-modal-box.ays-modal'); 3485 if((response.matrixModalHtml && response.matrixModalHtml != '') && checkModal.length == 0){ 3486 $('body').append(response.matrixModalHtml); 3487 } 3488 forMatrixScaleTypeCustom( this, thisAysSurveyPublicChartData ); 3489 break; 3490 case "star_list": 3491 forStarListTypeCustom( this, thisAysSurveyPublicChartData ); 3492 break; 3493 case "slider_list": 3494 forSliderListTypeCustom( this, thisAysSurveyPublicChartData ); 3495 break; 3496 case "range": 3497 forRangeType( this, thisAysSurveyPublicChartData ); 3498 break; 3499 case "ranking": 3500 forRankingType( this, thisAysSurveyPublicChartData ); 3501 break; 3502 3503 } 3504 }); 3505 }); 3506 } 3507 3508 if(conditionRedirectUrl){ 3509 if(conditionRedirectDelay && (+conditionRedirectDelay >
3509 0 || +conditionRedirectDelay == 0)){ 3510 var redirectAfterSubmitTimerHTML = '<div class="' + _this.htmlClassPrefix + 'redirect-timer ' + _this.htmlClassPrefix + 'countdown-timer">' + 3511 aysSurveyLangObj.redirectAfter + ' <span class="' + _this.htmlClassPrefix + 'countdown-time">' + conditionRedirectCountDown + '</span>' + 3512 '</div>'; 3513 formResults.prepend( $( redirectAfterSubmitTimerHTML ) ); 3514 _this.$el.find('.'+_this.htmlClassPrefix+'chat-footer').prepend( $( redirectAfterSubmitTimerHTML ) ); 3515 3516 var timer = +conditionRedirectDelay + 2; 3517 _this.timer( timer, { 3518 blockedContent: true, 3519 redirectUrl: conditionRedirectUrl 3520 }); 3521 } 3522 }else{ 3523 if( _this.dbOptions[ _this.dbOptionsPrefix + 'redirect_after_submit' ] ){ 3524 var uniqueCode = response.unique_code; 3525 var redirectUrl = _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_url' ]; 3526 3527 redirectUrl = redirectUrl.includes('?') ? redirectUrl.replace('(uniquecode)', `&uniquecode=${uniqueCode}`) : redirectUrl.replace('(uniquecode)', `?uniquecode=${uniqueCode}`); 3528 3529 if( parseInt( _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_delay' ] ) > 0 ){ 3530 if( redirectUrl != '' ){ 3531 var redirectAfterSubmitTimerHTML = '<div class="' + _this.htmlClassPrefix + 'redirect-timer ' + _this.htmlClassPrefix + 'countdown-timer">' + 3532 aysSurveyLangObj.redirectAfter + ' <span class="' + _this.htmlClassPrefix + 'countdown-time">' + _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_seconds' ] + '</span>' + 3533 '</div>'; 3534 formResults.prepend( $( redirectAfterSubmitTimerHTML ) ); 3535 _this.$el.find('.'+_this.htmlClassPrefix+'chat-footer').append( $( redirectAfterSubmitTimerHTML ) ); 3536 3537 if( chatSurveyMessage !== null ){ 3538 chatSurveyMessage.prepend( $( redirectAfterSubmitTimerHTML ) ); 3539 } 3540 3541 var timer = parseInt( _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_delay' ] ) + 2; 3542 _this.timer( timer, { 3543 blockedContent: true, 3544 redirectUrl: redirectUrl, 3545 redirectNewTab: _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_new_tab' ] 3546 }); 3547 } 3548 } else{ 3549 3550 _this.timer( timer, { 3551 blockedContent: true, 3552 redirectUrl: redirectUrl, 3553 redirectNewTab: _this.dbOptions[ _this.dbOptionsPrefix + 'submit_redirect_new_tab' ] 3554 }); 3555 } 3556 } 3557 } 3558 3559 var popupContainer = _this.$el.parents('.ays-survey-popup-survey-window'); 3560 if(typeof popupContainer != 'undefined' && popupContainer.length > 0){ 3561 var dataClosePopup = popupContainer.attr('data-close-popup'); 3562 if(typeof dataClosePopup != 'undefined' && dataClosePopup == 'true'){ 3563 var dataClosePopupDelay = popupContainer.attr('data-close-popup-delay'); 3564 if(typeof dataClosePopupDelay != 'undefined' && dataClosePopupDelay){ 3565 var popupCloseButton = popupContainer.find('.ays-survey-popup-btn-close'); 3566 popupCloseButton.addClass('ays-survey-popup-btn-close-timer'); 3567 var dataClosePopupDelayCount = +dataClosePopupDelay; 3568 if(dataClosePopupDelay > 0){ 3569 var popupCloser = setInterval(function(){ 3570 popupCloseButton.text(dataClosePopupDelayCount); 3571 dataClosePopupDelayCount--; 3572 if(dataClosePopupDelayCount < 0){ 3573 clearInterval(popupCloser); 3574 popupCloseButton.trigger('click'); 3575 } 3576 }, 1000); 3577 }else{ 3578 setInterval(function(){ 3579 popupCloseButton.trigger('click'); 3580 }, 1000); 3581 } 3582 } 3583 } 3584 } 3585 3586 formResults.css({'display':'block'});
3587 _this.$el.find('.'+_this.htmlClassPrefix+'chat-footer').css({'display':'block'}); 3588 }else{ 3589 3590 } 3591 } 3592 3593 AysSurveyPlugin.prototype.aysResetQuiz = function ($quizContainer){ 3594 var cont = $quizContainer.find('div[data-question-id]'); 3595 cont.find('input[type="text"], textarea, input[type="number"], input[type="url"], input[type="email"]').each(function(){ 3596 $(this).val(''); 3597 }); 3598 cont.find('select').each(function(){ 3599 $(this).val(''); 3600 }); 3601 cont.find('select.ays-select').each(function(){ 3602 $(this).val(null).trigger('change'); 3603 }); 3604 cont.find('select option').each(function(){ 3605 $(this).removeAttr('selected'); 3606 }); 3607 cont.find('input[type="radio"], input[type="checkbox"]').each(function(){ 3608 $(this).removeAttr('checked'); 3609 }); 3610 } 3611 3612 AysSurveyPlugin.prototype.aysAutofillData = function (data, currentEl){ 3613 $.ajax({ 3614 url: window.aysSurveyMakerAjaxPublic.ajaxUrl, 3615 method: 'post', 3616 dataType: 'json', 3617 data: data, 3618 success: function (response) { 3619 if(response !== null){ 3620 if( response.data ){ 3621 currentEl.find(".ays-survey-question[data-type='name'] .ays-survey-question-input-box input.ays-survey-input").val(response.data.display_name); 3622 currentEl.find(".ays-survey-question[data-type='email'] .ays-survey-question-input-box input.ays-survey-question-email-input").val(response.data.user_email); 3623 } 3624 } //:last-of-type 3625 } 3626 }); 3627 } 3628 3629 AysSurveyPlugin.prototype.checkSurveyPassword = function(passwordSurvey, isAlert){ 3630 var _this = this; 3631 var activPsw = _this.dbOptions.options.survey_generated_passwords.survey_active_passwords; 3632 var flag = false; 3633 3634 if(_this.dbOptions.options.survey_password_type == 'general'){ 3635 if( _this.dbOptions.options.survey_enable_password && _this.dbOptions.options.survey_password_survey != "" ){ 3636 if( _this.dbOptions.options.survey_password_survey !== passwordSurvey ){ 3637 if(isAlert){ 3638 alert( aysSurveyLangObj.passwordIsWrong ); 3639 } 3640 return false; 3641 } 3642 } 3643 return true; 3644 3645 }else if(_this.dbOptions.options.survey_password_type == 'generated_password'){ 3646 3647 if( _this.dbOptions.options.survey_enable_password && activPsw.length != 0 ){ 3648 3649 for (var activePass in activPsw) { 3650 3651 if(activPsw[activePass] == passwordSurvey){ 3652 flag = true; 3653 break; 3654 } 3655 } 3656 if( flag === false ){ 3657 if(isAlert){ 3658 alert( aysSurveyLangObj.passwordIsWrong ); 3659 } 3660 return false; 3661 } 3662 } 3663 } 3664 3665 // if( _this.dbOptions.options.survey_enable_password && _this.dbOptions.options.survey_password_survey != "" ){ 3666 // if( _this.dbOptions.options.survey_password_survey !== passwordSurvey ){ 3667 3668 // if(isAlert){ 3669 // alert( aysSurveyLangObj.passwordIsWrong ); 3670 // } 3671 3672 // return false; 3673 // } 3674 // } 3675 return true; 3676 } 3677 3678 AysSurveyPlugin.prototype.checkMinVotes = function( item ){ 3679 var _this = this; 3680 var options; 3681 var questionId = item.data('id'); 3682 options = _this.dbOptions[ _this.dbOptionsPrefix + 'checkbox_options' ][questionId]; 3683 if( options.enable_max_selection_count ){ 3684 var allVotesCount = item.find('.' + _this.htmlClassPrefix + 'answer input[type="checkbox"][name^="' + _this.htmlClassPrefix + 'answers"]').length; 3685 var checkedCount = item.find('.' + _this.htmlClassPrefix + 'answer input[type="checkbox"][name^="' + _this.htmlClassPrefix + 'answers"]:checked').length; 3686 var MinVotes = options.min_selection_count; 3687 var MaxVotes = options.max_selection_count; 3688 3689 if(MinVotes > MaxVotes){ 3690 MinVotes = MaxVotes; 3691 } 3692 3693 if(MinVotes > allVotesCount){ 3694 MinVotes = allVotesCount; 3695 } 3696 3697 var errorMessage = ''; 3698 if( MinVotes <= checkedCount ){ 3699 item.find('.' + _this.htmlClassPrefix + 'votes-count-validation-error').hide(); 3700 } 3701 3702 if( MinVotes > checkedCount ){ 3703 errorMessage += '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">'; 3704 errorMessage += '<span>' + aysSurveyLangObj.minimumVotes + ' ' + MinVotes + '</span>'; 3705 item.addClass('ays-has-error'); 3706 item.find('.' + _this.htmlClassPrefix + 'votes-count-validation-error').html(errorMessage); 3707 item.find('.' + _this.htmlClassPrefix + 'votes-count-validation-error').show(); 3708 _this.goToTop( item ); 3709 return false; 3710 }else{ 3711 return true; 3712 } 3713 } 3714 return true; 3715 } 3716 3717 AysSurveyPlugin.prototype.checkOneResponsePerColumn = function( item ) { 3718 var _this = this; 3719 var errorMessage = '<img src="' + aysSurveyMakerAjaxPublic.warningIcon + '" alt="error">'; 3720 errorMessage += '<span>' + aysSurveyLangObj.oneResponsePerColumn + '</span>'; 3721 var hasError = false; 3722 var columnCounts = {}; 3723 3724 // Initialize column counts 3725 item.find('.' + _this.htmlClassPrefix + 'answer-matrix-scale-row').each(function() { 3726 $(this).find('.' + _this.htmlClassPrefix + 'answer-matrix-scale-real-column').each(function(index) { 3727 if (!columnCounts[index]) { 3728 columnCounts[index] = 0; 3729 } 3730 if ($(this).find(':radio').is(':checked')) { 3731 columnCounts[index]++; 3732 } 3733 }); 3734 }); 3735 3736 // Check for errors 3737 $.each(columnCounts, function(index, count) { 3738 if (count > 1) { 3739 hasError = true; 3740 } 3741 }); 3742 3743 // Display or hide error message 3744 if (hasError) { 3745 item.addClass('ays-has-error'); 3746 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').html(errorMessage).show(); 3747 _this.goToTop( item ); 3748 return false; 3749 } else { 3750 item.removeClass('ays-has-error'); 3751 item.find('.' + _this.htmlClassPrefix + 'question-validation-error').html('').hide(); 3752 return true; 3753 } 3754 }; 3755 3756 AysSurveyPlugin.prototype.toggleFullscreen = function (elem) { 3757 var _this = this; 3758 elem = elem || document.documentElement; 3759 if (!document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement) { 3760 _this.aysSurveyFullScreenActivate( elem ); 3761 _this.aysSurveyFullScreenWindowActivator( elem ); 3762 }else{ 3763 _this.aysSurveyFullScreenDeactivate( elem ); 3764 _this.aysSurveyFullScreenWindowDeactivator(); 3765 } 3766 } 3767 3768 AysSurveyPlugin.prototype.aysSurveyFullScreenActivate = function (elem) { 3769 $(elem).css({'background-color':'#fff'}); 3770 $(elem).find('.ays-survey-full-screen-mode .ays-survey-close-full-screen').css({'display':'inline'}); 3771 $(elem).find('.ays-survey-full-screen-mode .ays-survey-open-full-screen').css('display','none'); 3772 $(elem).find('.ays-survey-full-screen-mode').css({'padding-right':'15px'}); 3773 $(elem).css({'overflow':'auto'}); 3774 } 3775 3776 AysSurveyPlugin.prototype.aysSurveyFullScreenDeactivate = function (elem) { 3777 $(elem).css({'background-color':'initial'}); 3778 $(elem).find('.ays-survey-full-screen-mode .ays-survey-open-full-screen').css({'display':'inline'}); 3779 $(elem).find('.ays-survey-full-screen-mode .ays-survey-close-full-screen').css('display','none'); 3780 $(elem).find('.ays-survey-full-screen-mode').css({'padding-right':'0'}); 3781 $(elem).css({'overflow':'initial'}); 3782 } 3783 3784 AysSurveyPlugin.prototype.aysSurveyFullScreenDeactivateAll = function (elem) { 3785 var _this = this; 3786 document.addEventListener('fullscreenchange', function(event) { 3787 if (!document.fullscreenElement) { 3788 var eventTarget = event.target; 3789 if( $( eventTarget ).hasClass('ays-survey-container') ){ 3790 _this.aysSurveyFullScreenDeactivate( eventTarget ); 3791 } 3792 } 3793 }, false); 3794 } 3795 3796 AysSurveyPlugin.prototype.aysSurveyFullScreenWindowActivator = function (elem) { 3797 if (elem.requestFullscreen) { 3798 elem.requestFullscreen(); 3799 }else if (elem.msRequestFullscreen) { 3800 elem.msRequestFullscreen(); 3801 }else if (elem.mozRequestFullScreen) { 3802 elem.mozRequestFullScreen(); 3803 }else if (elem.webkitRequestFullscreen) { 3804 elem.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT); 3805 } 3806 } 3807 3808 AysSurveyPlugin.prototype.aysSurveyFullScreenWindowDeactivator = function () { 3809 if(document.exitFullscreen) { 3810 document.exitFullscreen(); 3811 }else if (document.msExitFullscreen) { 3812 document.msExitFullscreen(); 3813 }else if (document.mozCancelFullScreen) { 3814 document.mozCancelFullScreen(); 3815 }else if (document.webkitExitFullscreen) { 3816 document.webkitExitFullscreen(); 3817 } 3818 } 3819 3820 AysSurveyPlugin.prototype.aysSurveyCheckTextLimit = function(question, options,e,current) { 3821 var $this = current; 3822 var _this = this; 3823 var box = question.find('.ays-survey-question-text-message'); 3824 var questionTextMessage = question.find('.ays-survey-question-text-message-span'); 3825 // Maximum length of a text field 3826 var enable_question_text_max_length = (options.enable_word_limitation && options.enable_word_limitation != "") ? options.enable_word_limitation : false; 3827 // Length 3828 var question_text_max_length = (options.limit_length && options.limit_length != "") ? parseInt(options.limit_length) : ''; 3829 // Limit by 3830 var question_limit_text_type = (options.limit_by && options.limit_by != "") ? options.limit_by : ''; 3831 // Show word/character counter 3832 var question_enable_text_message = (options.limit_counter && options.limit_counter != '') ? options.limit_counter : false; 3833 3834 var remainder = ''; 3835 if(question_text_max_length != '' && question_text_max_length != 0){ 3836 switch ( question_limit_text_type ) { 3837 case 'char': 3838 var tval = $this.val(); 3839 var tlength = tval.length; 3840 var set = question_text_max_length; 3841 var remain = parseInt(set - tlength); 3842 if (remain <= 0 && e.which !== 0 && e.charCode !== 0) { 3843 $this.val((tval).substring(0, tlength - 1)); 3844 } 3845 if (e.type=="keyup") { 3846 var tval = $this.val().trim(); 3847 if(tval.length > 0 && tval != null){ 3848 var wordsLength = $this[0].value.split('').length;
3849 if (wordsLength > question_text_max_length) { 3850 var trimmed = tval.split('', question_text_max_length).join(""); 3851 $this.val(trimmed); 3852 } 3853 } 3854 } 3855 remainder = remain; 3856 break; 3857 case 'word': 3858 if (e.type=="keyup") { 3859 var tval = $this.val().trim(); 3860 if(tval.length > 0 && tval != null){ 3861 var wordsLength = $this[0].value.match(/\S+/g).length; 3862 if (wordsLength > question_text_max_length) { 3863 var trimmed = tval.split(/\s+/, question_text_max_length).join(" "); 3864 $this.val(trimmed + " "); 3865 } 3866 remainder = question_text_max_length - wordsLength; 3867 } 3868 } 3869 break; 3870 default: 3871 break; 3872 } 3873 if (e.type=="keyup") { 3874 if ( question_enable_text_message ) { 3875 if(question_text_max_length != '' && question_text_max_length != 0){ 3876 if (remainder <= 0) { 3877 remainder = 0; 3878 if (! box.hasClass(_this.htmlClassPrefix + ' question-text-error-message') ) { 3879 box.addClass(_this.htmlClassPrefix + 'question-text-error-message') 3880 } 3881 }else{ 3882 if ( box.hasClass(_this.htmlClassPrefix + 'question-text-error-message') ) { 3883 box.removeClass(_this.htmlClassPrefix + 'question-text-error-message') 3884 } 3885 } 3886 if (tval.length == 0 || tval == null) { 3887 if ( box.hasClass(_this.htmlClassPrefix + 'question-text-error-message') ) { 3888 box.removeClass(_this.htmlClassPrefix + 'question-text-error-message') 3889 } 3890 remainder = question_text_max_length; 3891 } 3892 3893 questionTextMessage.html( remainder ); 3894 } 3895 } 3896 } 3897 } 3898 } 3899 3900 AysSurveyPlugin.prototype.aysSurveyCheckNumberLimit = function(question, options,e,current) { 3901 var $this = current; 3902 var _this = this; 3903 var errorBox = question.find('.ays-survey-number-limit-message-box'); 3904 question.removeClass('ays-has-error'); 3905 errorBox.hide(); 3906 var limitBox = question.find('.ays-survey-question-text-message'); 3907 var questionTextMessage = question.find('.ays-survey-question-text-message-span'); 3908 // Enable Limitation 3909 var enableQuestionLimit = (options.enable_number_limitation && options.enable_number_limitation != "") ? options.enable_number_limitation : false; 3910 // Min Value 3911 var questionTextMinValue = (options.number_min_selection && options.number_min_selection != "") ? parseInt(options.number_min_selection) : ''; 3912 // Max Value 3913 var questionTextMaxValue = (options.number_max_selection && options.number_max_selection != "") ? parseInt(options.number_max_selection) : ''; 3914 // Show error message 3915 var enableTextMessage = (options.enable_number_error_message && options.enable_number_error_message != '') ? options.enable_number_error_message : false; 3916 // Max Length 3917 var questionTextMaxLength = (options.number_limit_length && options.number_limit_length != "") ? parseInt(options.number_limit_length) : ''; 3918 // Show char length 3919 var questionEnableTextMessage = (options.enable_number_limit_counter && options.enable_number_limit_counter != '') ? options.enable_number_limit_counter : false; 3920 if(questionTextMinValue >= questionTextMaxValue){ 3921 questionTextMaxValue = questionTextMinValue; 3922 } 3923 if(enableQuestionLimit){ 3924 var remainder = ''; 3925 var showErrorMessage = 0; 3926 if(questionTextMaxLength != '' && questionTextMaxLength != 0){ 3927 var tval = $this.val(); 3928 var tlength = tval.length; 3929 var set = questionTextMaxLength; 3930 var remain = parseInt(set - tlength); 3931 // if (remain <= 0 && e.which !== 0 && e.charCode !== 0) { 3932 // $this.val((tval).substring(0, tlength - 1)); 3933 // } 3934 // if (e.type=="keyup") { 3935 var tval = $this.val().trim(); 3936 if(tval.length > 0 && tval != null){ 3937 3938 var wordsLength = $this[0].value.split('').length;
3939 if (wordsLength > questionTextMaxLength) { 3940 // var trimmed = tval.split('', questionTextMaxLength).join(""); 3941 // $this.val(trimmed); 3942 question.addClass('ays-has-error'); 3943 } 3944 } 3945 // } 3946 remainder = remain; 3947 } 3948 var enteredValue = $this.val().trim(); 3949 var inputValue = parseInt( enteredValue ); 3950 3951 // Check if min value exists and min value not 0 3952 if(questionTextMinValue != '' && questionTextMinValue != 0){ 3953 if( ! isNaN(inputValue) ){ 3954 // if (e.type=="keyup") { 3955 if ( inputValue < questionTextMinValue ) { 3956 // $this.val(questionTextMinValue); 3957 showErrorMessage++; 3958 question.addClass('ays-has-error'); 3959 } 3960 // } 3961 } 3962 } 3963 3964 // Check if min value exists and max value not 0 3965 if(questionTextMaxValue != '' && questionTextMaxValue != 0){ 3966 // if (e.type=="keyup") { 3967 if ( inputValue > questionTextMaxValue ) { 3968 // $this.val(questionTextMaxValue); 3969 showErrorMessage++; 3970 question.addClass('ays-has-error'); 3971 } 3972 // } 3973 } 3974 3975 // Check if min value exists and min value <= 0 3976 if(questionTextMaxValue != '' && questionTextMinValue <= 0){ 3977 if( ! isNaN(inputValue) ){ 3978 // if (e.type=="keyup") { 3979 if ( inputValue < questionTextMinValue ) { 3980 // $this.val(questionTextMinValue); 3981 showErrorMessage++; 3982 question.addClass('ays-has-error'); 3983 } 3984 // } 3985 } 3986 } 3987 // if (e.type=="keyup") { 3988 if ( questionEnableTextMessage ) { 3989 if(questionTextMaxLength != '' && questionTextMaxLength != 0){ 3990 if (remainder <= 0) { 3991 remainder = 0; 3992 if (! limitBox.hasClass(_this.htmlClassPrefix + 'question-text-error-message') ) { 3993 limitBox.addClass(_this.htmlClassPrefix + 'question-text-error-message') 3994 } 3995 }else{ 3996 if ( limitBox.hasClass(_this.htmlClassPrefix + 'question-text-error-message') ) { 3997 limitBox.removeClass(_this.htmlClassPrefix + 'question-text-error-message') 3998 } 3999 } 4000 if (tval.length == 0 || tval == null) { 4001 if ( limitBox.hasClass(_this.htmlClassPrefix + 'question-text-error-message') ) { 4002 limitBox.removeClass(_this.htmlClassPrefix + 'question-text-error-message') 4003 } 4004 remainder = questionTextMaxLength; 4005 } 4006 4007 questionTextMessage.html( remainder ); 4008 } 4009 } 4010 // } 4011 if(enableTextMessage && showErrorMessage > 0){ 4012 errorBox.show(); 4013 } 4014 4015 } 4016 } 4017 4018 4019 AysSurveyPlugin.prototype.collapseQuestion = function($this){ 4020 var _this = this; 4021 var questsCont = $this.parents('.' + _this.htmlClassPrefix + 'question'); 4022 // var questsText = questsCont.find('.' + _this.htmlClassPrefix + 'question-title').attr('value'); 4023 // questsCont.find('.ays-survey-question-wrap-collapsed-action-contnet-text').html( questsText ); 4024 questsCont.find('.ays-survey-question-wrap-collapsed-action').removeClass('ays-survey-display-none'); 4025 questsCont.find('.ays-survey-question-wrap-expanded-action').addClass('ays-survey-display-none'); 4026 } 4027 4028 AysSurveyPlugin.prototype.expandQuestion = function($this){ 4029 var _this = this; 4030 var questsCont = $this.parents('.' + _this.htmlClassPrefix + 'question'); 4031 questsCont.find('.ays-survey-question-wrap-collapsed-action').addClass('ays-survey-display-none'); 4032 questsCont.find('.ays-survey-question-wrap-expanded-action').removeClass('ays-survey-display-none'); 4033 } 4034 4035 AysSurveyPlugin.prototype.uploadFile = function(data, mainBox, fileName){ 4036 var _this = this; 4037 $.ajax({
4038 url: window.aysSurveyMakerAjaxPublic.ajaxUrl, 4039 method: 'post', 4040 dataType: 'json', 4041 data: data, 4042 contentType: false, 4043 processData: false, 4044 success: function (response) { 4045 if(response.status){ 4046 var messageBox = mainBox.find('.' + _this.htmlClassPrefix + 'answer-upload-ready'); 4047 var messageBoxLink = messageBox.find('.' + _this.htmlClassPrefix + 'answer-upload-ready-link'); 4048 var messageBoxHidden = messageBox.find('.' + _this.htmlClassPrefix + 'answer-upload-ready-url-link'); 4049 messageBoxLink.html(fileName); 4050 messageBoxLink.attr("download", fileName); 4051 messageBoxLink.attr("href", response.fileUrl); 4052 messageBoxHidden.val(response.fileUrl); 4053 mainBox.find('.' + _this.htmlClassPrefix + 'answer-upload-type').hide(); 4054 mainBox.find('.' + _this.htmlClassPrefix + 'answer-upload-type-loader').hide(); 4055 mainBox.attr("data-required", false); 4056 messageBox.show(); 4057 } 4058 } 4059 }); 4060 } 4061 4062 AysSurveyPlugin.prototype.checkTermsAndConds = function( item ){ 4063 var _this = this; 4064 var alltermsCondsCount = item.find('.' + _this.htmlClassPrefix + 'is-checked-terms-and-conditions').length; 4065 var checkedTermsConsdCount = item.find('.' + _this.htmlClassPrefix + 'is-checked-terms-and-conditions:checked').length; 4066 if( alltermsCondsCount != checkedTermsConsdCount ){ 4067 if( _this.dbOptions['enable_terms_and_conditions_required_message' ] ){ 4068 item.find('.'+_this.htmlClassPrefix+'section-terms-and-conditions-required-message-content').css( 'display', 'block' ); 4069 } 4070 item.find('.' + _this.htmlClassPrefix + 'is-checked-terms-and-conditions:not(:checked)').next().addClass('ays-has-error'); 4071 return false; 4072 }else{ 4073 return true; 4074 } 4075 } 4076 4077 AysSurveyPlugin.prototype.aysSurveyonTabPress = function() { 4078 var _this = this; 4079 _this.$el.on('keydown', (e) => { 4080 var selectedBox = $(e.target); 4081 if( !selectedBox.hasClass( 'ays-survey-answer-text-inputs' ) && !selectedBox.hasClass( 'ays-survey-chat-short-text-input' )){ 4082 if (e.keyCode === 32) { 4083 e.preventDefault(); 4084 if(selectedBox.hasClass('ays-survey-section-button-container')){ 4085 selectedBox.find('.ays-survey-section-button').trigger("click"); 4086 } 4087 else{ 4088 selectedBox.trigger("click"); 4089 } 4090 } 4091 } 4092 }); 4093 } 4094 4095 AysSurveyPlugin.prototype.radioCheckboxTypesChanges = function( elem, htmlPreffix, options ){ 4096 elem.each(function(index){ 4097 var theme = $(this).data('theme'); 4098 if(theme == 'elegant'){ 4099 elem.eq(index).on('click', '.'+htmlPreffix+'answer-matrix-scale-column-content-wrap, .'+htmlPreffix+'answer', function(){ 4100 if( $(this).parents('.'+ htmlPreffix + theme + '-theme-question').attr('data-type') == 'radio'){ 4101 4102 var check_required = $(this).parents('.' + htmlPreffix + 'question').data('required'); 4103 if(!check_required){ 4104 $(this).parents('.' + htmlPreffix + 'question-answers').find('.' + htmlPreffix + 'answer-clear-selection-container').addClass('in'); 4105 $(this).parents('.' + htmlPreffix + 'question-answers').find('.' + htmlPreffix + 'answer-clear-selection-container').removeClass('out'); 4106 $(this).parents('.' + htmlPreffix + 'question-answers').find('.' + htmlPreffix + 'answer-clear-selection-container').removeClass(htmlPreffix + 'visibility-none'); 4107 } 4108 4109 $(this).parents('.'+ htmlPreffix + 'question-answers').find('.' + htmlPreffix + 'answer-' + theme + '-active').removeClass(htmlPreffix + 'answer-' + theme + '-active'); 4110 $(this).find('input.'+htmlPreffix+'elegant-theme-answers').prop( 'checked', true ); 4111 if($(this).find('input.'+htmlPreffix+'elegant-theme-answers').prop( 'checked')){ 4112 $(this).addClass(htmlPreffix + 'answer-' + theme + '-active'); 4113 } 4114 } 4115 }); 4116 } 4117 4118 elem.eq(index).find('input[type="checkbox"][class*="' + htmlPreffix + theme + '-theme-answers"], input[type="radio"][class^="' + htmlPreffix + theme + '-theme-answers"], .'+ htmlPreffix + 'matrix-scale-checbox-inputs.' + htmlPreffix + theme +'-theme-answers').on('change', function(){ 4119 var thisClick = $(this).prop('checked'); 4120 var thisParentsElegant = $(this).parents('.'+ htmlPreffix + theme + '-theme-style-for-other-answer'); 4121 if(theme == 'business' || theme == 'elegant'){ 4122 if( $(this).parents('.'+ htmlPreffix + theme + '-theme-question').attr('data-type') == 'radio' || $(this).parents('.'+ htmlPreffix + theme + '-theme-question').attr('data-type') == 'linear_scale'){ 4123 $(this).parents('.'+ htmlPreffix + 'question-answers').find('.' + htmlPreffix + 'answer-' + theme + '-active').removeClass(htmlPreffix + 'answer-' + theme + '-active'); 4124 if(thisClick){ 4125 $(this).parents('.'+ htmlPreffix + 'answer-' + theme + '-hover').addClass(htmlPreffix + 'answer-' + theme + '-active'); 4126 } 4127 } 4128 else if( $(this).parents('.'+ htmlPreffix + theme + '-theme-question').attr('data-type') == 'matrix_scale'){ 4129 if(theme == 'elegant'){ 4130 $(this).parents('.'+ htmlPreffix + 'answer-matrix-scale-row-content').find('.'+ htmlPreffix + 'answer-' + theme+ '-active-matrix-scale').removeClass(htmlPreffix + 'answer-' + theme + '-active-matrix-scale'); 4131 if(thisClick){ 4132 $(this).parents('.'+ htmlPreffix + 'answer-' + theme + '-hover').addClass(htmlPreffix + 'answer-' + theme + '-active-matrix-scale'); 4133 } 4134 }else{ 4135 $(this).parents('.'+ htmlPreffix + 'answer-matrix-scale-row-content').find('.'+ htmlPreffix + 'answer-' + theme+ '-active').removeClass(htmlPreffix + 'answer-' + theme + '-active'); 4136 if(thisClick){ 4137 $(this).parents('.'+ htmlPreffix + 'answer-' + theme + '-hover').addClass(htmlPreffix + 'answer-' + theme + '-active'); 4138 } 4139 } 4140 } 4141 else{ 4142 if(thisClick){ 4143 if(theme == 'business'){ 4144 $(this).parents('.'+ htmlPreffix + 'answer-'+theme+'-hover').css({ 4145 'border': '1px solid' + options.survey_text_color, 4146 'background-color': '#f2f2f2', 4147 'border-radius': '7px', 4148 }); 4149 } 4150 4151 if(theme == 'elegant'){ 4152 if( $(this).parents('.'+ htmlPreffix + theme + '-theme-question').attr('data-type') == 'matrix_scale_checkbox'){ 4153 $(this).parents('.'+ htmlPreffix + 'answer-'+theme+'-hover').addClass(htmlPreffix + 'answer-' + theme + '-active-matrix-scale'); 4154 }else{ 4155 $(this).parents('.'+ htmlPreffix + 'answer-'+theme+'-hover').addClass(htmlPreffix + 'answer-' + theme + '-active'); 4156 4157 thisParentsElegant.find('div.'+ htmlPreffix+'answer-other-text').css({ 4158 'background':'#fff', 4159 'display':'block', 4160 }); 4161 thisParentsElegant.find('div.'+ htmlPreffix+'answer-other-text > input.'+htmlPreffix+'answer-other-input').css({ 4162 'caret-color': options.ays_survey_color, 4163 'border-bottom': '1px solid '+options.ays_survey_buttons_bg_color+' !important', 4164 'color': options.ays_survey_color, 4165 'font-size': 'inherit', 4166 'font-family': 'inherit', 4167 'font-weight': 'inherit', 4168 'line-height': 'inherit', 4169 }); 4170 } 4171 } 4172 }else{ 4173 if(theme == 'business'){ 4174 $(this).parents('.'+ htmlPreffix + 'answer-' + theme + '-hover').css({ 4175 'border': '1px solid #00000000', 4176 'background-color': 'unset', 4177 'border-radius': '7px', 4178 }); 4179 } 4180 4181 if(theme == 'elegant'){ 4182 $(this).parents('.' + htmlPreffix + 'answer-' + theme + '-active').removeClass(htmlPreffix + 'answer-' + theme + '-active'); 4183 $(this).parents('.' + htmlPreffix + 'answer-' + theme + '-active-matrix-scale').removeClass(htmlPreffix + 'answer-' + theme + '-active-matrix-scale'); 4184 4185 thisParentsElegant.find('div.'+ htmlPreffix+'answer-other-text').css({ 4186 'display':'none', 4187 }); 4188 thisParentsElegant.find('div.'+ htmlPreffix+'answer-other-text > input.'+htmlPreffix+'answer-other-input').css({ 4189 'background-color':'unset', 4190 }); 4191 4192 } 4193 } 4194 } 4195 } 4196 }); 4197 4198 4199 }); 4200 } 4201 4202 AysSurveyPlugin.prototype.makeThemeQuestionContentActive = function( elem, htmlPreffix, options ){ 4203 elem.each(function(index){ 4204 var theme = $(this).data('theme'); 4205 if( theme == 'elegant' ){ 4206 elem.eq(index).on('click', '.' + htmlPreffix + theme +'-theme-question', function(e){
4207 elem.eq(index).find('.' + htmlPreffix + theme +'-theme-question').removeClass(htmlPreffix + theme + '-theme-question-active'); 4208 $(this).addClass(htmlPreffix + theme + '-theme-question-active'); 4209 4210 } ); 4211 4212 $(document).on('click', function(e){ 4213 if (!elem.eq(index).find('.' + htmlPreffix + theme + '-theme-question').is(e.target) && !elem.eq(index).find('.' + htmlPreffix + theme + '-theme-question').has(e.target).length) { 4214 elem.eq(index).find('.' + htmlPreffix + theme + '-theme-question').removeClass(htmlPreffix + theme +'-theme-question-active'); 4215 } 4216 }); 4217 } 4218 }); 4219 } 4220 4221 AysSurveyPlugin.prototype.listenQuestionText = function( text, voice, rate, pitch, volume, action ){ 4222 if(action == 'play'){ 4223 let speakData = new SpeechSynthesisUtterance(); 4224 speakData.volume = volume; // From 0 to 1 4225 speakData.rate = rate; // From 0.1 to 10 4226 speakData.pitch = pitch; // From 0 to 2 4227 speakData.text = text; 4228 speakData.lang = 'en'; 4229 speakData.voice = voice; 4230 speechSynthesis.speak(speakData); 4231 } 4232 else if (action == 'cancel'){ 4233 speechSynthesis.cancel(); 4234 } 4235 } 4236 4237 AysSurveyPlugin.prototype.requestForEditSubmission = async function( surveyId , thisButton){ 4238 var _this = this; 4239 var action = _this.ajaxAction; 4240 var afunction = 'ays_survey_edit_previous_submission_fn'; 4241 _this.$el.addClass('ays-survey-edit-previous-submission-wait-layer'); 4242 var nextButton = _this.$el.find('.ays-survey-next-button.display_none_important').removeClass('display_none_important'); 4243 nextButton.removeClass('display_none_not_important'); 4244 var responseForLoop; 4245 var responseFlag = false; 4246 var errorMessage; 4247 if(surveyId){ 4248 await $.ajax({
4249 url: window.aysSurveyMakerAjaxPublic.ajaxUrl, 4250 method: 'post', 4251 dataType: 'json', 4252 data: { 4253 action: action, 4254 survey_id: surveyId, 4255 function: afunction 4256 }, 4257 success: function (response) { 4258 if(response.status){ 4259 responseForLoop = response; 4260 responseFlag = true; 4261 } 4262 else{ 4263 errorMessage = response.message; 4264 } 4265 } 4266 }); 4267 if(responseForLoop){ 4268 4269 await _this.preventQuestionAnswers(responseForLoop.questions); 4270 4271 var submissionId = responseForLoop.submission_id; 4272 var userId = responseForLoop.user_id; 4273 var submQuestIdsMatrixTypes = responseForLoop.subm_quest_ids_matrix_types; 4274 4275 var sendData = { 4276 userId : userId, 4277 surveyId : surveyId, 4278 submissionId : submissionId, 4279 subm_quest_ids_matrix_types : submQuestIdsMatrixTypes, 4280 } 4281 4282 var sendDataEncoded = btoa(JSON.stringify(sendData)); 4283 var inputForUpdate = '<input type="hidden" name="ays_survey_update_submission_'+surveyId+'" value="'+sendDataEncoded+'">' 4284 _this.$el.find('.ays-survey-form').append(inputForUpdate); 4285 4286 } 4287 } 4288 _this.$el.removeClass('ays-survey-edit-previous-submission-wait-layer'); 4289 _this.$el.find('.ays-survey-edit-previous-submission-box img.ays-survey-edit-previous-submission-loader').addClass('display_none'); 4290 4291 if(!responseFlag){ 4292 thisButton.removeClass('display_none'); 4293 errorMessage = $('<span class="ays-survey-edit-previous-submission-box-failed ays-survey-edit-previous-submission-box-message">'+errorMessage+'</span>'); 4294 thisButton.parents('.ays-survey-edit-previous-submission-box').prepend(errorMessage); 4295 setTimeout(function() { 4296 errorMessage.fadeOut(500, function() { 4297 errorMessage.remove(); 4298 }); 4299 }, 3000); 4300 } 4301 else{ 4302 _this.$el.find('.ays-survey-edit-previous-submission-box').html('<span class="ays-survey-edit-previous-submission-box-message">' + responseForLoop.message + '</span>'); 4303 } 4304 } 4305 4306 AysSurveyPlugin.prototype.preventQuestionAnswers = function (response) { 4307 if(response.length < 1){ 4308 return; 4309 } 4310 var _this = this; 4311 var inputSimpleTypes = ['radio', 'yesorno', 'checkbox', 'select', 'star', 'linear_scale', 'nps' , 'range']; 4312 var inputTextTypes = ['text', 'short_text', 'number', 'phone', 'date', 'date_time', 'time' , 'email' , 'name', 'upload']; 4313 var inputMatrixTypes = ['matrix_scale', 'matrix_scale_checkbox', 'star_list', 'slider_list']; 4314 var rPromise = new Promise(function(resolve, reject) { 4315 for(var questionId in response){ 4316 var eachQuestion = _this.$el.find('.ays-survey-question[data-id="'+questionId+'"]'); 4317 var questionType = eachQuestion.attr('data-type'); 4318 var eachAnswerBox = eachQuestion.find('.ays-survey-question-answers'); 4319 var uAnswer = ''; 4320 4321 var userExplanation = typeof response[questionId].user_explanation != 'undefined' && response[questionId].user_explanation ? response[questionId].user_explanation : ''; 4322 4323 if(inputSimpleTypes.includes(questionType)){ 4324 uAnswer = response[questionId].answer; 4325 // For checkbox type 4326 if(Array.isArray(uAnswer)){ 4327 $.each(uAnswer, function(i, value){ 4328 eachAnswerBox.find('input[value="'+value+'"]').prop('checked', true); 4329 } ); 4330 } 4331 else{ 4332 eachAnswerBox.find('input[value="'+uAnswer+'"]').prop('checked', true); 4333 } 4334 4335 if(questionType == 'range'){ 4336 var rangeInput = eachAnswerBox.find('input.ays-survey-range-type-input[type="range"]'); 4337 if(rangeInput.length > 0){ 4338 rangeInput.val(uAnswer); 4339 rangeInput.trigger('change'); 4340 rangeInput.trigger('input'); 4341 } 4342 } 4343 4344 if(questionType == 'star'){ 4345 var starInput = eachAnswerBox.find('.ays-survey-answer-star-radio input[value="'+uAnswer+'"]').parents('.ays-survey-answer-label '); 4346 if(starInput.length > 0){ 4347 starInput.trigger('click'); 4348 starInput.trigger("mouseover"); 4349 } 4350 } 4351 4352 if(questionType == 'select'){ 4353 if(uAnswer){ 4354 var selectBox = eachAnswerBox.find(".ays-survey-question-select .menu .item[data-value='"+uAnswer+"']"); 4355 selectBox.trigger("click"); 4356 } 4357 } 4358 4359 } 4360 4361 else if(inputTextTypes.includes(questionType)){ 4362 uAnswer = response[questionId].answer; 4363 4364 var tAnswer = ''; 4365 if(questionType == 'date' || questionType == 'date_time'){ 4366 if(uAnswer){ 4367 var dateParts = uAnswer.split(' '); 4368 uAnswer = dateParts[4] + "-" + dateParts[2] + "-" + dateParts[0]; 4369 tAnswer = (dateParts[5] && dateParts[7]) ? dateParts[5] + ":" + dateParts[7] : ''; 4370 } 4371 } 4372 else if(questionType == 'time'){ 4373 if(uAnswer){ 4374 var dateParts = uAnswer.split(' : '); 4375 tAnswer = dateParts[0] + ":" + dateParts[1]; 4376 } 4377 } 4378 4379 if(tAnswer){ 4380 eachAnswerBox.find('.ays-survey-question-input-box input.ays-survey-timepicker').val(tAnswer); 4381 } 4382 if(uAnswer){ 4383 eachAnswerBox.find('.ays-survey-question-input-box input:not(.ays-survey-timepicker), .ays-survey-question-input-box textarea').val(uAnswer); 4384 } 4385 4386 if(questionType == 'email'){ 4387 eachAnswerBox.find('.ays-survey-question-input-box input[type="hidden"][name*="ays-survey-user-email"]').val(questionId); 4388 } 4389 4390 if(questionType == 'upload'){ 4391 var uAnswerName = response[questionId].answer_name; 4392 if(uAnswer && uAnswerName){ 4393 4394 var uploadBox = eachAnswerBox.find('.ays-survey-answer-upload-type-main'); 4395 var uploadInput = uploadBox.find('input.ays-survey-answer-upload-ready-url-link'); 4396 var uploadLink = uploadBox.find('a.ays-survey-answer-upload-ready-link'); 4397 4398 uploadBox.find('.ays-survey-answer-upload-type').hide(); 4399 uploadBox.find('.ays-survey-answer-upload-ready').show(); 4400 4401 uploadInput.val(uAnswer); 4402 uploadLink.attr('download' , uAnswerName); 4403 uploadLink.attr('href' , uAnswer); 4404 uploadLink.html(uAnswerName); 4405 } 4406 } 4407 } 4408 4409 else if(inputMatrixTypes.includes(questionType)){ 4410 switch(questionType){ 4411 case 'matrix_scale': 4412 case 'matrix_scale_checkbox': 4413 uAnswer = response[questionId].answer_ids; 4414 break; 4415 case 'star_list': 4416 uAnswer = response[questionId].star_list_answer_ids; 4417 break; 4418 case 'slider_list': 4419 uAnswer = response[questionId].slider_list_answer_ids; 4420 break; 4421 } 4422 $.each(uAnswer, function(i, value){ 4423 if(Array.isArray(value)){ 4424 $.each(value, function(innerI, innerValue){ 4425 eachAnswerBox.find('input[name*="'+i+'"][value="'+innerValue+'"]').prop('checked', true); 4426 } ); 4427 } 4428 else{ 4429 eachAnswerBox.find('input[name*="'+i+'"][value="'+value+'"]').prop('checked', true); 4430 eachAnswerBox.find('input[name*="'+i+'"][value="'+value+'"]').parents('.ays-survey-answer-label ').trigger("mouseover"); 4431 eachAnswerBox.find('input[name*="'+i+'"][value="'+value+'"]').parents('.ays-survey-answer-label ').trigger("click"); 4432 4433 eachAnswerBox.find('input.ays-survey-range-type-input[name*="'+i+'"][type="range"]').val(value); 4434 eachAnswerBox.find('input.ays-survey-range-type-input[name*="'+i+'"][type="range"]').trigger('change'); 4435 eachAnswerBox.find('input.ays-survey-range-type-input[name*="'+i+'"][type="range"]').trigger('input'); 4436 } 4437 } ); 4438 } 4439 4440 else if(questionType == 'ranking'){ 4441 uAnswer = response[questionId].answer; 4442 var rAnswerTitles = []; 4443 var answerTitle = 0; 4444 4445 var eachAnswers = eachAnswerBox.find('.ays-survey-ranking-answer-label-content'); 4446 $.each(uAnswer, function(i, value){ 4447 answerTitle = eachAnswerBox.find('.ays-survey-ranking-answer-label-text[data-answer-id="'+value+'"]').text(); 4448 rAnswerTitles.push(answerTitle); 4449 } ); 4450 4451 $.each(eachAnswers, function(i, value){ 4452 $(value).find('.ays-survey-ranking-answer-label-text').text(rAnswerTitles[i]); 4453 $(value).find('.ays-survey-ranking-answer-input').val(uAnswer[i]); 4454 $(value).find('.ays-survey-ranking-answer-label-text').attr('data-answer-id' , uAnswer[i]); 4455 } ); 4456 } 4457 4458 if(userExplanation){ 4459 var userExplanationBox = eachQuestion.find('.ays-survey-user-explanation'); 4460 if(userExplanationBox.length > 0){ 4461 var userExplanationInput = userExplanationBox.find('textarea[name*="ays-survey-user-explanation"]'); 4462 if(userExplanationInput.length > 0){ 4463 userExplanationInput.val(userExplanation); 4464 } 4465 } 4466 } 4467 4468 4469 } 4470 resolve(); 4471 }); 4472 4473 return rPromise; 4474 } 4475 4476 AysSurveyPlugin.prototype.updateRankingType = function(a,b) { 4477 $(a.target).parents('.ays-survey-question').attr('data-required' , false); 4478 } 4479 4480 AysSurveyPlugin.prototype.checkFormAllSections = function( button ){ 4481 var _this = this; 4482 var bool = true; 4483 var allSectionsNextButtons = _this.showAllSections.find('.' + _this.htmlClassPrefix + 'section-button.' + _this.htmlClassPrefix + 'next-button'); 4484 allSectionsNextButtons.each(function(){ 4485 if(! _this.checkForm($(this))){ 4486 bool = false; 4487 return false; 4488 } 4489 }) 4490 return bool; 4491 } 4492 4493 AysSurveyPlugin.prototype.aysAutoNext = function(button) { 4494 var _this = this; 4495 var checkedRadiosCount = 0; 4496 var activeSection = button.parents('.ays-survey-section.active-section'); 4497 4498 var sectionQuestions = activeSection.find('.ays-survey-section-questions .ays-survey-question'); 4499 var sectionQuestionsCount = sectionQuestions.length; 4500 4501 var checkedRadios = sectionQuestions.find('input[type="radio"]:checked'); 4502 checkedRadiosCount += checkedRadios.length; 4503 4504 var changedDropdown = sectionQuestions.find('input.ays-survey-detect-selected-question-dropdown'); 4505 4506 changedDropdown.each(function() { 4507 if ($(this).val().trim() !== '') { 4508 checkedRadiosCount++; 4509 } 4510 }); 4511 4512 var nextButton = activeSection.find('.' + _this.htmlClassPrefix + 'next-button'); 4513 4514 if((checkedRadiosCount >= sectionQuestionsCount) && nextButton.hasClass('display_none_important') && !_this.$el.hasClass('ays-survey-activated-edit-prev-submission')){ 4515 nextButton.trigger('click'); 4516 } 4517 _this.$el.removeClass('ays-survey-activated-edit-prev-submission'); 4518 } 4519 4520 /** 4521 * @return {string} 4522 */ 4523 function AddZero(num) { 4524 return (num >= 0 && num < 10) ? "0" + num : num + ""; 4525 } 4526 4527 /** 4528 * @return {string} 4529 */ 4530 function aysEscapeHtml(text) { 4531 var map = { 4532 '&': '&', 4533 '<': '<', 4534 '>': '>', 4535 '"': '"', 4536 "'": ''' 4537 }; 4538 return text.replace(/[&<>\"']/g, function(m) { return map[m]; }); 4539 } 4540 4541 function validatePhoneNumber(input) { 4542 var phoneno = /^[+ 0-9-]+$/; 4543 if (input.value.match(phoneno)) { 4544 return true; 4545 } else { 4546 return false; 4547 } 4548 } 4549 4550 function setBubble(range, bubble) { 4551 var val = range.value; 4552 var min = range.min ? range.min : 0; 4553 var max = range.max ? range.max : 100; 4554 var newVal = Number( ( ( val - min ) * 100 ) / ( max - min ) ); 4555 bubble.innerHTML = val; 4556 4557 // Sorta magic numbers based on size of the native UI thumb 4558 bubble.style.left = 'calc( ' + newVal + '% + ' + ( 9 - newVal * 0.18 ) + 'px )'; 4559 } 4560 4561 function surveyGetVoices() { 4562 var voices = speechSynthesis.getVoices(); 4563 if(!voices.length){ 4564 var utterance = new SpeechSynthesisUtterance(""); 4565 speechSynthesis.speak(utterance); 4566 voices = speechSynthesis.getVoices(); 4567 } 4568 return voices; 4569 } 4570 4571 $.fn.serializeFormJSON = function () { 4572 var o = {}, 4573 a = this.serializeArray(); 4574 $.each(a, function () { 4575 if (o[this.name]) { 4576 if (!o[this.name].push) { 4577 o[this.name] = [o[this.name]]; 4578 } 4579 o[this.name].push(this.value || ''); 4580 } else { 4581 o[this.name] = this.value || ''; 4582 } 4583 }); 4584 return o; 4585 }; 4586 4587 // Warn if overriding existing method 4588 if(Array.prototype.equals) 4589 console.warn("Overriding existing Array.prototype.equals. Possible causes: New API defines the method, there's a framework conflict or you've got double inclusions in your code."); 4590 4591 // attach the .equals method to Array's prototype to call it on any array 4592 Array.prototype.equals = function (array) {
4593 // if the other array is a falsy value, return 4594 if (!array) 4595 return false; 4596 4597 // compare lengths - can save a lot of time 4598 if (this.length != array.length) 4599 return false; 4600 4601 for (var i = 0, l=this.length; i < l; i++) { 4602 // Check if we have nested arrays 4603 if (this[i] instanceof Array && array[i] instanceof Array) { 4604 // recurse into the nested arrays 4605 if (!this[i].equals(array[i])) 4606 return false; 4607 } 4608 else if (this[i] != array[i]) { 4609 // Warning - two different object instances will never be equal: {x:20} != {x:20} 4610 return false; 4611 } 4612 } 4613 return true; 4614 } 4615 // Hide method from for-in loops 4616 Object.defineProperty(Array.prototype, "equals", {enumerable: false}); 4617 4618 4619 $.fn.AysSurveyMaker = function(options) { 4620 return this.each(function() { 4621 if (!$.data(this, 'AysSurveyMaker')) { 4622 $.data(this, 'AysSurveyMaker', new AysSurveyPlugin(this, options)); 4623 } else { 4624 try { 4625 $(this).data('AysSurveyMaker').init(); 4626 } catch (err) { 4627 console.error('AysSurveyMaker has not initiated properly'); 4628 } 4629 } 4630 }); 4631 }; 4632 4633})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.