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