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

survey-maker-admin.js in Survey Maker by AYS 5.2.2.4, at admin/js/survey-maker-admin.js

4,032 lines 226.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function( $ ) {
2 'use strict';
3 $.fn.serializeFormJSON = function () {
4 let o = {},
5 a = this.serializeArray();
6 $.each(a, function () {
7 if (o[this.name]) {
8 if (!o[this.name].push) {
9 o[this.name] = [o[this.name]];
10 }
11 o[this.name].push(this.value || '');
12 } else {
13 o[this.name] = this.value || '';
14 }
15 });
16 return o;
17 };
18
19 $.fn.goToTop = function() {
20 this.get(0).scrollIntoView({
21 block: "center",
22 behavior: "smooth"
23 });
24 }
25
26 $.fn.goTo = function() {
27 $('html, body').animate({
28 scrollTop: this.offset().top - 200 + 'px'
29 }, 'fast');
30 return this; // for chaining...
31 }
32
33 $.fn.goToNormal = function() {
34 $('html, body').animate({
35 scrollTop: this.offset().top - 200 + 'px'
36 }, 'normal');
37 return this; // for chaining...
38 }
39
40 $(document).ready(function () {
41
42 var maxInputVarsPannelBox = $(document).find('.ays-survey-general-action-max-inps-vars');
43 var maxInputVarsTabsBox = $(document).find('.ays-survey-max-inp-vars-tabs-box');
44 var maxInputVars = +maxInputVarsPannelBox.attr('data-max-inp-vars');
45 if(typeof maxInputVars != 'undefined' && maxInputVars){
46 var filledInputs = +$(':input').filter(function() {return this.value;}).length;
47
48 var calcVarsDiff = maxInputVars - filledInputs;
49 if(calcVarsDiff <= 200){
50 if(calcVarsDiff <= 0){
51 filledInputs = maxInputVars
52 }
53 maxInputVarsPannelBox.removeClass('display_none');
54 maxInputVarsTabsBox.removeClass('display_none');
55 var varsMessageText = SurveyMakerAdmin.maxInputVarsWarningMessage;
56 varsMessageText = varsMessageText.replace(/%f/g, maxInputVars);
57 varsMessageText = varsMessageText.replace(/%t/g, filledInputs);
58 maxInputVarsPannelBox.attr('data-content' , varsMessageText);
59 maxInputVarsTabsBox.find('.ays-survey-max-inp-vars-texts-content').text(varsMessageText);
60 }
61 }
62
63
64 setInterval(function () {
65 $('div.ays-quiz-maker-wrapper h1 i.ays_fa').toggleClass('pulse');
66 $(document).find('.ays_heart_beat i.ays_fa').toggleClass('ays_pulse');
67 }, 1000);
68
69
70 // Disabling submit when press enter button on inputing
71 $(document).on("input", 'input', function(e){
72 if(e.keyCode == 13){
73 if($(document).find("#ays-survey-form").length !== 0 ||
74 $(document).find("#ays-survey-category-form").length !== 0 ||
75 $(document).find("#ays-survey-settings-form").length !== 0){
76 return false;
77 }
78 }
79 });
80
81 $(document).on("keydown", function(e){
82 if(e.target.nodeName == "TEXTAREA"){
83 return true;
84 }
85 if(e.keyCode == 13){
86 if($(document).find("#ays-survey-form").length !== 0 ||
87 $(document).find("#ays-survey-category-form").length !== 0 ||
88 $(document).find("#ays-survey-settings-form").length !== 0){
89 return false;
90 }
91 }
92
93 if ( ( e.ctrlKey && e.which == 83 ) && !( e.which == 19 ) ){
94 var saveButton = $(document).find("input#ays-button-apply, input.ays-survey-gen-settings-save");
95 if( saveButton.length > 0 ){
96 e.preventDefault();
97 saveButton.trigger("click");
98 }
99 return false;
100 }
101
102 if(e.keyCode === 27){
103 $(document).find('.ays-modal').aysModal('hide');
104 return false;
105 }
106 });
107
108 var answerAddedByEnter = false;
109 $(document).on("keyup", ".ays-survey-answers-conteiner .ays-survey-answer-box input.ays-survey-input", function(e){
110 answerAddedByEnter = false;
111 });
112
113 $(document).on("focus", ".ays-survey-answers-conteiner .ays-survey-answer-box input.ays-survey-input", function(e){
114 var _this = $(this);
115 setTimeout(function(){
116 _this.get(0).setSelectionRange(0, _this.get(0).value.length);
117 // _this.select();
118 }, 1);
119 });
120
121 $(document).on("keydown", ".ays-survey-answers-conteiner .ays-survey-answer-box input.ays-survey-input", function(e){
122 if( answerAddedByEnter === false ) {
123 answerAddedByEnter = true;
124
125 if(e.keyCode === 13){
126 aysSurveyAddAnswer( $(this), true );
127 }
128
129 if(e.keyCode == 38 && !e.ctrlKey && !e.shiftKey ){
130 var ansCont = $(this).parents('.ays-survey-answer-row');
131 if( ansCont.prev().length > 0 ){
132 ansCont.prev().find(".ays-survey-answer-box input.ays-survey-input").trigger('focus');
133 }else{
134 return false;
135 }
136 }
137
138 if(e.keyCode === 40 && !e.ctrlKey && !e.shiftKey ){
139 var ansCont = $(this).parents('.ays-survey-answer-row');
140 if( ansCont.next().length > 0 ){
141 ansCont.next().find(".ays-survey-answer-box input.ays-survey-input").trigger('focus');
142 }else{
143 var questCont = $(this).parents('.ays-survey-question-answer-conteiner');
144 questCont.find('.ays-survey-action-add-answer').trigger('click');
145 }
146 }
147
148 if(e.keyCode === 8){
149 if( $(this).val() == '' ){
150 var thatNext = $(this).parents('.ays-survey-answer-row').next().find('input.ays-survey-input');
151 var thatPrev = $(this).parents('.ays-survey-answer-row').prev().find('input.ays-survey-input');
152 if( thatPrev.length > 0 ){
153 thatPrev.trigger('focus');
154 $(this).parents('.ays-survey-answer-row').find('.ays-survey-answer-delete').trigger('click');
155 }else if( thatNext.length > 0 ){
156 thatNext.trigger('focus');
157 $(this).parents('.ays-survey-answer-row').find('.ays-survey-answer-delete').trigger('click');
158 }
159 return false;
160 }
161 }
162
163 if(e.keyCode === 46){
164 if( $(this).val() == '' ){
165 var thatNext = $(this).parents('.ays-survey-answer-row').next().find('input.ays-survey-input');
166 var thatPrev = $(this).parents('.ays-survey-answer-row').prev().find('input.ays-survey-input');
167 if( thatNext.length > 0 ){
168 thatNext.trigger('focus');
169 $(this).parents('.ays-survey-answer-row').find('.ays-survey-answer-delete').trigger('click');
170 }else if( thatPrev.length > 0 ){
171 thatPrev.trigger('focus');
172 $(this).parents('.ays-survey-answer-row').find('.ays-survey-answer-delete').trigger('click');
173 }
174 return false;
175 }
176 }
177 }
178 });
179
180 // Notifications dismiss button
181 var $html_name_prefix = 'ays_';
182 $(document).on('click', '.notice-dismiss', function (e) {
183 changeCurrentUrl('status');
184 });
185
186 if(location.href.indexOf('del_stat')){
187 setTimeout(function(){
188 changeCurrentUrl('del_stat');
189 changeCurrentUrl('mcount');
190 }, 500);
191 }
192
193 var aysSurveyTextArea = $(document).find('textarea.ays-survey-question-input-textarea');
194 autosize(aysSurveyTextArea);
195 var aysSurveyDescriptionTextArea = $(document).find('textarea.ays-survey-section-description');
196 autosize(aysSurveyDescriptionTextArea);
197
198
199 function changeCurrentUrl(key){
200 var linkModified = location.href.split('?')[1].split('&');
201 for(var i = 0; i < linkModified.length; i++){
202 if(linkModified[i].split("=")[0] == key){
203 linkModified.splice(i, 1);
204 }
205 }
206 linkModified = linkModified.join('&');
207 window.history.replaceState({}, document.title, '?'+linkModified);
208 }
209
210 // Quiz toast close button
211 jQuery('.quiz_toast__close').click(function(e){
212 e.preventDefault();
213 var parent = $(this).parent('.quiz_toast');
214 parent.fadeOut("slow", function() { $(this).remove(); } );
215 });
216
217 var toggle_ddmenu = $(document).find('.toggle_ddmenu');
218 toggle_ddmenu.on('click', function () {
219 var ddmenu = $(this).next();
220 var state = ddmenu.attr('data-expanded');
221 switch (state) {
222 case 'true':
223 $(this).find('.ays_fa').css({
224 transform: 'rotate(0deg)'
225 });
226 ddmenu.attr('data-expanded', 'false');
227 break;
228 case 'false':
229 $(this).find('.ays_fa').css({
230 transform: 'rotate(90deg)'
231 });
232 ddmenu.attr('data-expanded', 'true');
233 break;
234 }
235 });
236
237 var ays_results = $(document).find('.ays_result_read');
238 for (var i in ays_results) {
239 if (typeof ays_results.eq(i).val() != 'undefined') {
240 if ( ays_results.eq(i).val() == 0 || ays_results.eq(i).val() == 2 ) {
241 ays_results.eq(i).parents('tr').addClass('ays_read_result');
242 }
243 }
244 }
245
246 // Check if save button closed for unsaved changes confirmation box
247 var subButtons = '#ays_apply_top.button, #ays_apply.button, #ays_submit_top.button, #ays_submit.button, #ays-button-save-new-top.button, #ays-button-save-new.button, #ays-button-apply-top.button, #ays-button-apply.button, #ays-button-save-new-top.button, #ays-button-save-new.button, #ays-button-save.button, #ays-button-save-top.button, #ays-button.button';
248 $(document).on('click', subButtons ,function () {
249 var $this = $(this);
250 if(!$this.hasClass('ays-save-button-clicked')){
251 $this.addClass('ays-save-button-clicked');
252 }
253 });
254
255 setTimeout(function() {
256 var aysUnsavedChanges = false;
257
258 var selectorsArr = [
259 '#ays-survey-form .ays-survey-tab-content input',
260 '#ays-survey-form .ays-survey-tab-content select',
261 '#ays-survey-form .ays-survey-tab-content textarea',
262 '#ays-survey-category-form .ays-survey-tab-content input',
263 '#ays-survey-category-form .ays-survey-tab-content select',
264 '#ays-survey-category-form .ays-survey-tab-content textarea',
265 '#ays-survey-popup-surveys-form .ays-survey-tab-content input',
266 '#ays-survey-popup-surveys-form .ays-survey-tab-content select',
267 '#ays-survey-popup-surveys-form .ays-survey-tab-content textarea',
268 '#ays-survey-settings-form input',
269 '#ays-survey-settings-form select',
270 '#ays-survey-settings-form textarea',
271 ];
272
273 var formInputs = selectorsArr.join(',');
274
275 $(document).on('change input', formInputs, function() {
276 aysUnsavedChanges = true;
277 });
278
279 $(window).on('beforeunload', function(event) {
280 var saveButtons = $(document).find('#ays_apply_top.button, #ays_apply.button, #ays_submit_top.button, #ays_submit.button, #ays-button-save-new-top.button, #ays-button-save-new.button, #ays-button-apply-top.button, #ays-button-apply.button, #ays-button-save-new-top.button, #ays-button-save-new.button, #ays-button-save.button, #ays-button-save-top.button, #ays-button.button');
281 var savingButtonsClicked = saveButtons.filter('.ays-save-button-clicked').length > 0;
282
283 if (aysUnsavedChanges && !savingButtonsClicked) {
284 event.preventDefault();
285 event.returnValue = true;
286 }
287 });
288 }, 1000);
289
290
291 // $('[data-toggle="popover"]').popover();
292
293 $(document).find('.ays-survey-sections-conteiner [data-toggle="popover"]').popover();
294 $(document).find('.aysFormeditorViewFatRoot [data-toggle="popover"]').popover();
295 $(document).find('.ays_survey_previous_next [data-toggle="popover"]').popover();
296 $('[data-toggle="tooltip"]').tooltip();
297
298 $(document).find('.ays_survey_aysDropdown').aysDropdown();
299 $(document).find('[data-toggle="dropdown"]').dropdown();
300 // $('.dropdown-toggle').dropdown()
301
302 // Disabling submit when press enter button on inputing
303 $(document).on("input", 'input', function(e){
304 if(e.keyCode == 13){
305 if($(document).find("#ays-question-form").length !== 0 ||
306 $(document).find("#ays-survey-category-form").length !== 0 ||
307 $(document).find("#ays-survey-settings-form").length !== 0){
308 return false;
309 }
310 }
311 });
312
313 $(document).find('strong.ays-survey-shortcode-box.ays_survey_each_sub_user_info_header_button button').on('mouseleave', function(){
314 var _this = $(this);
315
316 _this.attr( 'data-original-title', SurveyMakerAdmin.clickForCopy );
317 _this.attr( 'title', SurveyMakerAdmin.clickForCopy );
318 });
319
320 // Modal close
321
322 $(document).find('.ays-close').on('click', function () {
323 $(document).find('.ays-modal').aysModal('hide');
324 });
325
326 $(document).find('.ays-close-editor-popup').on('click', function () {
327 $(document).find('.ays-modal').aysEditorModal('hide');
328 });
329
330 $(document).find('.ays-close-templates-popup').on('click', function (e) {
331 var $this = $(this);
332 var dataAction = $this.attr('data-action');
333 if(dataAction && dataAction !== 'ays-close-templates'){
334 e.preventDefault();
335 $(document).find('#ays-survey-templates-modal').aysModal('hide');
336 }
337
338 });
339
340 $(document).find('.ays-close-pro-popup').on('click', function () {
341 $(this).parents('.ays-modal').aysModal('hide_remove_video');
342 });
343
344
345 $(document).on('change', '.ays_toggle_checkbox', function (e) {
346 var state = $(this).prop('checked');
347 var parent = $(this).parents('.ays_toggle_parent');
348
349 if($(this).hasClass('ays_toggle_slide')){
350 switch (state) {
351 case true:
352 parent.find('.ays_toggle_target').slideDown(250);
353 break;
354 case false:
355 parent.find('.ays_toggle_target').slideUp(250);
356 break;
357 }
358 }else{
359 switch (state) {
360 case true:
361 parent.find('.ays_toggle_target').show(250);
362 break;
363 case false:
364 parent.find('.ays_toggle_target').hide(250);
365 break;
366 }
367 }
368 });
369
370 $(document).on('change', '.ays_toggle_select', function (e) {
371 var state = $(this).val();
372 var toggle = $(this).data('hide');
373 var parent = $(this).parents('.ays_toggle_parent');
374
375 if($(this).hasClass('ays_toggle_slide')){
376 if (toggle == state) {
377 parent.find('.ays_toggle_target').slideUp(250);
378 parent.find('.ays_toggle_target_inverse').slideDown(150);
379 }else{
380 parent.find('.ays_toggle_target').slideDown(150);
381 parent.find('.ays_toggle_target_inverse').slideUp(250);
382 }
383 }else{
384 if (toggle == state) {
385 parent.find('.ays_toggle_target').hide(150);
386 parent.find('.ays_toggle_target_inverse').show(250);
387 }else{
388 parent.find('.ays_toggle_target').show(250);
389 parent.find('.ays_toggle_target_inverse').hide(150);
390 }
391 }
392 });
393
394
395 $(document).find('#ays-category').select2({
396 placeholder: 'Select category'
397 });
398
399 $(document).find('#ays-status').select2({
400 placeholder: 'Select status'
401 });
402
403 // Tab documentation links data
404 var tabDocsData = {
405 'tab1': {
406 'link': 'https://ays-pro.com/wordpress-survey-maker-user-manual#survey-maker-1-1-general',
407 'text': SurveyMakerAdmin.generalTabDoc
408 },
409 'tab2': {
410 'link': 'https://ays-pro.com/wordpress-survey-maker-user-manual#survey-maker-1-2-styles',
411 'text': SurveyMakerAdmin.stylesTabDoc
412 },
413 'tab3': {
414 'link': 'https://ays-pro.com/wordpress-survey-maker-user-manual#survey-maker-1-4-settings',
415 'text': SurveyMakerAdmin.settingsTabDoc
416 },
417 'tab4': {
418 'link': 'https://ays-pro.com/wordpress-survey-maker-user-manual#survey-maker-1-5-results-settings',
419 'text': SurveyMakerAdmin.resultsSettingsTabDoc
420 },
421 'tab5': {
422 'link': 'https://ays-pro.com/wordpress-survey-maker-user-manual#survey-maker-1-7-limitation-users',
423 'text': SurveyMakerAdmin.limitationUsersTabDoc
424 },
425 'tab6': {
426 'link': 'https://ays-pro.com/wordpress-survey-maker-user-manual#survey-maker-1-3-start-page',
427 'text': SurveyMakerAdmin.userDataTabDoc
428 },
429 'tab7': {
430 'link': 'https://ays-pro.com/wordpress-survey-maker-user-manual#survey-maker-1-8-e-mail',
431 'text': SurveyMakerAdmin.emailTabDoc
432 },
433 'tab8': {
434 'link': 'https://ays-pro.com/instructions-for-survey-maker-plugin-integrations',
435 'text': SurveyMakerAdmin.integrationTabDoc
436 },
437 'tab9': {
438 'link': 'https://ays-pro.com/wordpress-survey-maker-user-manual#survey-maker-1-6-conditional-result',
439 'text': SurveyMakerAdmin.conditionsTabDoc
440 },
441 };
442
443
444 // Tabulation
445 $(document).find('.nav-tab-wrapper a.nav-tab').on('click', function (e) {
446 if(! $(this).hasClass('no-js')){
447 var elemenetID = $(this).attr('href');
448 var active_tab = $(this).attr('data-tab');
449 $(document).find('.nav-tab-wrapper a.nav-tab').each(function () {
450 if ($(this).hasClass('nav-tab-active')) {
451 $(this).removeClass('nav-tab-active');
452 }
453 });
454 $(this).addClass('nav-tab-active');
455 $(document).find('.ays-survey-tab-content').each(function () {
456 $(this).css('display', 'none');
457 });
458 $(document).find("[name='ays_survey_tab']").val(active_tab);
459 $('.ays-survey-tab-content' + elemenetID).css('display', 'block');
460
461 // Update documentation link based on active tab
462 var docLinkContainer = $(document).find('#ays-survey-tab-doc-link .ays-survey-doc-link');
463 if (docLinkContainer.length > 0) {
464 if (tabDocsData[active_tab]) {
465 docLinkContainer.attr('href', tabDocsData[active_tab].link);
466 docLinkContainer.find('span').text(tabDocsData[active_tab].text);
467 docLinkContainer.show();
468 } else {
469 docLinkContainer.hide();
470 }
471 }
472
473 e.preventDefault();
474 }
475 });
476
477
478 // Survey category form submit
479 // Checking the issues
480 $(document).find('#ays-survey-category-form').on('submit', function(e){
481 var submitFlag = true;
482 if($(document).find('#ays-title').val() == ''){
483 $(document).find('#ays-title').val('Survey category').trigger('input');
484 submitFlag = false;
485 }
486
487 var $this = $(this)[0];
488 if( submitFlag ){
489 $this.submit();
490 }else{
491 // e.preventDefault();
492 // $this.submit();
493 }
494 });
495
496 // Survey form submit
497 // Checking the issues
498 $(document).find('#ays-survey-form').on('submit', function(e){
499 var $this = $(this)[0];
500 var submitFlag = true;
501 if($(document).find('#ays-survey-title').val() == ''){
502 $(document).find('#ays-survey-title').val('Survey').trigger('input');
503 // submitFlag = false;
504 }
505
506 // $(document).find('.ays-survey-section-title').each(function(){
507 // if( $(this).val() == ''){
508 // $(this).val('Untitled section').trigger('input');
509 // // submitFlag = false;
510 // }
511 // });
512
513 if( submitFlag ){
514 $this.submit();
515 }else{
516 // e.preventDefault();
517 // $this.submit();
518 }
519 });
520
521 $(document).find('.ays-survey-copy-image').on('click', function(){
522 var _this = this;
523 var input = $(_this).parent().find('input.ays-survey-shortcode-input');
524 var length = input.val().length;
525
526 input[0].focus();
527 input[0].setSelectionRange(0, length);
528 document.execCommand('copy');
529 // document.getSelection().removeAllRanges();
530
531 $(_this).attr('data-original-title', SurveyMakerAdmin.copied);
532 $(_this).attr("data-bs-original-title", SurveyMakerAdmin.copied);
533 $(_this).attr("title", SurveyMakerAdmin.copied);
534 $(_this).tooltip('show');
535 });
536
537 $(document).find('.ays-survey-copy-image').on('mouseleave', function(){
538 var _this = this;
539
540 $(_this).attr('data-original-title', SurveyMakerAdmin.clickForCopy);
541 $(_this).attr("data-bs-original-title", SurveyMakerAdmin.clickForCopy);
542 $(_this).attr("title", SurveyMakerAdmin.clickForCopy);
543 });
544
545 // Submit buttons disableing with loader
546 $(document).find('.ays-survey-loader-banner').on('click', function () {
547 var $this = $(this);
548 submitOnce($this);
549 });
550
551 function submitOnce(subButton){
552 var subLoader = subButton.parents('div').find('.ays_survey_loader_box');
553 if ( subLoader.hasClass("display_none") ) {
554 subLoader.removeClass("display_none");
555 }
556 subLoader.css({
557 "padding-left": "8px",
558 "display": "inline-block"
559 });
560
561 setTimeout(function() {
562 $(document).find('.ays-survey-loader-banner').attr('disabled', true);
563 }, 10);
564
565 setTimeout(function() {
566 $(document).find('.ays-survey-loader-banner').attr('disabled', false);
567 subButton.parents('div').find('.ays_survey_loader_box').css('display', 'none');
568 }, 5000);
569
570 }
571
572 // Delete confirmation
573 $(document).on('click', '.ays_confirm_del', function(e){
574 e.preventDefault();
575 var message = $(this).data('message');
576 var confirm = window.confirm('Are you sure you want to delete '+message+'?');
577 if(confirm === true){
578 window.location.replace($(this).attr('href'));
579 }
580 });
581
582 // FILTERS FOR LIST TABEL
583 $(document).find('.ays-survey-question-tab-all-filter-button-top, .ays-survey-question-tab-all-filter-button-bottom').on('click', function(e){
584 e.preventDefault();
585 var $this = $(this);
586 var parent = $this.parents('.tablenav');
587 var link = location.href;
588
589 var html_name = '';
590 var top_or_bottom = 'top';
591
592 if ( parent.hasClass('bottom') ) {
593 top_or_bottom = 'bottom';
594 }
595
596 var catFilter = $(document).find('select[name="filterby-'+ top_or_bottom +'"]').val();
597 var userFilter = $(document).find('select[name="filterbyuser-'+ top_or_bottom +'"]').val();
598 var filterbyDescriptionFilter = $(document).find('select[name="filterbyDescription-'+ top_or_bottom +'"]').val();
599
600 if(typeof catFilter != "undefined"){
601 link = catFilterForListTable(link, {
602 what: 'filterby',
603 value: catFilter
604 });
605 }
606 if(typeof userFilter != "undefined"){
607 link = catFilterForListTable(link, {
608 what: 'filterbyuser',
609 value: userFilter
610 });
611 }
612 if(typeof filterbyDescriptionFilter != "undefined"){
613 link = catFilterForListTable(link, {
614 what: 'filterbyDescription',
615 value: filterbyDescriptionFilter
616 });
617 }
618 if($(this).hasClass('ays-survey-question-filter-each-submission')){
619 link = catFilterForListTable(link, {
620 what: 'ays_survey_tab',
621 value: 'poststuff'
622 });
623 }
624 document.location.href = link;
625 });
626
627 function catFilterForListTable(link, options){
628 if( options.value != '' ){
629 options.value = "&" + options.what + "=" + options.value;
630 var linkModifiedStart = link.split('?')[0];
631 var linkModified = link.split('?')[1].split('&');
632 for(var i = 0; i < linkModified.length; i++){
633 if(linkModified[i].split("=")[0] == options.what){
634 linkModified.splice(i, 1);
635 }
636 }
637 linkModified = linkModified.join('&');
638 return linkModifiedStart + "?" + linkModified + options.value;
639 }else{
640 var linkModifiedStart = link.split('?')[0];
641 var linkModified = link.split('?')[1].split('&');
642 for(var i = 0; i < linkModified.length; i++){
643 if(linkModified[i].split("=")[0] == options.what){
644 linkModified.splice(i, 1);
645 }
646 }
647 linkModified = linkModified.join('&');
648 return linkModifiedStart + "?" + linkModified;
649 }
650 }
651
652 $(document).on('change', '#import_file', function(e){
653 var pattern = /(.csv|.xlsx|.json)$/g;
654 if(pattern.test($(this).val())){
655 $(this).parents('form').find('input[name="ays_survey_import"]').removeAttr('disabled')
656 }
657 });
658
659
660 // Add Image
661 $(document).on('click', '.ays-survey-add-image', function (e) {
662 openMediaUploaderForImage(e, $(this));
663 });
664
665 // Remove Image
666 $(document).on('click', '.removeImage', function (e) {
667 var $this = $(this);
668 $this.parents('.ays-survey-image-container').find('.ays-survey-image-body').fadeOut(500);
669 $this.parents('.ays-survey-image-container').find('.ays-survey-add-image').text( SurveyMakerAdmin.addImage );
670 setTimeout(function(){
671 $(document).find("#ays_survey_logo_enable_image_url").prop("checked" , false);
672 $this.parents('.ays-survey-image-container').parent().find('.ays-survey-logo-open-close').hide();
673 $this.parents('.ays-survey-image-container').parent().find('.ays-survey-logo-open').hide();
674 $this.parents('.ays-survey-image-container').find('.ays-survey-img').removeAttr('src');
675 $this.parents('.ays-survey-image-container').find('.ays-survey-img-src').val('');
676 $(document).find('.ays-survey-logo-url-box').addClass('display_none_not_important');
677 }, 500);
678 });
679
680 /////////////////////////////////////////////////////////////////////////////////////////////
681 /////////////////////////////////////ARO START///////////////////////////////////////////////
682 /////////////////////////////////////////////////////////////////////////////////////////////
683 /////////////////////////////////////////////////////////////////////////////////////////////
684
685 function aysSurveyQuestionSortableHelper( event ) {
686 var clone = $(event.target).parents('.ays-survey-question-answer-conteiner').clone(true, true);
687 clone.find('.ays-survey-question-image-container').remove();
688 clone.find('.ays-survey-other-answer-and-actions-row').remove();
689 clone.find('.ays-survey-answers-conteiner').html('<div class="ays-survey-sortable-ect">…</div>');
690 return clone;
691 }
692
693 // Auto-scroll functionality for drag and drop
694 var autoScrollTimer = null;
695 var autoScrollSpeed = 10; // pixels per scroll
696 var autoScrollZone = 50; // pixels from edge to trigger scroll
697
698 function startAutoScroll(direction) {
699 if (autoScrollTimer) return; // Already scrolling
700
701 autoScrollTimer = setInterval(function() {
702 var currentScroll = $(window).scrollTop();
703 var newScroll = currentScroll + (direction * autoScrollSpeed);
704
705 // Ensure we don't scroll beyond document bounds
706 var maxScroll = $(document).height() - $(window).height();
707 newScroll = Math.max(0, Math.min(newScroll, maxScroll));
708
709 $(window).scrollTop(newScroll);
710 }, 16); // ~60fps
711 }
712
713 function stopAutoScroll() {
714 if (autoScrollTimer) {
715 clearInterval(autoScrollTimer);
716 autoScrollTimer = null;
717 }
718 }
719
720 function handleAutoScroll(event, ui) {
721 var mouseY = event.clientY || (event.originalEvent && event.originalEvent.clientY);
722 var windowHeight = $(window).height();
723
724 if (!mouseY) return;
725
726 // Check if mouse is near top or bottom of viewport
727 if (mouseY < autoScrollZone) {
728 // Near top - scroll up
729 startAutoScroll(-1);
730 } else if (mouseY > windowHeight - autoScrollZone) {
731 // Near bottom - scroll down
732 startAutoScroll(1);
733 } else {
734 // In middle zone - stop scrolling
735 stopAutoScroll();
736 }
737 }
738
739 var sectionDragHandle = {
740 handle: '.ays-survey-section-dlg-dragHandle',
741 appendTo: "parent",
742 cursor: 'move',
743 opacity: 0.8,
744 axis: 'y',
745 placeholder: 'ays-survey-sortable-placeholder',
746 tolerance: "pointer",
747 revert: true,
748 forcePlaceholderSize: true,
749 forceHelperSize: true,
750 // helper: aysSurveyQuestionSortableHelper,
751 sort: function(e, ui){
752 ui.placeholder.css('height', ui.helper.height());
753 handleAutoScroll(e, ui); // Add auto-scroll functionality
754 },
755 update: function( event, ui ){
756 var sortableContainer = $(event.target);
757 var sections = sortableContainer.find('.ays-survey-section-box');
758 sections.each(function(i){
759 $(this).find('.ays-survey-section-ordering').val(i+1);
760 $(this).find('.ays-survey-section-number').text(i+1);
761 });
762 },
763 stop: function(e, ui) {
764 stopAutoScroll(); // Stop auto-scroll when dragging ends
765 }
766 };
767
768 var questionDragHandle = {
769 handle: '.ays-survey-question-dlg-dragHandle',
770 appendTo: "parent",
771 cursor: 'move',
772 opacity: 0.8,
773 axis: 'y',
774 placeholder: 'ays-survey-sortable-placeholder',
775 tolerance: "pointer",
776 revert: true,
777 forcePlaceholderSize: true,
778 forceHelperSize: true,
779 helper: aysSurveyQuestionSortableHelper,
780 connectWith: '.ays-survey-sections-conteiner .ays-survey-section-questions',
781 sort: function(e, ui){
782 ui.placeholder.css('height', ui.helper.height());
783 handleAutoScroll(e, ui); // Add auto-scroll functionality
784 },
785 receive: function( event, ui ){
786 var section = $(event.target).parents('.ays-survey-section-box');
787 var oldSection = ui.sender.parents('.ays-survey-section-box');
788 draggedQuestionUpdate( ui.item, section, oldSection);
789 },
790 update: function( event, ui ){
791 var sortableContainer = $(event.target);
792 var oldSection = false;
793 if(ui.sender != null){
794 oldSection = ui.sender.parents('.ays-survey-section-box');
795 }
796 var questions = sortableContainer.find('.ays-survey-question-answer-conteiner');
797 if( questions.length == 0 ){
798 swal.fire({
799 type: 'warning',
800 text: SurveyMakerAdmin.minimumCountOfQuestions
801 });
802 setTimeout(function(){
803 draggedQuestionUpdate( ui.item, sortableContainer.parents('.ays-survey-section-box'), oldSection );
804 }, 1);
805 return false;
806 }
807 questions.each(function(i){
808 $(this).find('.ays-survey-question-ordering').val(i+1);
809 });
810 },
811 stop: function(e, ui) {
812 stopAutoScroll(); // Stop auto-scroll when dragging ends
813 }
814 };
815
816 var answerDragHandle = {
817 handle: '.ays-survey-answer-dlg-dragHandle',
818 cursor: 'move',
819 opacity: 0.8,
820 axis: 'y',
821 placeholder: 'clone',
822 tolerance: "pointer",
823 helper: "clone",
824 revert: true,
825 forcePlaceholderSize: true,
826 forceHelperSize: true,
827 sort: function(e, ui){
828 handleAutoScroll(e, ui); // Add auto-scroll functionality
829 },
830 update: function( event, ui ){
831 var sortableContainer = $(event.target);
832 var answers = sortableContainer.find('.ays-survey-answer-row');
833 answers.each(function(i){
834 $(this).find('.ays-survey-answer-ordering').val(i+1);
835 });
836 },
837 stop: function(e, ui) {
838 stopAutoScroll(); // Stop auto-scroll when dragging ends
839 }
840 }
841 // Answers ordering jQuery UI
842 $(document).find('.ays-survey-sections-conteiner .ays-survey-answers-conteiner').sortable(answerDragHandle);
843 // Question ordering jQuery UI
844 $(document).find('.ays-survey-sections-conteiner .ays-survey-section-questions').sortable(questionDragHandle);
845 // Question ordering jQuery UI
846 $(document).find('.ays-survey-sections-conteiner').sortable(sectionDragHandle);
847
848 // Collapse All
849 $(document).on('click', '.ays-survey-collapse-all', function (e) {
850 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
851 var sections = sectionCont.find('.ays-survey-section-box');
852 sections.each(function(){
853 var section = $(this);
854 section.find('.ays-survey-action-collapse-question').each(function(){
855 collapseQuestion( $(this) );
856 });
857 collapseSection( section.find('.ays-survey-action-collapse-section') );
858 });
859 });
860
861 // Expand All
862 $(document).on('click', '.ays-survey-expand-all', function (e) {
863 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
864 var sections = sectionCont.find('.ays-survey-section-box');
865 sections.each(function(){
866 var section = $(this);
867 section.find('.ays-survey-action-collapse-question').each(function(){
868 expandQuestion( $(this) );
869 });
870 expandSection( section.find('.ays-survey-action-expand-section') );
871 });
872 });
873
874 // Collapse Section Questions
875 $(document).on('click', '.ays-survey-collapse-sec-quests', function (e) {
876 var $this = $(this);
877 var section = $this.parents('.ays-survey-section-box');
878 section.find('.ays-survey-action-collapse-question').each(function(){
879 collapseQuestion( $(this) );
880 });
881 });
882
883 // Collapse Section Questions
884 $(document).on('click', '.ays-survey-section-questions-required', function (e) {
885 makeAllQuestionsRequired($(this) , true);
886 });
887
888 // Expand Section Questions
889 $(document).on('click', '.ays-survey-expand-sec-quests', function (e) {
890 var $this = $(this);
891 var section = $this.parents('.ays-survey-section-box');
892 section.find('.ays-survey-action-collapse-question').each(function(){
893 expandQuestion( $(this) );
894 });
895 });
896
897 // Collapse Question
898 $(document).on('click', '.ays-survey-action-collapse-question', function (e) {
899 var $this = $(this);
900 collapseQuestion( $this );
901 });
902
903 // Expand Question
904 $(document).on('click', '.ays-survey-action-expand-question, .ays-survey-question-wrap-collapsed-contnet', function (e) {
905 var $this = $(this);
906
907 if(!$(e.target).hasClass('dropdown-item')){
908 expandQuestion( $this );
909 }
910 });
911
912 // Collapse Section
913 $(document).on('click', '.ays-survey-action-collapse-section', function (e) {
914 var $this = $(this);
915 collapseSection( $this );
916 });
917
918 // Expand Section
919 $(document).on('click', '.ays-survey-action-expand-section', function (e) {
920 var $this = $(this);
921 expandSection( $this );
922 });
923
924
925 function collapseQuestion( _this ){
926 var questsCont = _this.parents('.ays-survey-question-answer-conteiner');
927 var questsText = questsCont.find('.ays-survey-question-input-textarea').val();
928 questsCont.find('.ays-survey-question-wrap-collapsed-contnet-text').text( questsText );
929 questsCont.find('.ays-survey-question-wrap-collapsed').removeClass('display_none');
930 questsCont.find('.ays-survey-question-wrap-expanded').addClass('display_none');
931 questsCont.find('.ays-survey-question-collapsed-input').val('collapsed');
932 aysSurveySectionsInitQuestionsCollapse();
933 }
934
935 function expandQuestion( _this ){
936 var questsCont = _this.parents('.ays-survey-question-answer-conteiner');
937 questsCont.find('.ays-survey-question-wrap-collapsed').addClass('display_none');
938 questsCont.find('.ays-survey-question-wrap-expanded').removeClass('display_none');
939 questsCont.find('.ays-survey-question-collapsed-input').val('expanded');
940 aysSurveySectionsInitQuestionsCollapse();
941 aysAutosizeUpdate();
942 }
943
944 function collapseSection( _this ){
945 var sectionCont = _this.parents('.ays-survey-section-box');
946 var sectionText = sectionCont.find('.ays-survey-section-title').val();
947 sectionCont.find('.ays-survey-section-wrap-collapsed-contnet-text').text( sectionText );
948 sectionCont.find('.ays-survey-section-wrap-collapsed').removeClass('display_none');
949 sectionCont.find('.ays-survey-section-wrap-expanded').addClass('display_none');
950 sectionCont.find('.ays-survey-section-collapsed-input').val('collapsed');
951 }
952
953 function expandSection( _this ){
954 var sectionCont = _this.parents('.ays-survey-section-box');
955 sectionCont.find('.ays-survey-section-wrap-collapsed').addClass('display_none');
956 sectionCont.find('.ays-survey-section-wrap-expanded').removeClass('display_none');
957 sectionCont.find('.ays-survey-section-collapsed-input').val('expanded');
958 aysAutosizeUpdate();
959 }
960
961 function aysAutosizeUpdate(){
962 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
963 var aysSurveyQuestionTextArea = sectionCont.find('textarea.ays-survey-question-input-textarea');
964 var aysSurveySectionDescriptionTextArea = sectionCont.find('textarea.ays-survey-section-description');
965 autosize.update(aysSurveyQuestionTextArea);
966 autosize.update(aysSurveySectionDescriptionTextArea);
967 }
968
969 // Add Question and Answer Image
970 $(document).on('click', '.ays-survey-add-question-image, .ays-survey-add-answer-image', function (e) {
971 var dataType = $(this).data('type');
972 openMediaUploader(e, $(this), dataType);
973 });
974
975 // Add Answer Button
976 $(document).on('click', '.ays-survey-action-add-answer', function(e){
977 var $this = $(this);
978 aysSurveyAddAnswer( $this, false );
979 });
980
981 // Delete Answer Button
982 $(document).on('click', '.ays-survey-answer-delete', function(e){
983 var $this = $(this);
984 var itemId = $this.parents('.ays-survey-question-answer-conteiner').data('id');
985 var answerId = $this.parents('.ays-survey-answer-row').data('id');
986 var length = $this.parents('.ays-survey-answers-conteiner').find('.ays-survey-answer-delete').length - 1;
987 var parent = $this.parents('.ays-survey-answers-conteiner');
988 var hideDeleteButton = parent.find('.ays-survey-answer-delete');
989
990 if(length == 1){
991 hideDeleteButton.css('visibility','hidden');
992 }else{
993 hideDeleteButton.removeAttr('style');
994 }
995 if( ! $this.parents('.ays-survey-answer-row').hasClass('ays-survey-new-answer') ){
996 var delImp = '<input type="hidden" name="'+ $html_name_prefix +'answers_delete[]" value="'+ answerId +'">';
997 $this.parents('form').append( delImp );
998 }
999
1000 $this.parents('.ays-survey-answer-row [data-toggle="popover"]').popover('hide');
1001 $this.parents('.ays-survey-answer-row').remove();
1002
1003 parent.find('.ays-survey-answer-ordering').each(function(i){
1004 $(this).val( i + 1 );
1005 });
1006 });
1007
1008 // Add "Other" Answer
1009 $(document).on('click', '.ays-survey-other-answer-add', function(e){
1010 var $this = $(this);
1011 var parent = $this.parents('.ays-survey-question-answer-conteiner');
1012 var checkbox = parent.find('.ays-survey-other-answer-checkbox').attr('checked', 'checked');
1013 var oterAnswer = parent.find('.ays-survey-other-answer-row');
1014 oterAnswer.removeAttr('style');
1015 $this.parents('.ays-survey-other-answer-add-wrap').css('display','none');
1016 });
1017
1018 // Delete "Other" Answer
1019 $(document).on('click', '.ays-survey-other-answer-delete', function(e){
1020 var $this = $(this);
1021 var parent = $this.parents('.ays-survey-question-answer-conteiner');
1022 var checkbox = parent.find('.ays-survey-other-answer-checkbox').removeAttr('checked');
1023 var oterAnswer = parent.find('.ays-survey-other-answer-row');
1024 oterAnswer.css('display','none');
1025 parent.find('.ays-survey-other-answer-add-wrap').removeAttr('style');
1026 });
1027
1028 // Dublicate Question Button
1029 $(document).on('click', '.ays-survey-action-duplicate-question', function(e){
1030 var $this = $(this);
1031 var sectionId = $this.parents('.ays-survey-section-box').attr('data-id');
1032 var thisSection = $this.parents('.ays-survey-section-box');
1033 var sectionName = $this.parents('.ays-survey-section-box').attr('data-name');
1034 var cloningElement = $this.parents('.ays-survey-question-answer-conteiner');
1035 var itemId = cloningElement.data('id');
1036 var question_length = cloningElement.parent().find('.ays-survey-question-answer-conteiner').length + 1;
1037 var question_type = cloningElement.find('.ays-survey-question-conteiner .ays-survey-question-type').aysDropdown('get value');
1038
1039 // var questionsCount = questionsLength;
1040 var questionsCountBox = thisSection.find(".ays-survey-action-questions-count span").text(question_length);
1041
1042 cloningElement.find('.ays-survey-question-type').aysDropdown('destroy');
1043 var clonedLimitBy = cloningElement.find('.ays-survey-question-word-limit-by-select select').val();
1044
1045 var clone = cloningElement.clone(true, false).attr('data-id', question_length).addClass('ays-survey-new-question').insertAfter( cloningElement );
1046 var newElement = $this.parents('.ays-survey-section-box').find('.ays-survey-question-answer-conteiner.ays-survey-new-question[data-id = '+ question_length +']');
1047
1048 newElement.attr('data-id', question_length);
1049 newElement.data('id', question_length);
1050 newElement.attr('data-name', 'questions_add');
1051 newElement.find('input[name="ays_question_ids[]"]').remove();
1052 newElement.find('textarea.ays-survey-question-input.ays-survey-input').attr( 'name', newQuestionAttrName( sectionName, sectionId, question_length, 'title') );
1053 newElement.find('input.ays-survey-question-img-src').attr( 'name', newQuestionAttrName( sectionName, sectionId, question_length, 'image') );
1054 newElement.find('input.ays-survey-input-required-question').attr( 'name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'required') );
1055 newElement.find('input.ays-survey-question-ordering').attr( 'name', newQuestionAttrName( sectionName, sectionId, question_length, 'ordering') );
1056 newElement.find('input.ays-survey-question-collapsed-input').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'collapsed'));
1057 newElement.find('input.ays-survey-other-answer-checkbox').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'user_variant') );
1058 newElement.find('.ays-survey-question-max-selection-count-checkbox').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'enable_max_selection_count'));
1059 newElement.find('.ays-survey-question-max-selection-count input.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'max_selection_count'));
1060 newElement.find('.ays-survey-question-min-selection-count input.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'min_selection_count'));
1061 // Text limitation options
1062 newElement.find('.ays-survey-question-word-limitations-checkbox').attr('name', newQuestionAttrName(sectionName, sectionId, question_length, 'options', 'enable_word_limitation'));
1063 newElement.find('.ays-survey-question-more-option-wrap-limitations .ays-survey-question-word-limit-by-select select').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'limit_by'));
1064 newElement.find('.ays-survey-question-more-option-wrap-limitations input.ays-survey-limit-length-input').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'limit_length'));
1065 newElement.find('.ays-survey-question-more-option-wrap-limitations .ays-survey-text-limitations-counter-input').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'limit_counter'));
1066 // Number limitation options start
1067 newElement.find('.ays-survey-question-number-limitations-checkbox').attr('name', newQuestionAttrName(sectionName, sectionId, question_length, 'options', 'enable_number_limitation'));
1068 newElement.find('.ays-survey-question-number-limitations input.ays-survey-number-min-votes').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'number_min_selection'));
1069 newElement.find('.ays-survey-question-number-limitations input.ays-survey-number-max-votes').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'number_max_selection'));
1070 newElement.find('.ays-survey-question-number-limitations input.ays-survey-number-error-message').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'number_error_message'));
1071 newElement.find('.ays-survey-question-number-limitations input.ays-survey-number-enable-error-message').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'enable_number_error_message'));
1072 newElement.find('.ays-survey-question-number-limitations input.ays-survey-number-limit-length').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'number_limit_length'));
1073 newElement.find('.ays-survey-question-number-limitations input.ays-survey-number-number-limit-length').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'enable_number_limit_counter'));
1074 // Number limitation options end
1075
1076 newElement.find('.ays-survey-question-admin-note-saver').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'enable_admin_note'));
1077 newElement.find('.ays-survey-question-admin-note-label input.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'admin_note'));
1078
1079 // Star start
1080 newElement.find('select.ays-survey-choose-for-select-lenght').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'scale_length'));
1081 newElement.find('input.ays-survey-input-star-1').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'star_1'));
1082 newElement.find('input.ays-survey-input-star-2').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'star_2'));
1083 newElement.find('select.ays-survey-choose-for-start-select-lenght').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'star_scale_length'));
1084 // Star end
1085
1086 // Input types placeholders
1087 newElement.find('.ays-survey-remove-default-border.ays-survey-question-types-input.ays-survey-question-types-input-with-placeholder').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'placeholder'));
1088
1089 newElement.find('input.ays-survey-question-image-caption').attr( 'name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'image_caption') );
1090 newElement.find('input.ays-survey-question-img-caption-enable').attr( 'name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'image_caption_enable') );
1091
1092 newElement.find('.ays-survey-open-question-editor-flag').attr('name', newQuestionAttrName( sectionName, sectionId, question_length, 'options', 'with_editor'));
1093 if( newElement.find('select.ays-survey-question-type').length ){
1094 newElement.find('select.ays-survey-question-type').attr( 'name', newQuestionAttrName( sectionName, sectionId, question_length, 'type') );
1095 }else if( newElement.find('.ays-survey-question-type select').length ){
1096 newElement.find('.ays-survey-question-type select').attr( 'name', newQuestionAttrName( sectionName, sectionId, question_length, 'type') );
1097 }
1098 var ddElem = newElement.find('.ays-survey-question-conteiner .ays-survey-question-type').aysDropdown('get text');
1099 newElement.find('.ays-survey-question-conteiner .ays-survey-question-type').aysDropdown('set text', ddElem);
1100 newElement.find('.ays-survey-question-conteiner .ays-survey-question-type select option[value="'+question_type+'"]').prop('selected', true);
1101 // newElement.find('.ays-survey-question-conteiner .ays-survey-question-type').aysDropdown('set selected', question_type);
1102 newElement.find('.ays_question_ids').val(question_length);
1103 newElement.find('.ays_question_old_ids').remove();
1104
1105 var answer = newElement.find('.ays-survey-answers-conteiner .ays-survey-answer-box input.ays-survey-input').each(function(i){
1106 $(this).parents('.ays-survey-answer-row').attr( 'data-id', i+1 );
1107 $(this).parents('.ays-survey-answer-row').attr( 'data-name', 'answers_add' );
1108 $(this).parents('.ays-survey-answer-row').addClass('ays-survey-new-answer');
1109 $(this).attr('name', newAnswerAttrName( sectionName, sectionId, newElement.attr('data-name'), question_length, i+1, 'title') );
1110 $(this).parents('.ays-survey-answer-row').find('.ays-survey-answer-img-src').attr('name', newAnswerAttrName( sectionName, sectionId, newElement.attr('data-name'), question_length, i+1, 'image') );
1111 $(this).parents('.ays-survey-answer-row').find('.ays-survey-answer-ordering').attr('name', newAnswerAttrName( sectionName, sectionId, newElement.attr('data-name'), question_length, i+1, 'ordering') );
1112 });
1113
1114 newElement.find('.ays-survey-answers-conteiner').sortable(answerDragHandle);
1115 newElement.find('.ays-survey-question-word-limit-by-select select option[value="'+clonedLimitBy+'"]').prop('selected', true);
1116
1117 if( question_type == 'select' ){
1118 newElement.find('.ays-survey-other-answer-row').hide();
1119 newElement.find('.ays-survey-other-answer-checkbox').prop('checked', false );
1120 newElement.find('.ays-survey-other-answer-add-wrap').hide();
1121 }
1122
1123 newElement.find('.ays-survey-question-type').aysDropdown();
1124 cloningElement.find('.ays-survey-question-type').aysDropdown();
1125
1126 var aysSurveyTextArea = newElement.find('textarea.ays-survey-question-input-textarea');
1127 autosize(aysSurveyTextArea);
1128 if( newElement.find('.dropdown .divider').length == 0 ){
1129 newElement.find('.dropdown .item[data-value="email"]').before('<div class="divider"></div>');
1130 newElement.find('.dropdown .item[data-value="matrix_scale"]').before('<div class="divider"></div>');
1131 }
1132 if( cloningElement.find('.dropdown .divider').length == 0 ){
1133 cloningElement.find('.dropdown .item[data-value="email"]').before('<div class="divider"></div>');
1134 cloningElement.find('.dropdown .item[data-value="matrix_scale"]').before('<div class="divider"></div>');
1135 }
1136 $this.parents('.ays-survey-section-box').find('.ays-survey-question-ordering').each(function(i){
1137 $(this).val(i+1);
1138 });
1139 // newElement.find('.ays-survey-question-type').dropdown('refresh');
1140 // var answerImg = newElement.find('.aysFormeditorAnswerConteiner input.quantumWizTextinputSimpleinputInput').each(function(i){
1141 // $(this).attr('name', $html_name_prefix + 'section_add['+ sectionId +'][question]['+ question_length +'][answer]['+ i +'][title]');
1142 // });
1143
1144 setTimeout(function(){
1145 newElement.goToTop();
1146 }, 100 );
1147
1148 reInitPopovers( newElement );
1149 aysSurveySectionsInitQuestionsCollapse();
1150 });
1151
1152 // Remove Question Button
1153 $(document).on('click', '.ays-survey-action-delete-question', function(e){
1154 var $this = $(this);
1155 var length = $this.parents('.ays-survey-section-questions').find('.ays-survey-question-answer-conteiner').length;
1156 var status = true;
1157 if(length == 1){
1158 swal.fire({
1159 type: 'warning',
1160 text: SurveyMakerAdmin.minimumCountOfQuestions
1161 });
1162 status = false;
1163 }else{
1164 swal({
1165 html:"<h4>"+ SurveyMakerAdmin.questionDeleteConfirmation +"</h4>",
1166 type: 'error',
1167 showCloseButton: true,
1168 showCancelButton: true,
1169 allowOutsideClick: true,
1170 allowEscapeKey: true,
1171 allowEnterKey: true,
1172 confirmButtonColor: '#d33',
1173 cancelButtonColor: '#3085d6',
1174 confirmButtonText: SurveyMakerAdmin.yes,
1175 cancelButtonText: SurveyMakerAdmin.cancel
1176 }).then( function(result) {
1177
1178 if( result.dismiss && result.dismiss == 'close' ){
1179 return false;
1180 }
1181
1182 var deleteQuest = false;
1183 if (result.value) deleteQuest = true;
1184
1185 if( deleteQuest ){
1186 if( ! $this.parents('.ays-survey-question-answer-conteiner').hasClass('ays-survey-new-question') ){
1187 var qId = $this.parents('.ays-survey-question-answer-conteiner').data('id');
1188 var delImp = '<input type="hidden" name="'+ $html_name_prefix +'questions_delete[]" value="'+ qId +'">';
1189 $this.parents('form').append( delImp );
1190 }
1191 var section = $this.parents('.ays-survey-section-box');
1192 section.find(".ays-survey-action-questions-count span").text(length - 1);
1193 $this.parents('.ays-survey-question-answer-conteiner').remove();
1194 }
1195 } );
1196 }
1197
1198 if (status == false) {
1199 e.preventDefault();
1200 }
1201
1202 });
1203
1204 // Remove Section Button
1205 $(document).on('click', '.ays-survey-delete-section', function(e){
1206 var $this = $(this);
1207
1208 swal({
1209 html:"<h4>"+ SurveyMakerAdmin.sectionDeleteConfirmation +"</h4>",
1210 type: 'error',
1211 showCloseButton: true,
1212 showCancelButton: true,
1213 allowOutsideClick: true,
1214 allowEscapeKey: true,
1215 allowEnterKey: true,
1216 confirmButtonColor: '#d33',
1217 cancelButtonColor: '#3085d6',
1218 confirmButtonText: SurveyMakerAdmin.yes,
1219 cancelButtonText: SurveyMakerAdmin.cancel
1220 }).then( function(result) {
1221
1222 if( result.dismiss && result.dismiss == 'close' ){
1223 return false;
1224 }
1225
1226 var deleteQuest = false;
1227 if (result.value) deleteQuest = true;
1228
1229 if( deleteQuest ){
1230 var parent = $this.parents('.ays-survey-section-box');
1231 if( ! parent.hasClass('ays-survey-new-section') ){
1232 var sId = parent.data('id');
1233 var delImp = '<input type="hidden" name="'+ $html_name_prefix +'sections_delete[]" value="'+ sId +'">';
1234 $this.parents('form').append( delImp );
1235 }
1236 parent.remove();
1237
1238 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
1239 var sections = sectionCont.find('.ays-survey-section-box');
1240 var addQuestionButton = $(document).find('.ays-survey-general-action[data-action="add-question"]');
1241
1242 var length = sectionCont.find('.ays-survey-section-box').length;
1243 sections.each(function(i, el){
1244 $(this).find('.ays-survey-section-number').text(i+1);
1245 $(this).find('.ays-survey-sections-count').text( sections.length );
1246 });
1247
1248 if (length == 1) {
1249 addQuestionButton.dropdown('dispose');
1250 addQuestionButton.removeAttr('data-toggle');
1251 sections.find('.ays-survey-section-head-top').addClass('display_none');
1252 sections.find('.ays-survey-section-head').removeClass('ays-survey-section-head-topleft-border-none');
1253 sections.find('.ays-survey-section-actions-more .ays-survey-delete-section').addClass('display_none');
1254 }
1255
1256 aysSurveySectionsInitToAddQuestions();
1257 }
1258 } );
1259 });
1260
1261 // Remove Answer Image
1262 $(document).on('click', '.removeAnswerImage', function (e) {
1263 var $this = $(this);
1264 $this.parents('.ays-survey-answer-image-container').fadeOut(500);
1265 setTimeout(function(){
1266 $this.parents('.ays-survey-answer-image-container').find('.ays-survey-answer-img').removeAttr('src');
1267 $this.parents('.ays-survey-answer-image-container').find('.ays-survey-answer-img-src').val('');
1268 }, 500);
1269 });
1270
1271 // Survey Question Image actions Buttons
1272 $(document).on('click', '.ays-survey-question-img-action', function(e){
1273 var $this = $(this);
1274
1275 var action = $this.attr('data-action');
1276
1277 switch( action ){
1278 case 'edit-image':
1279 $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-add-question-image').trigger('click');
1280 break;
1281 case 'delete-image':
1282 $this.parents('.ays-survey-question-image-container').fadeOut(500);
1283 setTimeout(function(){
1284 $this.parents('.ays-survey-question-image-container').find('.ays-survey-question-img').removeAttr('src');
1285 $this.parents('.ays-survey-question-image-container').find('.ays-survey-question-img-src').val('');
1286 }, 500);
1287 break;
1288 case 'add-caption':
1289 $this.parents('.ays-survey-question-image-container').find('.ays-survey-question-image-caption-text-row').removeClass('display_none');
1290 $this.parents('.ays-survey-question-image-container').find('.ays-survey-question-img-caption-enable').val('on');
1291 $this.parents('.ays-survey-question-image-container').find('.ays-survey-input.ays-survey-question-image-caption').focus();
1292 $this.attr('data-action' , 'close-caption');
1293 $this.text(SurveyMakerAdmin.closeQuestionImageCaption);
1294 break;
1295 case 'close-caption':
1296 $this.parents('.ays-survey-question-image-container').find('.ays-survey-question-image-caption-text-row').addClass('display_none');
1297 $this.parents('.ays-survey-question-image-container').find('.ays-survey-question-img-caption-enable').val('off');
1298 $this.attr('data-action' , 'add-caption');
1299 $this.text(SurveyMakerAdmin.addQuestionImageCaption);
1300 break;
1301 }
1302 });
1303
1304 // Survey General actions Buttons
1305 $(document).on('click', '.ays-survey-general-action', function(e){
1306 var $this = $(this);
1307 var action = $this.data('action');
1308 switch( action ){
1309 case 'add-question':
1310 if(! $this.attr('data-toggle')){
1311 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
1312 var sections = sectionCont.find('.ays-survey-section-box');
1313 aysSurveyAddQuestion( sections.data('id'), false, sections );
1314 }
1315 break;
1316 case 'import-question':
1317
1318 break;
1319 case 'add-section-header':
1320
1321 break;
1322 case 'add-image':
1323
1324 break;
1325 case 'add-video':
1326
1327 break;
1328 case 'add-section':
1329 aysSurveyAddSection( null, null );
1330 aysSurveySectionsInitToAddQuestions();
1331 break;
1332 case 'save-changes':
1333 $(document).find('#ays-button-apply-top').trigger('click');
1334 break;
1335 case 'make-questions-required':
1336 makeAllQuestionsRequired($this , false);
1337 break;
1338 }
1339 });
1340
1341 // Survey Question actions Buttons
1342 $(document).on('click', '.ays-survey-question-action', function(e){
1343 var $this = $(this);
1344 var action = $this.attr('data-action');
1345 var $thisEl = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-max-selection-count,.ays-survey-question-min-selection-count');
1346 var $thisWordEl = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-word-limitations');
1347 var $thisNumberEl = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-number-limitations');
1348 var enableNumberLimit = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-number-limitations-checkbox');
1349
1350 var currentSection = $this.parents('.ays-survey-section-box');
1351 var currentQuestion = $this.parents('.ays-survey-question-answer-conteiner');
1352 var sectionId = currentSection.attr('data-id');
1353 var sectionName = currentSection.attr('data-name');
1354 var questionId = currentQuestion.attr('data-id');
1355 var questionName = currentQuestion.attr('data-name');
1356
1357 switch( action ){
1358 case 'max-selection-count-enable':
1359 var enableCheckbox = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-max-selection-count-checkbox');
1360 enableCheckbox.prop('checked', true);
1361 $thisEl.removeClass('display_none');
1362 $this.attr('data-action', 'max-selection-count-disable');
1363 break;
1364 case 'max-selection-count-disable':
1365 var enableCheckbox = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-max-selection-count-checkbox');
1366 enableCheckbox.prop('checked', false);
1367 $thisEl.addClass('display_none');
1368 $this.attr('data-action', 'max-selection-count-enable');
1369 break;
1370 case 'word-limitation-enable':
1371 var enableTextLimit = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-word-limitations-checkbox');
1372 enableTextLimit.prop('checked', true);
1373 $thisWordEl.removeClass('display_none');
1374 $this.attr('data-action', 'word-limitation-disable');
1375 break;
1376 case 'word-limitation-disable':
1377 var enableTextLimit = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-word-limitations-checkbox');
1378 enableTextLimit.prop('checked', false);
1379 $thisWordEl.addClass('display_none');
1380 $this.attr('data-action', 'word-limitation-enable');
1381 break;
1382 case 'number-word-limitation-enable':
1383 enableNumberLimit.prop('checked', true);
1384 $thisNumberEl.removeClass('display_none');
1385 $this.attr('data-action', 'number-word-limitation-disable');
1386 break;
1387 case 'number-word-limitation-disable':
1388 enableNumberLimit.prop('checked', false);
1389 $thisNumberEl.addClass('display_none');
1390 $this.attr('data-action', 'number-word-limitation-enable');
1391 break;
1392 case 'move-to-section':
1393 var popup = $(document).find('#ays-survey-move-to-section');
1394 popup.attr('data-section-id', sectionId);
1395 popup.attr('data-section-name', sectionName);
1396 popup.attr('data-question-id', questionId);
1397 popup.attr('data-question-name', questionName);
1398 aysSurveySectionsInitToMoveQuestions( currentSection, currentQuestion );
1399 popup.aysModal('show');
1400 break;
1401 case 'enable-admin-note':
1402 var parentQuestion = $this.parents('.ays-survey-question-answer-conteiner');
1403 var enableCheckbox = parentQuestion.find('.ays-survey-question-admin-note-saver');
1404 parentQuestion.find('.ays-survey-question-admin-note').removeClass('display_none');
1405 enableCheckbox.val('on');
1406 $this.find('.ays-survey-question-action-icon').removeClass('display_none');
1407 $this.attr('data-action', 'disable-admin-note');
1408 break;
1409 case 'disable-admin-note':
1410 var parentQuestion = $this.parents('.ays-survey-question-answer-conteiner');
1411 var enableCheckbox = parentQuestion.find('.ays-survey-question-admin-note-saver');
1412 parentQuestion.find('.ays-survey-question-admin-note').addClass('display_none');
1413 enableCheckbox.val('off');
1414 $this.find('.ays-survey-question-action-icon').addClass('display_none');
1415 $this.attr('data-action', 'enable-admin-note');
1416 break;
1417 }
1418 });
1419
1420 $(document).on('show.bs.dropdown', '.ays-survey-question-more-actions', function(e){
1421 // var $this = $(this);
1422 // var enableCheckbox = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-max-selection-count-checkbox');
1423 // if( enableCheckbox.prop('checked') == true ){
1424 // $this.find('.ays-survey-question-action[data-action^="max-selection-count"]').text(SurveyMakerAdmin.disableMaxSelectionCount);
1425 // }else{
1426 // $this.find('.ays-survey-question-action[data-action^="max-selection-count"]').text(SurveyMakerAdmin.enableMaxSelectionCount);
1427 // }
1428
1429 // if( $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-type').aysDropdown( 'get value' ) == 'checkbox' ){
1430 // $this.find('.ays-survey-question-action[data-action^="max-selection-count"]').removeClass('display_none');
1431 // }
1432 var $this = $(this);
1433 // var question = $this.parents('.ays-survey-question-answer-conteiner');
1434 var questionType = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-type').aysDropdown( 'get value' );
1435 var enableCheckbox = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-max-selection-count-checkbox');
1436 var enableWordLimit = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-word-limitations-checkbox');
1437 var enableNumberLimit = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-question-number-limitations-checkbox');
1438 if( enableCheckbox.prop('checked') == true ){
1439 $this.find('.ays-survey-question-action[data-action^="max-selection-count"]').text(SurveyMakerAdmin.disableSelectionCount);
1440 }else{
1441 $this.find('.ays-survey-question-action[data-action^="max-selection-count"]').text(SurveyMakerAdmin.enableSelectionCount);
1442 }
1443
1444 if( questionType == 'checkbox' ){
1445 $this.find('.ays-survey-question-action[data-action^="max-selection-count"]').removeClass('display_none');
1446 }else{
1447 $this.find('.ays-survey-question-action[data-action^="max-selection-count"]').addClass('display_none');
1448 }
1449
1450 if( enableWordLimit.prop('checked') == true ){
1451 $this.find('.ays-survey-question-action[data-action^="word-limitation-"]').text(SurveyMakerAdmin.disableWordLimitation);
1452 }else{
1453 $this.find('.ays-survey-question-action[data-action^="word-limitation-"]').text(SurveyMakerAdmin.enableWordLimitation);
1454 }
1455
1456 if( questionType == 'short_text' || questionType == 'text' ){
1457 $this.find('.ays-survey-question-action[data-action^="word-limitation-"]').removeClass('display_none');
1458 }else{
1459 $this.find('.ays-survey-question-action[data-action^="word-limitation-"]').addClass('display_none');
1460 }
1461
1462 if( enableNumberLimit.prop('checked') == true ){
1463 $this.find('.ays-survey-question-action[data-action^="number-word-limitation-"]').text(SurveyMakerAdmin.disableNumberLimitation);
1464 }else{
1465 $this.find('.ays-survey-question-action[data-action^="number-word-limitation-"]').text(SurveyMakerAdmin.enableNumberLimitation);
1466 }
1467
1468 if( questionType == 'number' || questionType == 'phone'){
1469 $this.find('.ays-survey-question-action[data-action^="number-word-limitation-"]').removeClass('display_none');
1470 }else{
1471 $this.find('.ays-survey-question-action[data-action^="number-word-limitation-"]').addClass('display_none');
1472 }
1473 });
1474
1475 $(document).on('click', '.ays-survey-add-question-to-this-section', function(e){
1476 var section = $(this).parents('.ays-survey-section-box');
1477
1478 var sectionId = section.attr('data-id');
1479 aysSurveyAddQuestion( sectionId, false, section );
1480
1481 });
1482
1483 $(document).on('click', '.ays-survey-add-new-section-from-bottom', function(e){
1484 var afterSectionId = $(this).parents('.ays-survey-section-box').attr('data-id');
1485 var newSection = $(this).parents('.ays-survey-section-box').hasClass('ays-survey-new-section');
1486 aysSurveyAddSection( afterSectionId, newSection );
1487 aysSurveySectionsInitToAddQuestions();
1488 });
1489
1490 $(document).on('click', '.ays-survey-duplicate-section', function(e){
1491 var afterSectionId = $(this).parents('.ays-survey-section-box').data('id');
1492 $(this).parents('.ays-survey-section-box').find(".ays-survey-delete-section").removeClass('display_none');
1493 var newSection = $(this).parents('.ays-survey-section-box').hasClass('ays-survey-new-section');
1494 aysSurveyDuplicateSection( $(this), afterSectionId, newSection);
1495 });
1496
1497 $(document).on('click', '.ays-survey-add-question-into-section', function(e){
1498 var section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box[data-id="'+ $(this).data( 'id' ) +'"]:not(.ays-survey-new-section)');
1499 if( $(this).hasClass('ays-survey-add-new-question-into-section') ){
1500 section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box.ays-survey-new-section[data-id="'+ $(this).data( 'id' ) +'"]');
1501 }
1502 var sectionId = $(this).attr( 'data-id' );
1503 aysSurveyAddQuestion( sectionId, false, section );
1504 });
1505
1506 $(document).on('change', '.ays-survey-question-type', function(e) {
1507 var $this = $(this);
1508 var parent = $this.parents('.ays-survey-section-box');
1509 var sectionId = parent.attr('data-id');
1510 var questionId = $this.parents('.ays-survey-question-answer-conteiner').attr('data-id');
1511 var questionDataName = $this.parents('.ays-survey-question-answer-conteiner').attr('data-name');
1512 var questionType = $this.aysDropdown('get value'); //$this.val();
1513 var questionTypeBeforeChange = $this.parents('.ays-survey-question-type-box').find('.ays-survey-check-type-before-change').val();
1514 var answerIds = $this.parents('.ays-survey-question-answer-conteiner').find('.ays-survey-answers-conteiner .ays-survey-answer-row');
1515 $this.parents('.ays-survey-question-type-box').find('.ays-survey-check-type-before-change').val(questionType);
1516
1517 if( questionType == 'radio' || questionType == 'checkbox' || questionType == 'select' ){
1518 if ( questionTypeBeforeChange == 'yesorno' ) {
1519 if (answerIds != undefined) {
1520 answerIds.each(function(e) {
1521 var answerId = $(this).data('id');
1522 if( ! $(this).hasClass('ays-survey-new-answer') ){
1523 var delImp = '<input type="hidden" name="'+ $html_name_prefix +'answers_delete[]" value="'+ answerId +'">';
1524 $this.parents('form').append( delImp );
1525 }
1526 });
1527 }
1528 }
1529 }else{
1530 if ( questionTypeBeforeChange == 'radio' || questionTypeBeforeChange == 'checkbox' || questionTypeBeforeChange == 'select' || questionTypeBeforeChange == 'yesorno' ) {
1531 if (answerIds != undefined) {
1532 answerIds.each(function(e) {
1533 var answerId = $(this).data('id');
1534 if( ! $(this).hasClass('ays-survey-new-answer') ){
1535 var delImp = '<input type="hidden" name="'+ $html_name_prefix +'answers_delete[]" value="'+ answerId +'">';
1536 $this.parents('form').append( delImp );
1537 }
1538 });
1539 }
1540 }
1541 }
1542
1543 switch( questionType ){
1544 case 'radio':
1545 aysSurveyQuestionType_Radio_Checkbox_Select_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1546 break;
1547 case 'checkbox':
1548 aysSurveyQuestionType_Radio_Checkbox_Select_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1549 break;
1550 case 'select':
1551 aysSurveyQuestionType_Radio_Checkbox_Select_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1552 break;
1553 case 'star':
1554 aysSurveyQuestionType_Star_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1555 break;
1556 case 'text':
1557 aysSurveyQuestionType_Text_ShortText_Number_Html( sectionId , questionId , questionDataName, questionType, false , parent );
1558 break;
1559 case 'short_text':
1560 aysSurveyQuestionType_Text_ShortText_Number_Html( sectionId , questionId , questionDataName, questionType, false , parent );
1561 break;
1562 case 'number':
1563 case 'phone':
1564 aysSurveyQuestionType_Text_ShortText_Number_Html( sectionId , questionId , questionDataName, questionType, false , parent );
1565 break;
1566 case 'yesorno':
1567 aysSurveyQuestionType_Radio_Checkbox_Select_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1568 break;
1569 case 'email':
1570 aysSurveyQuestionType_Text_ShortText_Number_Html( sectionId , questionId , questionDataName, questionType, false , parent );
1571 break;
1572 case 'name':
1573 aysSurveyQuestionType_Text_ShortText_Number_Html( sectionId , questionId , questionDataName, questionType, false , parent );
1574 break;
1575 case 'date':
1576 aysSurveyQuestionType_Date_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1577 break;
1578 case 'time':
1579 aysSurveyQuestionType_Time_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1580 break;
1581 case 'date_time':
1582 aysSurveyQuestionType_Date_Time_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1583 break;
1584 default:
1585 aysSurveyQuestionType_Radio_Checkbox_Select_Html( sectionId , questionId , questionDataName, questionType, questionTypeBeforeChange, false , parent );
1586 }
1587 });
1588
1589 setTimeout(function(){
1590 if($(document).find('#ays_survey_custom_css').length > 0){
1591 if(wp.codeEditor){
1592 wp.codeEditor.initialize($(document).find('#ays_survey_custom_css'), cm_settings);
1593 }
1594 }
1595 }, 500);
1596
1597 $(document).find('a[href="#tab2"]').on('click', function (e) {
1598 setTimeout(function(){
1599 if($(document).find('#ays_survey_custom_css').length > 0){
1600 var ays_survey_custom_css = $(document).find('#ays_survey_custom_css').html();
1601 if(wp.codeEditor){
1602 $(document).find('#ays_survey_custom_css').next('.CodeMirror').remove();
1603 wp.codeEditor.initialize($(document).find('#ays_survey_custom_css'), cm_settings);
1604 $(document).find('#ays_survey_custom_css').html(ays_survey_custom_css);
1605 }
1606 }
1607 }, 500);
1608 });
1609
1610 $(document).find('#ays_survey_schedule_active, #ays_survey_schedule_deactive, #ays_survey_change_creation_date').datetimepicker({
1611 controlType: 'select',
1612 oneLine: true,
1613 dateFormat: "yy-mm-dd",
1614 timeFormat: "HH:mm:ss",
1615 afterInject: function(){
1616 $(document).find('.ui-datepicker-buttonpane button.ui-state-default').addClass('button');
1617 $(document).find('.ui-datepicker-buttonpane button.ui-state-default.ui-priority-primary').addClass('button-primary').css('float', 'right');
1618 }
1619 });
1620
1621 $(document).on('click', '.ays-survey-open-question-editor', function(e){
1622 var editorPopup = $(document).find('#ays-edit-question-content');
1623 // For question
1624 var question = $(this).parents('.ays-survey-question-answer-conteiner');
1625 var questionId = question.data('id');
1626 var questionName = question.data('name');
1627 // For section
1628 var section = question.parents('.ays-survey-section-box');
1629 var sectionId = section.data('id');
1630 var sectionName = section.data('name');
1631 var questionContent = question.find('textarea.ays-survey-question-input-textarea').val();
1632 // For question
1633 editorPopup.find('.ays-survey-apply-question-changes').attr( 'data-question-id', questionId );
1634 editorPopup.find('.ays-survey-apply-question-changes').attr( 'data-question-name', questionName );
1635 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-question-id', questionId );
1636 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-question-name', questionName );
1637 // For section
1638 editorPopup.find('.ays-survey-apply-question-changes').attr( 'data-section-id', sectionId );
1639 editorPopup.find('.ays-survey-apply-question-changes').attr( 'data-section-name', sectionName );
1640 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-section-id', sectionId );
1641 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-section-name', sectionName );
1642
1643 if ( $(document).find("#wp-ays_survey_question_editor-wrap").hasClass("tmce-active") ){
1644 window.tinyMCE.get('ays_survey_question_editor').setContent( questionContent );
1645 }else{
1646 $(document).find('#ays_survey_question_editor').val( questionContent );
1647 }
1648
1649 editorPopup.aysEditorModal('open');
1650 });
1651
1652 $(document).on('dblclick click', '.ays-survey-question-preview-box', function(e){
1653 var editorPopup = $(document).find('#ays-edit-question-content');
1654 var question = $(this).parents('.ays-survey-question-answer-conteiner');
1655 var questionId = question.data('id');
1656 var questionName = question.data('name');
1657 var questionContent = question.find('textarea.ays-survey-question-input-textarea').val();
1658 editorPopup.find('.ays-survey-apply-question-changes').attr( 'data-question-id', questionId );
1659 editorPopup.find('.ays-survey-apply-question-changes').attr( 'data-question-name', questionName );
1660 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-question-id', questionId );
1661 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-question-name', questionName );
1662
1663 var SurveyTinyMCE = window.tinyMCE.get('ays_survey_question_editor');
1664 if(SurveyTinyMCE != null){
1665 SurveyTinyMCE.setContent( questionContent );
1666 }
1667 else{
1668 $(document).find('#ays_survey_question_editor').val( questionContent );
1669 }
1670
1671 editorPopup.aysEditorModal('open');
1672 });
1673
1674 $(document).on('click', '.ays-survey-back-to-textarea', function(e){
1675 var editorPopup = $(document).find('#ays-edit-question-content');
1676 var questionId = $(this).attr('data-question-id');
1677 var questionName = $(this).attr('data-question-name');
1678 var question = $(document).find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionName+'"]');
1679 var aysSurveyQuestionTextArea = question.find('textarea.ays-survey-question-input-textarea');
1680
1681 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-question-id', '' );
1682 editorPopup.find('.ays-survey-back-to-textarea').attr( 'data-question-name', '' );
1683
1684 question.find('.ays-survey-open-question-editor-flag').val('off');
1685
1686 question.find('.ays-survey-question-input-box').removeClass('display_none');
1687 question.find('.ays-survey-question-preview-box').addClass('display_none');
1688
1689 // setTimeout( function(){
1690 autosize.update(aysSurveyQuestionTextArea);
1691 // }, 100 );
1692
1693 editorPopup.aysEditorModal('hide');
1694 });
1695
1696 $(document).on('click', '.ays-survey-move-question-into-section', function(e){
1697 var popup = $(document).find('#ays-survey-move-to-section');
1698 var sectionId = popup.attr('data-section-id');
1699 var sectionDataName = popup.attr('data-section-name');
1700 var questionId = popup.attr('data-question-id');
1701 var questionDataName = popup.attr('data-question-name');
1702 var section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box[data-id="'+ $(this).data( 'id' ) +'"]:not(.ays-survey-new-section)');
1703 if( $(this).hasClass('ays-survey-move-new-question-into-section') ){
1704 section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box.ays-survey-new-section[data-id="'+ $(this).data( 'id' ) +'"]');
1705 }
1706 var oldSection = $(document).find('.ays-survey-section-box[data-id="'+sectionId+'"][data-name="'+sectionDataName+'"]');
1707 var question = oldSection.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"]');
1708 var questions = oldSection.find('.ays-survey-question-answer-conteiner');
1709
1710 if( questions.length <= 1 ){
1711 swal.fire({
1712 type: 'warning',
1713 text: SurveyMakerAdmin.minimumCountOfQuestions
1714 });
1715 }else{
1716 setTimeout(function(){
1717 question.appendTo( section.find('.ays-survey-section-questions') );
1718 draggedQuestionUpdate( question, section );
1719 popup.aysModal('hide');
1720 }, 1);
1721 }
1722 });
1723
1724 /////////////////////////////////////////////////////////////////////////////////////////////
1725 /////////////////////////////////////ARO END/////////////////////////////////////////////////
1726 /////////////////////////////////////////////////////////////////////////////////////////////
1727 /////////////////////////////////////////////////////////////////////////////////////////////
1728
1729 aysSurveySectionsInitToAddQuestions();
1730 function aysSurveySectionsInitToAddQuestions(){
1731 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
1732 var sections = sectionCont.find('.ays-survey-section-box');
1733 var addQuestionButton = $(document).find('.ays-survey-general-action[data-action="add-question"]');
1734 var ddmenu = addQuestionButton.parent().find('.dropdown-menu');
1735 ddmenu.html('');
1736 sections.each(function(i){
1737 var _this = $(this);
1738 var sectionQuestionsCollapsedInputs = _this.find('.ays-survey-question-collapsed-input');
1739 var sectionQuestionsCollapsedValues = [];
1740 var sectionQuestionsExpandedValues = [];
1741 sectionQuestionsCollapsedInputs.each(function(){
1742 if( $(this).val() == 'expanded' ){
1743 sectionQuestionsExpandedValues.push( true );
1744 }else{
1745 sectionQuestionsCollapsedValues.push( true );
1746 }
1747 });
1748
1749 var collapseButtonText = SurveyMakerAdmin.collapseSectionQuestions;
1750 if( sectionQuestionsExpandedValues.length == 0 ){
1751 collapseButtonText = SurveyMakerAdmin.expandSectionQuestions;
1752 }
1753
1754 var newClassToAddQuestion = '';
1755 if( _this.hasClass('ays-survey-new-section') ){
1756 newClassToAddQuestion = 'ays-survey-add-new-question-into-section';
1757 }
1758
1759 _this.find('.ays-survey-collapse-section-questions').text( collapseButtonText );
1760
1761 var buttonItem = '<button class="dropdown-item ays-survey-add-question-into-section '+ newClassToAddQuestion +'" data-id="'+ $(this).data('id') +'" type="button">';
1762 buttonItem += 'Add into Section '+ (i+1);
1763 buttonItem += '</button>';
1764 ddmenu.append(buttonItem);
1765 });
1766 if(sections.length > 1){
1767 addQuestionButton.attr('data-toggle', 'dropdown');
1768 addQuestionButton.attr('aria-expanded', 'false');
1769 }else{
1770 addQuestionButton.dropdown('dispose');
1771 addQuestionButton.removeAttr('data-toggle');
1772 }
1773 }
1774
1775 aysSurveySectionsInitQuestionsCollapse();
1776 function aysSurveySectionsInitQuestionsCollapse(){
1777 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
1778 var sections = sectionCont.find('.ays-survey-section-box');
1779 sections.each(function(i){
1780 var _this = $(this);
1781 var sectionQuestionsCollapsedInputs = _this.find('.ays-survey-question-collapsed-input');
1782 var sectionQuestionsCollapsedValues = [];
1783 var sectionQuestionsExpandedValues = [];
1784 sectionQuestionsCollapsedInputs.each(function(){
1785 if( $(this).val() == 'expanded' ){
1786 sectionQuestionsExpandedValues.push( true );
1787 }else{
1788 sectionQuestionsCollapsedValues.push( true );
1789 }
1790 });
1791
1792 var collapseButtonText = SurveyMakerAdmin.collapseSectionQuestions;
1793 var collapseButtonAddClass = 'ays-survey-collapse-sec-quests';
1794 var collapseButtonRemoveClass = 'ays-survey-expand-sec-quests';
1795 if( sectionQuestionsExpandedValues.length == 0 ){
1796 collapseButtonText = SurveyMakerAdmin.expandSectionQuestions;
1797 collapseButtonAddClass = 'ays-survey-expand-sec-quests';
1798 collapseButtonRemoveClass = 'ays-survey-collapse-sec-quests';
1799 }
1800
1801 _this.find('.ays-survey-collapse-section-questions').text( collapseButtonText );
1802 _this.find('.ays-survey-collapse-section-questions').addClass( collapseButtonAddClass );
1803 _this.find('.ays-survey-collapse-section-questions').removeClass( collapseButtonRemoveClass );
1804 });
1805 }
1806
1807 function aysSurveyAddQuestion( sectionId, returnElem = false, sectionElem = null, isFromTemplate = false ){
1808 var section = sectionElem;
1809
1810 var requiredQuestionButton = section.find('.ays-survey-section-questions-required');
1811 var requiredQuestionButtonFlag = requiredQuestionButton.attr('data-flag');
1812
1813 var cloningElement = $(document).find('.ays-question-to-clone .ays-survey-question-answer-conteiner');
1814 var clonedElement = cloningElement.clone( true, false );
1815 // var questionsLength = section.find('.ays-survey-question-answer-conteiner .ays-survey-question-input-box .ays-survey-input[name^="ays_section_add"]').length;
1816 var questionsLength = section.find('.ays-survey-question-answer-conteiner').length;
1817 var defaultQuestionType = $(document).find('input[name="ays_default_question_type"]').val();
1818 var answers = clonedElement.find('.ays-survey-answers-conteiner .ays-survey-answer-row');
1819
1820 // Generate unique number for every new question
1821 var generatedUniqueNumber = aysSurveyUniqueNumber();
1822 var questionId = generatedUniqueNumber;
1823 if(isFromTemplate){
1824 var questionTemplateId = questionsLength + 1;
1825 }
1826
1827 if(requiredQuestionButtonFlag && requiredQuestionButtonFlag == 'on'){
1828 clonedElement.find('.ays-survey-answer-elem-box .ays-survey-input-required-question').prop('checked', true);
1829 }
1830
1831
1832 var questionName = clonedElement.attr('data-name');
1833 var sectionName = section.attr('data-name');
1834 if( sectionElem !== null ){
1835 sectionName = sectionElem.attr('data-name');
1836 }
1837
1838 var questionsCount = questionsLength;
1839 var questionsCountBox = section.find(".ays-survey-action-questions-count span").text(questionsCount + 1);
1840 // Answers ordering jQuery UI
1841 clonedElement.find('.ays-survey-answers-conteiner').sortable(answerDragHandle);
1842
1843
1844 var aysSurveyTextArea = clonedElement.find('textarea.ays-survey-question-input-textarea');
1845 setTimeout( function(){
1846 autosize(aysSurveyTextArea);
1847 }, 100 );
1848
1849 clonedElement.addClass('ays-survey-new-question');
1850 clonedElement.attr('data-id', questionId);
1851 if(isFromTemplate){
1852 clonedElement.attr('data-template-id', questionTemplateId);
1853 }
1854 clonedElement.find('textarea.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'title'));
1855 clonedElement.find('select.ays-survey-question-type').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'type'));
1856 clonedElement.find('.ays-survey-question-img-src').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'image'));
1857 clonedElement.find('.ays-survey-other-answer-checkbox').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'user_variant'));
1858 clonedElement.find('.ays-survey-input-required-question').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'required'));
1859 clonedElement.find('.ays-survey-question-collapsed-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'collapsed'));
1860 clonedElement.find('.ays-survey-question-ordering').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'ordering'));
1861 clonedElement.find('.ays-survey-question-max-selection-count-checkbox').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'enable_max_selection_count'));
1862 clonedElement.find('.ays-survey-question-max-selection-count input.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'max_selection_count'));
1863 clonedElement.find('.ays-survey-question-min-selection-count input.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'min_selection_count'));
1864 // Text limitation options
1865 clonedElement.find('.ays-survey-question-word-limitations-checkbox').attr('name', newQuestionAttrName(sectionName, sectionId, questionId, 'options', 'enable_word_limitation'));
1866 clonedElement.find('.ays-survey-question-more-option-wrap-limitations .ays-survey-question-word-limit-by-select select').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'limit_by'));
1867 clonedElement.find('.ays-survey-question-more-option-wrap-limitations input.ays-survey-limit-length-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'limit_length'));
1868 clonedElement.find('.ays-survey-question-more-option-wrap-limitations .ays-survey-text-limitations-counter-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'limit_counter'));
1869 // Number limitation options start
1870 clonedElement.find('.ays-survey-question-number-limitations-checkbox').attr('name', newQuestionAttrName(sectionName, sectionId, questionId, 'options', 'enable_number_limitation'));
1871 clonedElement.find('.ays-survey-question-number-limitations input.ays-survey-number-min-votes').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'number_min_selection'));
1872 clonedElement.find('.ays-survey-question-number-limitations input.ays-survey-number-max-votes').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'number_max_selection'));
1873 clonedElement.find('.ays-survey-question-number-limitations input.ays-survey-number-error-message').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'number_error_message'));
1874 clonedElement.find('.ays-survey-question-number-limitations input.ays-survey-number-enable-error-message').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'enable_number_error_message'));
1875 clonedElement.find('.ays-survey-question-number-limitations input.ays-survey-number-limit-length').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'number_limit_length'));
1876 clonedElement.find('.ays-survey-question-number-limitations input.ays-survey-number-number-limit-length').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'enable_number_limit_counter'));
1877 // Number limitation options end
1878 clonedElement.find('.ays-survey-open-question-editor-flag').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'with_editor'));
1879
1880 clonedElement.find('.ays-survey-question-image-caption').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'image_caption'));
1881 clonedElement.find('.ays-survey-question-img-caption-enable').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'image_caption_enable'));
1882 clonedElement.find('.ays-survey-question-ordering').val(questionId);
1883
1884 clonedElement.find('.ays-survey-question-admin-note-saver').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'enable_admin_note'));
1885 clonedElement.find('.ays-survey-question-admin-note-label input.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'admin_note'));
1886
1887 answers.each(function(j){
1888 var answerId = j+1; //answers.find('.ays-survey-answer-box input.ays-survey-input').length;
1889 $(this).addClass('ays-survey-new-answer');
1890 $(this).attr('data-id', answerId);
1891 $(this).find('.ays-survey-answer-box input.ays-survey-input').attr('name', newAnswerAttrName( sectionName, sectionId, questionName, questionId, answerId, 'title'));
1892 $(this).find('.ays-survey-answer-img-src').attr('name', newAnswerAttrName( sectionName, sectionId, questionName, questionId, answerId, 'image'));
1893 $(this).find('.ays-survey-answer-ordering').attr('name', newAnswerAttrName( sectionName, sectionId, questionName, questionId, answerId, 'ordering'));
1894
1895 var deleteButton = $(this).find('.ays-survey-answer-delete');
1896 if( answers.length == 1){
1897 deleteButton.css('visibility', 'hidden');
1898 }else{
1899 deleteButton.removeAttr('style');
1900 }
1901 });
1902
1903 clonedElement.find('select.ays-survey-question-type').aysDropdown();
1904 clonedElement.find('.dropdown .item[data-value="email"]').before('<div class="divider"></div>');
1905 clonedElement.find('.dropdown .item[data-value="matrix_scale"]').before('<div class="divider"></div>');
1906
1907 var sectionCollapsedInput = section.find('.ays-survey-section-collapsed-input');
1908 var sectionCollapsed = sectionCollapsedInput.val() == 'collapsed' ? true : false;
1909
1910 if( sectionCollapsed ){
1911 expandSection( sectionCollapsedInput );
1912 }
1913
1914 if( returnElem ){
1915 return clonedElement;
1916 }else{
1917 section.find('.ays-survey-section-questions').append(clonedElement);
1918 clonedElement = section.find('.ays-survey-question-answer-conteiner.ays-survey-new-question[data-id="'+questionId+'"]');
1919 }
1920
1921 clonedElement.find('.ays-survey-question-type').aysDropdown('set selected', defaultQuestionType);
1922 clonedElement.find('.ays-survey-question-type').aysDropdown('set value', defaultQuestionType);
1923
1924 if(!isFromTemplate){
1925 setTimeout(function(){
1926 clonedElement.goToTop();
1927 }, 100 );
1928 }
1929
1930 reInitPopovers( clonedElement );
1931 aysSurveySectionsInitQuestionsCollapse();
1932 }
1933
1934 // Generate unique number
1935 function aysSurveyUniqueNumber() {
1936 var randomNumber = Math.random();
1937 var timestamp = Date.now();
1938 var uniqueNumber = Math.floor(randomNumber * timestamp);
1939 return uniqueNumber;
1940 }
1941
1942 function aysSurveyAddSection( afterSectionId, newSection, isFromTemplate = false){
1943
1944 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
1945 var sections = sectionCont.find('.ays-survey-section-box');
1946 var sectionsAdd = sectionCont.find('.ays-survey-new-section');
1947
1948 var section = $(document).find('.ays-question-to-clone .ays-survey-section-box');
1949 var clonedElement = section.clone( true, false );
1950 var sectionNewId = sectionsAdd.length + 1;
1951
1952 clonedElement.attr('data-id', sectionNewId);
1953 clonedElement.attr('data-name', 'ays_section_add');
1954 clonedElement.addClass('ays-survey-new-section');
1955 clonedElement.find('.ays-survey-section-title').attr('name', newSectionAttrName( sectionNewId, 'title' ));
1956 clonedElement.find('.ays-survey-section-description').attr('name', newSectionAttrName( sectionNewId, 'description' ));
1957 clonedElement.find('.ays-survey-section-ordering').attr('name', newSectionAttrName( sectionNewId, 'ordering' ));
1958 clonedElement.find('.ays-survey-section-collapsed-input').attr('name', newSectionAttrName( sectionNewId, 'options', 'collapsed' ));
1959
1960 if( typeof afterSectionId !== 'undefined' && afterSectionId !== null ){
1961 if( newSection === true ){
1962 clonedElement.insertAfter( sectionCont.find('.ays-survey-section-box.ays-survey-new-section[data-id="' + afterSectionId + '"]') );
1963 }else{
1964 clonedElement.insertAfter( sectionCont.find('.ays-survey-section-box.ays-survey-old-section[data-id="' + afterSectionId + '"]') );
1965 }
1966 }else{
1967 sectionCont.append( clonedElement );
1968 }
1969
1970 var defaultQuestionType = $(document).find('input[name="ays_default_question_type"]').val();
1971 var question = aysSurveyAddQuestion( sectionNewId, true, clonedElement );
1972 clonedElement.find('.ays-survey-section-questions').append( question );
1973
1974 question.find('.ays-survey-question-type').aysDropdown('set selected', defaultQuestionType);
1975 question.find('.ays-survey-question-type').aysDropdown('set value', defaultQuestionType);
1976
1977 clonedElement.find('.ays-survey-section-questions').sortable(questionDragHandle);
1978
1979 sectionCont = $(document).find('.ays-survey-sections-conteiner');
1980 sections = sectionCont.find('.ays-survey-section-box');
1981
1982 sections.each(function(i){
1983 $(this).find('.ays-survey-section-ordering').val( i + 1 );
1984 });
1985
1986 var aysSurveyDescriptionTextArea = clonedElement.find('textarea.ays-survey-section-description');
1987 setTimeout( function(){
1988 autosize(aysSurveyDescriptionTextArea);
1989 }, 100 );
1990
1991 sectionCont.find('.ays-survey-section-head-top').removeClass('display_none');
1992 sectionCont.find('.ays-survey-section-head').addClass('ays-survey-section-head-topleft-border-none');
1993
1994 sectionCont.find('.ays-survey-section-box').each(function( index ){
1995 $(this).find('.ays-survey-section-number').text( index + 1 );
1996 });
1997
1998 sectionCont.find('.ays-survey-sections-count').text( sections.length );
1999
2000 // sectionCont.find('.invisible').removeClass( 'invisible' );
2001 sectionCont.find('.ays-survey-section-actions-more .ays-survey-delete-section').removeClass('display_none');
2002 // sectionCont.find('.ays-survey-other-answer-and-actions-row .ays-survey-answer-dlg-dragHandle .ays-survey-icons').addClass( 'invisible' );
2003 // sectionCont.find('.ays-survey-other-answer-and-actions-row .ays-question-img-icon-content').parents('.ays-survey-answer-icon-box').addClass( 'invisible' );
2004 // sectionCont.find('.ays-survey-other-answer-and-actions-row .ays-survey-other-answer-delete-icon').parents('.ays-survey-answer-icon-box').addClass( 'invisible' );
2005 if(!isFromTemplate){
2006 setTimeout(function(){
2007 clonedElement.goToTop();
2008 }, 100 );
2009 }
2010
2011 reInitPopovers( clonedElement );
2012 }
2013
2014 function aysSurveyDuplicateSection( currentButton, afterSectionId, newSection){
2015 var sectionCont = currentButton.parents('.ays-survey-sections-conteiner');
2016 var sections = sectionCont.find('.ays-survey-section-box');
2017 var sectionsAdd = sectionCont.find('.ays-survey-new-section');
2018 var sectionNewId = sectionsAdd.length + 1;
2019
2020 var currentElement = currentButton.parents(".ays-survey-section-box");
2021 var clonedElement = currentElement.clone( true, false );
2022 clonedElement = aysSetNewSectionNames(clonedElement, sectionNewId);
2023
2024 if( typeof afterSectionId !== 'undefined' && afterSectionId !== null ){
2025 clonedElement.insertAfter( currentElement );
2026 }else{
2027 sectionCont.append( clonedElement );
2028 }
2029
2030 // Get all questions
2031 var allQuestions = clonedElement.find('.ays-survey-question-answer-conteiner');
2032 allQuestions.each(function(i){
2033 var questionElem = this;
2034 var questionId = i+1;
2035 var answers = $(this).find('.ays-survey-answers-conteiner .ays-survey-answer-row');
2036
2037 // Set new names for questions
2038 aysSetNewQuestionNames($(questionElem), sectionNewId, questionId);
2039 answers.each(function(j){
2040 var answerId = j;
2041 // Set new names for answers
2042 aysSetNewAnswerNames($(this), sectionNewId, questionId, answerId);
2043
2044 var deleteButton = $(this).find('.ays-survey-answer-delete');
2045 if( answers.length == 1){
2046 deleteButton.css('visibility', 'hidden');
2047 }else{
2048 deleteButton.removeAttr('style');
2049 }
2050 });
2051 });
2052
2053
2054 clonedElement.find('.ays-survey-section-questions').sortable(questionDragHandle);
2055
2056 sectionCont = $(document).find('.ays-survey-sections-conteiner');
2057 sections = sectionCont.find('.ays-survey-section-box');
2058 sections.each(function(i){
2059 $(this).find('.ays-survey-section-ordering').val( i + 1 );
2060 $(this).find('.ays-survey-section-number').text( i + 1 );
2061 });
2062
2063 sectionCont.find('.ays-survey-sections-count').text( sections.length );
2064
2065 sectionCont.find('.ays-survey-section-head-top').removeClass('display_none');
2066 sectionCont.find('.ays-survey-section-head').addClass('ays-survey-section-head-topleft-border-none');
2067 setTimeout(function(){
2068 clonedElement.goTo();
2069 }, 100 );
2070 reInitPopovers( clonedElement );
2071 }
2072
2073 function aysSetNewSectionNames(element, sectionId){
2074 element.attr('data-id', sectionId);
2075 element.attr('data-name', 'ays_section_add');
2076 element.addClass('ays-survey-new-section');
2077 element.find('.ays-survey-section-title').attr('name', newSectionAttrName( sectionId, 'title' ));
2078 element.find('.ays-survey-section-description').attr('name', newSectionAttrName( sectionId, 'description' ));
2079 element.find('.ays-survey-section-ordering').attr('name', newSectionAttrName( sectionId, 'ordering' ));
2080 element.find('.ays-survey-section-collapsed-input').attr('name', newSectionAttrName( sectionId, 'options', 'collapsed' ));
2081 element.find('.ays-survey-delete-section').removeClass("display_none");
2082 element.find('.dropdown-menu.dropdown-menu-right').removeClass("show");
2083 element.find('input[name*="ays_sections_ids"]').remove();
2084 return element;
2085 }
2086
2087 function aysSetNewQuestionNames(element, sectionId, questionId){
2088 element.removeClass('ays-survey-old-question');
2089 element.addClass('ays-survey-new-question');
2090 element.attr('data-id', questionId);
2091 element.attr('data-name', 'questions_add');
2092 var question_type = element.find('.ays-survey-check-type-before-change').val();
2093
2094 var starScaleOldLength = "";
2095 if(question_type == 'star'){
2096 starScaleOldLength = element.find(".ays-survey-choose-for-start-select-lenght").val();
2097 element.find('select.ays-survey-choose-for-start-select-lenght').val(starScaleOldLength);
2098 element.find('input.ays-survey-input-star-1').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'star_1'));
2099 element.find('input.ays-survey-input-star-2').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'star_2'));
2100 element.find('select.ays-survey-choose-for-start-select-lenght').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'star_scale_length'));
2101 }
2102
2103 element.find('textarea.ays-survey-input').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'title'));
2104 element.find('.ays-survey-question-type select').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'type'));
2105 element.find('.ays-survey-question-img-src').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'image'));
2106 element.find('.ays-survey-other-answer-checkbox').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'user_variant'));
2107 element.find('.ays-survey-input-required-question').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'required'));
2108 element.find('.ays-survey-question-collapsed-input').attr('name', newQuestionAttrName('ays_section_add', sectionId, questionId, 'options', 'collapsed'));
2109 element.find('.ays-survey-question-ordering').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'ordering'));
2110 element.find('.ays-survey-question-max-selection-count-checkbox').attr('name', newQuestionAttrName('ays_section_add', sectionId, questionId, 'options', 'enable_max_selection_count'));
2111 element.find('.ays-survey-question-max-selection-count input.ays-survey-input').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'max_selection_count'));
2112 element.find('.ays-survey-question-min-selection-count input.ays-survey-input').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'min_selection_count'));
2113 // Text limitation options
2114 element.find('.ays-survey-question-word-limitations-checkbox').attr('name', newQuestionAttrName('ays_section_add', sectionId, questionId, 'options', 'enable_word_limitation'));
2115 element.find('.ays-survey-question-more-option-wrap-limitations .ays-survey-question-word-limit-by-select select').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'limit_by'));
2116 element.find('.ays-survey-question-more-option-wrap-limitations input.ays-survey-limit-length-input').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'limit_length'));
2117 element.find('.ays-survey-question-more-option-wrap-limitations .ays-survey-text-limitations-counter-input').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'limit_counter'));
2118 // Number limitation options start
2119 element.find('.ays-survey-question-number-limitations-checkbox').attr('name', newQuestionAttrName('ays_section_add', sectionId, questionId, 'options', 'enable_number_limitation'));
2120 element.find('.ays-survey-question-number-limitations input.ays-survey-number-min-votes').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'number_min_selection'));
2121 element.find('.ays-survey-question-number-limitations input.ays-survey-number-max-votes').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'number_max_selection'));
2122 element.find('.ays-survey-question-number-limitations input.ays-survey-number-enable-error-message').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'number_error_message'));
2123 element.find('.ays-survey-question-number-limitations input.ays-survey-number-error-message').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'enable_number_error_message'));
2124 element.find('.ays-survey-question-number-limitations input.ays-survey-number-limit-length').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'number_limit_length'));
2125 element.find('.ays-survey-question-number-limitations input.ays-survey-number-number-limit-length').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'enable_number_limit_counter'));
2126 // Number limitation options end
2127
2128 // Input types placeholders
2129 element.find('.ays-survey-question-types-input-with-placeholder').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'placeholder'));
2130
2131
2132 element.find('.ays-survey-question-image-caption').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'image_caption'));
2133 element.find('.ays-survey-question-img-caption-enable').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'image_caption_enable'));
2134
2135 element.find('.ays-survey-question-admin-note-saver').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'enable_admin_note'));
2136 element.find('.ays-survey-question-admin-note-label input.ays-survey-input').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'admin_note'));
2137
2138 element.find('.ays-survey-open-question-editor-flag').attr('name', newQuestionAttrName( 'ays_section_add', sectionId, questionId, 'options', 'with_editor'));
2139 element.find('.ays-survey-question-ordering').val(questionId);
2140
2141 element.find('.ays-survey-question-type').aysDropdown('set selected', question_type);
2142 element.find('.ays-survey-question-type').aysDropdown('set value', question_type);
2143 element.find('.ays-survey-question-type').aysDropdown();
2144 }
2145
2146 function aysSetNewAnswerNames(element, sectionId, questionId, answerId){
2147 element.addClass('ays-survey-new-answer');
2148 element.attr('data-id', answerId);
2149 element.find('.ays-survey-answer-box input.ays-survey-input').attr('name', newAnswerAttrName( 'ays_section_add', sectionId, 'questions_add', questionId, answerId, 'title'));
2150 element.find('.ays-survey-answer-img-src').attr('name', newAnswerAttrName( 'ays_section_add', sectionId, 'questions_add', questionId, answerId, 'image'));
2151 element.find('.ays-survey-answer-ordering').attr('name', newAnswerAttrName( 'ays_section_add', sectionId, 'questions_add', questionId, answerId, 'ordering'));
2152 }
2153
2154 function aysSurveyQuestionType_Radio_Checkbox_Select_Html( sectionId, questionId, questionDataName, questionType, questionTypeBeforeChange, returnElem = false, sectionElem = null ){
2155
2156 var removeHtml = true; // Remove Html
2157 if(questionTypeBeforeChange == 'radio' || questionTypeBeforeChange == 'select' || questionTypeBeforeChange == 'checkbox'){
2158 removeHtml = false;
2159 }
2160
2161 var section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box[data-id="'+sectionId+'"]');
2162 var question = section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"]');
2163 var cloningElement = $(document).find('.ays-question-to-clone .ays-survey-question-answer-conteiner .ays-survey-answers-conteiner');
2164 var cloningElement_2 = $(document).find('.ays-question-to-clone .ays-survey-question-answer-conteiner .ays-survey-other-answer-and-actions-row');
2165
2166 if( questionType == 'yesorno' ){
2167 cloningElement = $(document).find('.ays-question-to-clone .ays-survey-question-type-yes-or-no');
2168 removeHtml = true;
2169 }
2170
2171 var clonedElement = cloningElement.clone( true, false );
2172 var clonedElement_2 = cloningElement_2.clone( true, false );
2173
2174 var answers = clonedElement.find('.ays-survey-answer-row');
2175 clonedElement.sortable(answerDragHandle);
2176
2177 var questionName = questionDataName;
2178 var sectionName = section.attr('data-name');
2179 if( sectionElem !== null ){
2180 sectionName = sectionElem.attr('data-name');
2181 }
2182 question.find('.ays-survey-question-word-limitations').addClass('display_none');
2183 question.find('.ays-survey-question-number-limitations').addClass('display_none');
2184 var placeholderVal = '';
2185 var questionTypeIconClass = '';
2186 var answer_icon = clonedElement.find('.ays-survey-answer-icon-box.ays-survey-answer-icon-just img');
2187 var other_answer_icon = clonedElement_2.find('.ays-survey-answer-icon-box.ays-survey-answer-icon-just img');
2188 switch( questionType ){
2189 case 'radio':
2190 case 'yesorno':
2191 questionTypeIconClass = SurveyMakerAdmin.icons.radioButtonUnchecked;
2192 break;
2193 case 'checkbox':
2194 questionTypeIconClass = SurveyMakerAdmin.icons.checkboxUnchecked;
2195 break;
2196 case 'select':
2197 questionTypeIconClass = SurveyMakerAdmin.icons.radioButtonUnchecked;
2198 break;
2199 default:
2200 questionTypeIconClass = SurveyMakerAdmin.icons.radioButtonUnchecked;
2201 }
2202
2203 other_answer_icon.attr('src', questionTypeIconClass);
2204 answer_icon.attr('src', questionTypeIconClass);
2205
2206 clonedElement_2.find('.ays-survey-other-answer-checkbox').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'user_variant'));
2207 clonedElement_2.find('.ays-survey-question-max-selection-count-checkbox').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'enable_max_selection_count'));
2208 clonedElement_2.find('.ays-survey-question-max-selection-count input.ays-survey-input').attr('name', newQuestionAttrName( sectionName, sectionId, questionId, 'options', 'max_selection_count'));
2209
2210 answers.each(function(i){
2211 var answerId = i+1;
2212 $(this).addClass('ays-survey-new-answer');
2213 $(this).attr('data-id', answerId);
2214 $(this).find('.ays-survey-answer-box input.ays-survey-input').attr('name', newAnswerAttrName( sectionName, sectionId, questionName, questionId, answerId, 'title'));
2215 $(this).find('.ays-survey-answer-img-src').attr('name', newAnswerAttrName( sectionName, sectionId, questionName, questionId, answerId, 'image'));
2216 $(this).find('.ays-survey-answer-ordering').attr('name', newAnswerAttrName( sectionName, sectionId, questionName, questionId, answerId, 'ordering'));
2217 });
2218
2219 if( questionType == 'select' ){
2220 clonedElement_2.find('.ays-survey-other-answer-add-wrap').hide();
2221 clonedElement_2.find('.ays-survey-other-answer-row').hide();
2222 clonedElement_2.find('.ays-survey-other-answer-checkbox').prop('checked', false );
2223 question.find('.ays-survey-other-answer-add-wrap').hide();
2224 question.find('.ays-survey-other-answer-checkbox').prop('checked', false );
2225 }else{
2226 clonedElement_2.find('.ays-survey-other-answer-add-wrap').show();
2227 if( question.find('.ays-survey-other-answer-checkbox').prop('checked') == true ){
2228 question.find('.ays-survey-other-answer-add-wrap').hide();
2229 }else{
2230 question.find('.ays-survey-other-answer-add-wrap').show();
2231 }
2232 }
2233
2234 var enableMaxSelectionCount = question.find('.ays-survey-question-max-selection-count-checkbox').prop('checked');
2235 if( questionType == "checkbox" && enableMaxSelectionCount ){
2236 question.find('.ays-survey-question-more-option-wrap').removeClass('display_none');
2237 }else{
2238 question.find('.ays-survey-question-more-option-wrap').addClass('display_none');
2239 }
2240
2241 if( questionType != "checkbox" ){
2242 question.find('.ays-survey-question-actions-pro[data-action="go-to-section-based-on-answers-enable"]').removeClass('display_none');
2243 }
2244
2245
2246 question.find('.ays-survey-question-more-actions').removeClass('display_none');
2247
2248
2249 if( returnElem ){
2250 clonedElement = $( clonedElement.html() );
2251 var clonedElementArr = new Array(clonedElement, clonedElement_2);
2252 return clonedElementArr;
2253 }else{
2254 // Remove Html
2255 if (removeHtml) {
2256 clonedElement = $( clonedElement.html() );
2257 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"] .ays-survey-answers-conteiner').html(clonedElement);
2258 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_star').html('');
2259 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date').html('');
2260 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_time').html('');
2261 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date_time').html('');
2262 }else{
2263 var answer_icon_tags = section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"] .ays-survey-answer-icon-box.ays-survey-answer-icon-just img');
2264 switch( questionType ){
2265 case 'radio':
2266 case 'yesorno':
2267 answer_icon_tags.attr('src', SurveyMakerAdmin.icons.radioButtonUnchecked);
2268 break;
2269 case 'checkbox':
2270 answer_icon_tags.attr('src', SurveyMakerAdmin.icons.checkboxUnchecked);
2271 break;
2272 case 'select':
2273 answer_icon_tags.attr('src', SurveyMakerAdmin.icons.radioButtonUnchecked);
2274 break;
2275 default:
2276 answer_icon_tags.attr('src', SurveyMakerAdmin.icons.radioButtonUnchecked);
2277 }
2278 }
2279
2280 if( questionType == 'select' || questionType == 'checkbox' || questionType == 'radio' || questionType == 'yesorno'){
2281 var addAnswerRow = section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"] .ays-survey-other-answer-and-actions-row');
2282 clonedElement_2.find('.ays-survey-other-answer-row .ays-survey-answer-icon-box .invisible').removeClass( 'invisible' );
2283
2284 if ( removeHtml || questionType == 'select' ) {
2285 addAnswerRow.html(clonedElement_2.html());
2286 }
2287 }
2288 }
2289 }
2290
2291 function aysSurveyQuestionType_Star_Html(sectionId, questionId, questionDataName, questionType, questionTypeBeforeChange, returnElem = false, sectionElem = null){
2292
2293 var section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box[data-id="'+sectionId+'"]');
2294 var question = section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"]');
2295 var cloningElement = $(document).find('.ays-question-to-clone .ays-survey-question-types_star');
2296 var clonedElement = cloningElement.clone( true, false );
2297
2298 var sectionName = section.attr('data-name');
2299 if( sectionElem !== null ){
2300 sectionName = sectionElem.attr('data-name');
2301 }
2302
2303 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-answer-elem-box').css('display','block');
2304 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-description-box').css('display','flex');
2305
2306 question.find('.ays-survey-question-word-limitations').addClass('display_none');
2307 question.find('.ays-survey-question-number-limitations').addClass('display_none');
2308 question.find('.ays-survey-question-action[data-action="enable-user-explanation"]').show();
2309 clonedElement.find('.ays-survey-choose-for-select-lenght').attr('name', updateQuestionAttrName( sectionName, sectionId, questionDataName, questionId, 'options', 'scale_length'));
2310 clonedElement.find('.ays-survey-input-star-1').attr('name', updateQuestionAttrName( sectionName, sectionId, questionDataName, questionId, 'options', 'star_1'));
2311 clonedElement.find('.ays-survey-input-star-2').attr('name', updateQuestionAttrName( sectionName, sectionId, questionDataName, questionId, 'options', 'star_2'));
2312 clonedElement.find('.ays-survey-choose-for-start-select-lenght').attr('name', updateQuestionAttrName( sectionName, sectionId, questionDataName, questionId, 'options', 'star_scale_length'));
2313
2314 question.find('.ays-survey-question-more-option-wrap').addClass('display_none');
2315 if(returnElem){
2316 return clonedElement;
2317 }else{
2318 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-answers-conteiner').html(clonedElement);
2319 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-other-answer-and-actions-row').html('');
2320 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date').html('');
2321 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_time').html('');
2322 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date_time').html('');
2323
2324 }
2325 }
2326
2327 function aysSurveyQuestionType_Text_ShortText_Number_Html( sectionId, questionId, questionDataName, questionType, returnElem = false, sectionElem = null ){
2328 var section = sectionElem;
2329 var cloningElement = $(document).find('.ays-question-to-clone .ays-survey-question-types');
2330 var question = section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"]');
2331 var clonedElement = cloningElement.clone( true, false );
2332
2333 var answers = clonedElement.find('.ays-survey-answer-row');
2334
2335 var questionName = questionDataName;
2336 var sectionName = section.attr('data-name');
2337 if( sectionElem !== null ){
2338 sectionName = sectionElem.attr('data-name');
2339 }
2340
2341
2342 var placeholderVal = '';
2343 var questionTypeClass = '';
2344 placeholderVal = SurveyMakerAdmin.inputAnswerText;
2345 switch( questionType ){
2346 case 'text':
2347 questionTypeClass = 'ays-survey-question-type-text-box ays-survey-question-type-all-text-types-box';
2348 break;
2349 case 'short_text':
2350 questionTypeClass = 'ays-survey-question-type-short-text-box ays-survey-question-type-all-text-types-box';
2351 break;
2352 case 'number':
2353 questionTypeClass = 'ays-survey-question-type-number-box ays-survey-question-type-all-text-types-box';
2354 break;
2355 case 'phone':
2356 placeholderVal = SurveyMakerAdmin.phoneAnswerText;
2357 questionTypeClass = 'ays-survey-question-type-number-box ays-survey-question-type-all-text-types-box';
2358 clonedElement.find(".ays-survey-question-types-box-phone-type-note").removeClass("display_none");
2359 question.find(".ays-survey-question-number-min-box,.ays-survey-question-number-max-box").addClass("display_none");
2360 break;
2361 case 'email':
2362 placeholderVal = SurveyMakerAdmin.emailField;
2363 questionTypeClass = 'ays-survey-question-type-email-box ays-survey-question-type-all-text-types-box';
2364 break;
2365 case 'name':
2366 placeholderVal = SurveyMakerAdmin.nameField;
2367 questionTypeClass = 'ays-survey-question-type-name-box ays-survey-question-type-all-text-types-box';
2368 break;
2369 default:
2370 placeholderVal = SurveyMakerAdmin.inputAnswerText;
2371 questionTypeClass = 'ays-survey-question-type-text-box ays-survey-question-type-all-text-types-box';
2372 }
2373
2374 var enableWordLimitation = question.find('.ays-survey-question-word-limitations-checkbox').prop('checked');
2375 if( (questionType == "short_text" || questionType == "text") && enableWordLimitation ){
2376 question.find('.ays-survey-question-word-limitations').removeClass('display_none');
2377 }else{
2378 question.find('.ays-survey-question-word-limitations').addClass('display_none');
2379 }
2380
2381 var enableNumberLimitation = question.find('.ays-survey-question-number-limitations-checkbox').prop('checked');
2382 if( (questionType == "number" || questionType == "phone") && enableNumberLimitation ){
2383 question.find('.ays-survey-question-number-limitations').removeClass('display_none');
2384 }else{
2385 question.find('.ays-survey-question-number-limitations').addClass('display_none');
2386 }
2387
2388 // if( questionType == "short_text" || questionType == "text" || questionType == "number"){
2389 // question.find('.ays-survey-question-more-actions').removeClass('display_none');
2390 // }else{
2391 // question.find('.ays-survey-question-more-actions').addClass('display_none');
2392 // }
2393 // question.find('.ays-survey-question-more-option-wrap-limitations .ays-survey-question-word-limit-by-select select').aysDropdown();
2394 // question.find('.ays-survey-question-more-option-wrap-limitations .ays-survey-question-word-limit-by-select select').aysDropdown();
2395
2396
2397
2398 var answerId = answers.find('input.ays-survey-question-types-input').length;
2399 answers.attr('data-id', answerId);
2400 answers.find('input.ays-survey-question-types-input.ays-survey-question-types-input-with-placeholder').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'placeholder'));
2401 answers.find('input.ays-survey-question-types-input').attr('placeholder', placeholderVal);
2402 answers.find('input.ays-survey-question-types-input').val(placeholderVal);
2403 answers.find('.ays-survey-question-types-box').addClass(questionTypeClass);
2404
2405 // question.find('.ays-survey-question-more-actions').addClass('display_none');
2406 question.find('.ays-survey-question-more-option-wrap').addClass('display_none');
2407 question.find('.ays-survey-question-actions-pro[data-action="go-to-section-based-on-answers-enable"]').addClass('display_none');
2408
2409 if( returnElem ){
2410 return clonedElement;
2411 }else{
2412 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"] .ays-survey-answers-conteiner').html(clonedElement);
2413 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"] .ays-survey-other-answer-and-actions-row').html('');
2414 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_star').html('');
2415 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date').html('');
2416 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_time').html('');
2417 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date_time').html('');
2418
2419 }
2420 }
2421
2422 function aysSurveyQuestionType_Date_Html(sectionId, questionId, questionDataName, questionType, questionTypeBeforeChange, returnElem = false, sectionElem = null){
2423
2424 var section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box[data-id="'+sectionId+'"]');
2425 var question = section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"]');
2426 var cloningElement = $(document).find('.ays-question-to-clone .ays-survey-question-types_date');
2427 var clonedElement = cloningElement.clone( true, false );
2428
2429 var sectionName = section.attr('data-name');
2430 if( sectionElem !== null ){
2431 sectionName = sectionElem.attr('data-name');
2432 }
2433
2434 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-answer-elem-box').css('display','block');
2435 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-description-box').css('display','flex');
2436
2437 question.find('.ays-survey-question-word-limitations').addClass('display_none');
2438 question.find('.ays-survey-question-number-limitations').addClass('display_none');
2439 question.find('.ays-survey-question-action[data-action="enable-user-explanation"]').show();
2440 question.find('.ays-survey-question-more-option-wrap').addClass('display_none');
2441 if(returnElem){
2442 return clonedElement;
2443 }else{
2444 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-answers-conteiner').html(clonedElement);
2445 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_linear_scale').html('');
2446
2447 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_nps').html('');
2448
2449 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_star').html('');
2450 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-other-answer-and-actions-row').html('');
2451 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-matrix_scale').html(' ');
2452 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-matrix_scale_checkbox').html(' ');
2453 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_range').html('');
2454 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-star_list').html('');
2455 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-slider_list').html('');
2456 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_html').html('');
2457 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_calculation').html('');
2458 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_time').html('');
2459 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date_time').html('');
2460 }
2461
2462 }
2463
2464 function aysSurveyQuestionType_Time_Html(sectionId, questionId, questionDataName, questionType, questionTypeBeforeChange, returnElem = false, sectionElem = null){
2465
2466 var section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box[data-id="'+sectionId+'"]');
2467 var question = section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"]');
2468 var cloningElement = $(document).find('.ays-question-to-clone .ays-survey-question-types_time');
2469 var clonedElement = cloningElement.clone( true, false );
2470
2471 var sectionName = section.attr('data-name');
2472 if( sectionElem !== null ){
2473 sectionName = sectionElem.attr('data-name');
2474 }
2475
2476 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-answer-elem-box').css('display','block');
2477 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-description-box').css('display','flex');
2478
2479 question.find('.ays-survey-question-word-limitations').addClass('display_none');
2480 question.find('.ays-survey-question-number-limitations').addClass('display_none');
2481 question.find('.ays-survey-question-action[data-action="enable-user-explanation"]').show();
2482 question.find('.ays-survey-question-more-option-wrap').addClass('display_none');
2483 if(returnElem){
2484 return clonedElement;
2485 }else{
2486 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-answers-conteiner').html(clonedElement);
2487 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_linear_scale').html('');
2488
2489 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_star').html('');
2490 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-other-answer-and-actions-row').html('');
2491 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date').html('');
2492 }
2493
2494 }
2495
2496
2497 function aysSurveyQuestionType_Date_Time_Html(sectionId, questionId, questionDataName, questionType, questionTypeBeforeChange, returnElem = false, sectionElem = null){
2498
2499 var section = $(document).find('.ays-survey-sections-conteiner .ays-survey-section-box[data-id="'+sectionId+'"]');
2500 var question = section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"][data-name="'+questionDataName+'"]');
2501 var cloningElement = $(document).find('.ays-question-to-clone .ays-survey-question-types_date_time');
2502 var clonedElement = cloningElement.clone( true, false );
2503
2504 var sectionName = section.attr('data-name');
2505 if( sectionElem !== null ){
2506 sectionName = sectionElem.attr('data-name');
2507 }
2508
2509 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-answer-elem-box').css('display','block');
2510 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-description-box').css('display','flex');
2511
2512 question.find('.ays-survey-question-word-limitations').addClass('display_none');
2513 question.find('.ays-survey-question-number-limitations').addClass('display_none');
2514 question.find('.ays-survey-question-action[data-action="enable-user-explanation"]').show();
2515 question.find('.ays-survey-question-more-option-wrap').addClass('display_none');
2516 if(returnElem){
2517 return clonedElement;
2518 }else{
2519 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-answers-conteiner').html(clonedElement);
2520 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_linear_scale').html('');
2521
2522 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_star').html('');
2523 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-other-answer-and-actions-row').html('');
2524 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_date').html('');
2525 section.find('.ays-survey-question-answer-conteiner[data-id="'+questionId+'"] .ays-survey-question-types_time').html('');
2526
2527 }
2528
2529 }
2530
2531 function aysSurveyAddAnswer( currentAnswer, afterAnswer, isFromTemplate = false ){
2532 var $this = currentAnswer;
2533 var section = $this.parents('.ays-survey-section-box');
2534 var sectionId = section.attr('data-id');
2535 var questsCont = $this.parents('.ays-survey-question-answer-conteiner');
2536 var itemId = questsCont.data('id');
2537 var answersCont = questsCont.find('.ays-survey-answers-conteiner');
2538 var cloningElement = answersCont.find('.ays-survey-answer-row:first-child');
2539 var id = cloningElement.data('id');
2540 var answerLength = answersCont.find('.ays-survey-answer-row').length + 1;
2541
2542 var clone = cloningElement.clone(true, false).attr('data-id', answerLength);
2543
2544 if( afterAnswer === true ){
2545 clone.insertAfter(currentAnswer.parents('.ays-survey-answer-row'));
2546 }else{
2547 clone.appendTo(answersCont);
2548 }
2549
2550 questsCont = clone.parents('.ays-survey-question-answer-conteiner');
2551 itemId = questsCont.data('id');
2552 var answerContainer = questsCont.find('.ays-survey-answers-conteiner');
2553 var length = answerContainer.find('.ays-survey-answer-row').length;
2554 var clonedElem = clone.find('.ays-survey-input');
2555 var clonedElemInp = clonedElem.val('Option '+ length).attr('placeholder', 'Option '+ length);
2556
2557 clonedElem.attr('name', newAnswerAttrName( section.attr('data-name'), sectionId, questsCont.attr('data-name'), itemId, length, 'title'));
2558 // clonedElem.find('.aysAnswerImgConteiner').html('');
2559 // clonedElemInp.select();
2560 if(!isFromTemplate){
2561 clonedElemInp.trigger('focus');
2562 }
2563
2564 clone.addClass('ays-survey-new-answer');
2565 clone.find('.ays-survey-answer-image-container').hide();
2566 clone.find('.ays-survey-answer-image-container .ays-survey-answer-img').removeAttr('src');
2567 clone.find('.ays-survey-answer-image-container .ays-survey-answer-img-src').val('');
2568 clone.find('.ays-survey-answer-image-container .ays-survey-answer-img-src').attr('name', newAnswerAttrName( section.attr('data-name'), sectionId, questsCont.attr('data-name'), itemId, length, 'image'));
2569 clone.find('.ays-survey-answer-ordering').attr('name', newAnswerAttrName( section.attr('data-name'), sectionId, questsCont.attr('data-name'), itemId, length, 'ordering'));
2570
2571 answersCont.find('.ays-survey-answer-ordering').each(function(i){
2572 $(this).val( i + 1 );
2573 });
2574
2575 // clone.find('.ays-survey-answer-ordering').val( length );
2576 var deleteButton = answerContainer.find('.ays-survey-answer-delete');
2577 if(length == 1){
2578 deleteButton.css('visibility', 'hidden');
2579 }else{
2580 deleteButton.removeAttr('style');
2581 }
2582 answerContainer.sortable(answerDragHandle);
2583 reInitPopovers( clone );
2584 }
2585
2586 function draggedQuestionUpdate( element, section, oldSection){
2587
2588
2589 var questionsLength = section.find('.ays-survey-question-answer-conteiner').length;
2590 var questionsCount = questionsLength;
2591 var questionsCountBox = section.find(".ays-survey-action-questions-count span").text(questionsCount);
2592
2593 if(oldSection){
2594 var oldQuestionsLength = oldSection.find('.ays-survey-question-answer-conteiner').length;
2595 var oldQuestionsCount = oldQuestionsLength;
2596 var questionsCountBox = oldSection.find(".ays-survey-action-questions-count span").text(oldQuestionsCount);
2597 }
2598
2599 var answers = element.find('.ays-survey-answers-conteiner .ays-survey-answer-row');
2600 var questionName = element.attr('data-name');
2601 var questionId = element.attr('data-id');
2602 if( element.hasClass('ays-survey-new-question') ){
2603 questionId = section.find('.ays-survey-question-answer-conteiner[data-name="questions_add"]').length;
2604 }
2605
2606 var sectionName = section.attr('data-name');
2607 var sectionId = section.attr('data-id');
2608
2609 element.find('textarea.ays-survey-input').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'title'));
2610 element.find('.ays-survey-question-type-box select').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'type'));
2611 element.find('.ays-survey-question-img-src').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'image'));
2612 element.find('.ays-survey-other-answer-checkbox').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'user_variant'));
2613 element.find('.ays-survey-input-required-question').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'required'));
2614 element.find('.ays-survey-question-collapsed-input').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'collapsed'));
2615 element.find('.ays-survey-question-ordering').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'ordering'));
2616 element.find('.ays-survey-question-max-selection-count-checkbox').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'enable_max_selection_count'));
2617 element.find('.ays-survey-question-max-selection-count input.ays-survey-input').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'max_selection_count'));
2618 element.find('.ays-survey-question-min-selection-count input.ays-survey-input').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'min_selection_count'));
2619 // Text limitation options
2620 element.find('.ays-survey-question-word-limitations-checkbox').attr('name', updateQuestionAttrName(sectionName, sectionId, questionName, questionId, 'options', 'enable_word_limitation'));
2621 element.find('.ays-survey-question-more-option-wrap-limitations .ays-survey-question-word-limit-by-select select').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'limit_by'));
2622 element.find('.ays-survey-question-more-option-wrap-limitations input.ays-survey-limit-length-input').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'limit_length'));
2623 element.find('.ays-survey-question-more-option-wrap-limitations .ays-survey-text-limitations-counter-input').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'limit_counter'));
2624 // Number limitation options start
2625 element.find('.ays-survey-question-number-limitations-checkbox').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'enable_number_limitation'));
2626 element.find('.ays-survey-question-number-limitations input.ays-survey-number-min-votes').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'number_min_selection'));
2627 element.find('.ays-survey-question-number-limitations input.ays-survey-number-max-votes').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'number_max_selection'));
2628 element.find('.ays-survey-question-number-limitations input.ays-survey-number-error-message').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'number_error_message'));
2629 element.find('.ays-survey-question-number-limitations input.ays-survey-number-enable-error-message').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'enable_number_error_message'));
2630 element.find('.ays-survey-question-number-limitations input.ays-survey-number-limit-length').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'number_limit_length'));
2631 element.find('.ays-survey-question-number-limitations input.ays-survey-number-number-limit-length').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'enable_number_limit_counter'));
2632 // Number limitation options end
2633
2634 // Input types placeholders
2635 element.find('.ays-survey-remove-default-border.ays-survey-question-types-input.ays-survey-question-types-input-with-placeholder').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'placeholder'));
2636
2637 element.find('.ays-survey-question-image-caption').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'image_caption'));
2638 element.find('.ays-survey-question-img-caption-enable').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'image_caption_enable'));
2639
2640 element.find('.ays-survey-open-question-editor-flag').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'with_editor'));
2641
2642 element.find('.ays-survey-question-admin-note-saver').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'enable_admin_note'));
2643 element.find('.ays-survey-question-admin-note-label input.ays-survey-input').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'admin_note'));
2644
2645 answers.each(function(){
2646 var answerId = $(this).attr('data-id');
2647 var answerName = $(this).hasClass('ays-survey-new-answer') ? 'answers_add' : 'answers';
2648 $(this).find('.ays-survey-answer-box input.ays-survey-input').attr('name', updateAnswerAttrName( sectionName, sectionId, questionName, questionId, answerName, answerId, 'title'));
2649 $(this).find('.ays-survey-answer-img-src').attr('name', updateAnswerAttrName( sectionName, sectionId, questionName, questionId, answerName, answerId, 'image'));
2650 $(this).find('.ays-survey-answer-ordering').attr('name', updateAnswerAttrName( sectionName, sectionId, questionName, questionId, answerName, answerId, 'ordering'));
2651 });
2652
2653 // Star start
2654 element.find('.ays-survey-choose-for-select-lenght').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'scale_length'));
2655 element.find('.ays-survey-input-star-1').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'star_1'));
2656 element.find('.ays-survey-input-star-2').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'star_2'));
2657 element.find('.ays-survey-choose-for-start-select-lenght').attr('name', updateQuestionAttrName( sectionName, sectionId, questionName, questionId, 'options', 'star_scale_length'));
2658 // Star end
2659
2660 setTimeout(function(){
2661 element.goToTop();
2662 }, 100 );
2663 }
2664
2665 function newSectionAttrName(sectionId, field, field2 = null){
2666 if(field2 !== null){
2667 return $html_name_prefix + 'section_add['+ sectionId +']['+ field +']['+ field2 +']';
2668 }
2669 return $html_name_prefix + 'section_add['+ sectionId +']['+ field +']';
2670 }
2671
2672 function newQuestionAttrName(sectionName, sectionId, questionId, field, field2 = null){
2673 if(field2 !== null){
2674 return sectionName + '['+ sectionId +'][questions_add]['+ questionId +']['+ field +']['+ field2 +']';
2675 }
2676 return sectionName + '['+ sectionId +'][questions_add]['+ questionId +']['+ field +']';
2677 }
2678
2679 function newAnswerAttrName( sectionName, sectionId, questionName, questionId, answerId, field, field2 = null){
2680 if(field2 !== null){
2681 return sectionName + '['+ sectionId +']['+ questionName +']['+ questionId +'][answers_add]['+ answerId +']['+ field +']['+ field2 +']';
2682 }
2683 return sectionName + '['+ sectionId +']['+ questionName +']['+ questionId +'][answers_add]['+ answerId +']['+ field +']';
2684 }
2685
2686 function updateSectionAttrName( sectionName, sectionId, field, field2 = null){
2687 if(field2 !== null){
2688 return sectionName + '['+ sectionId +']['+ field +']['+ field2 +']';
2689 }
2690 return sectionName + '['+ sectionId +']['+ field +']';
2691 }
2692
2693 function updateQuestionAttrName( sectionName, sectionId, questionName, questionId, field, field2 = null){
2694 if(field2 !== null){
2695 return sectionName + '['+ sectionId +']['+ questionName +']['+ questionId +']['+ field +']['+ field2 +']';
2696 }
2697 return sectionName + '['+ sectionId +']['+ questionName +']['+ questionId +']['+ field +']';
2698 }
2699
2700 function updateAnswerAttrName( sectionName, sectionId, questionName, questionId, answerName, answerId, field, field2 = null){
2701 if(field2 !== null){
2702 return sectionName + '['+ sectionId +']['+ questionName +']['+ questionId +']['+ answerName +']['+ answerId +']['+ field +']['+ field2 +']';
2703 }
2704 return sectionName + '['+ sectionId +']['+ questionName +']['+ questionId +']['+ answerName +']['+ answerId +']['+ field +']';
2705 }
2706
2707 function reInitPopovers( parentElement ){
2708 parentElement.find('[data-toggle="popover"]').each(function(){
2709 $(this).popover();
2710 });
2711 }
2712
2713 function aysSurveySectionsInitToMoveQuestions( currentSection, currentQuestion ){
2714 var popup = $(document).find('#ays-survey-move-to-section');
2715 var currentSectionId = popup.attr('data-section-id');
2716 var sectionCont = $(document).find('.ays-survey-sections-conteiner');
2717 var sections = sectionCont.find('.ays-survey-section-box');
2718 var moveSectionsCont = popup.find('.ays-survey-move-to-section-sections-wrap');
2719 moveSectionsCont.html('');
2720
2721 sections.each(function(i){
2722 var _this = $(this);
2723 var sectionQuestionsCollapsedInputs = _this.find('.ays-survey-question-collapsed-input');
2724 var sectionQuestionsCollapsedValues = [];
2725 var sectionQuestionsExpandedValues = [];
2726 sectionQuestionsCollapsedInputs.each(function(){
2727 if( $(this).val() == 'expanded' ){
2728 sectionQuestionsExpandedValues.push( true );
2729 }else{
2730 sectionQuestionsCollapsedValues.push( true );
2731 }
2732 });
2733
2734 var collapseButtonText = SurveyMakerAdmin.collapseSectionQuestions;
2735 if( sectionQuestionsExpandedValues.length == 0 ){
2736 collapseButtonText = SurveyMakerAdmin.expandSectionQuestions;
2737 }
2738
2739 var disabled = '';
2740 if( currentSectionId == _this.attr('data-id') ){
2741 disabled = ' disabled ';
2742 }
2743
2744 var newClassToAddQuestion = '';
2745 if( _this.hasClass('ays-survey-new-section') ){
2746 newClassToAddQuestion = 'ays-survey-move-new-question-into-section';
2747 }
2748
2749 _this.find('.ays-survey-collapse-section-questions').text( collapseButtonText );
2750
2751 var buttonItem = '<button class="dropdown-item ays-survey-move-question-into-section '+ newClassToAddQuestion +'" ' + disabled + ' data-id="'+ $(this).data('id') +'" type="button">';
2752 buttonItem += aysCreateSectionName( _this, i+1, SurveyMakerAdmin.moveToSection ); //SurveyMakerAdmin.addIntoSection + ' ' + (i+1);
2753 buttonItem += '</button>';
2754 moveSectionsCont.append(buttonItem);
2755 });
2756 }
2757
2758 function aysCreateSectionName( section, index, text ){
2759 var sectionName = section.find('.ays-survey-section-title').val();
2760 var name = text + ' ' + index;
2761 if( sectionName == '' ){
2762 name += ' (Untitled Form) ';
2763 }else{
2764 name += ' ('+ sectionName +') ';
2765 }
2766 return name;
2767 }
2768
2769
2770 $(document).find('#ays_select_surveys').select2({
2771 allowClear: true,
2772 placeholder: false
2773 });
2774
2775 $(document).find('#ays_user_roles').select2({
2776 allowClear: true,
2777 placeholder: SurveyMakerAdmin.selectUserRoles
2778 });
2779
2780 $(document).find('#ays_survey_default_type').select2({
2781 allowClear: true,
2782 placeholder: SurveyMakerAdmin.selectQuestionDefaultType
2783 });
2784
2785 $(document).find('.ays-survey-submission-select').aysDropdown();
2786
2787 $(document).find('.ays-survey-sections-conteiner .ays-survey-question-type').aysDropdown({
2788 // allowClear: true,
2789 // placeholder: false
2790 });
2791
2792 /* CONTINUE FROM HERE */
2793 // $(document).find('.ays-survey-sections-conteiner .ays-survey-question-type').aysDropdown({
2794 // // allowClear: true,
2795 // // placeholder: false
2796 // });
2797
2798 $(document).find('.ays-survey-sections-conteiner .dropdown .item[data-value="email"]').before('<div class="divider"></div>');
2799 $(document).find('.ays-survey-sections-conteiner .dropdown .item[data-value="matrix_scale"]').before('<div class="divider"></div>');
2800
2801
2802
2803 // ===============================================================
2804 // ====================== Ani ==========================
2805 // ===============================================================
2806
2807 var count = 0;
2808 $(document).find('.ays_survey_previous_next').on('click',function(){
2809 if($(this).attr('data-name') == 'ays_survey_next'){
2810 if($(document).find('.ays_number_of_result').val() == $(document).find('.ays_number_of_result').attr('max')){
2811 count = $(document).find('.ays_number_of_result').attr('min');
2812 $(document).find('.ays_number_of_result').val(count);
2813 }else{
2814 var selectVal = parseInt($(document).find('.ays_number_of_result').val());
2815 count = selectVal + 1;
2816 $(document).find('.ays_number_of_result').val(count);
2817 }
2818 }else if($(this).attr('data-name') == 'ays_survey_previous'){
2819 if($(document).find('.ays_number_of_result').val() == $(document).find('.ays_number_of_result').attr('min')){
2820 count = $(document).find('.ays_number_of_result').attr('max');
2821 $(document).find('.ays_number_of_result').val(count);
2822 }else{
2823 var selectVal = parseInt($(document).find('.ays_number_of_result').val());
2824 count = selectVal - 1;
2825 $(document).find('.ays_number_of_result').val(count);
2826 }
2827 }
2828 $(document).find('.ays_number_of_result').trigger('change');
2829 });
2830
2831 $(document).find('.ays_number_of_result').on('change', refreshSubmissionData);
2832 // $(document).find('.ays_number_of_result').on('input', refreshSubmissionData);
2833
2834 function refreshSubmissionData(){
2835 var submissionPrevVal;
2836 var $this = $(this);
2837
2838 var parent = $(this).parents('.ays_survey_previous_next_conteiner');
2839 var mainParent = $this.parents('.ays_survey_container_each_result');
2840 var submissionInputs = mainParent.find(".ays_number_of_result ");
2841 var currentNumber = $this.val();
2842 if(+$this.val() > +$this.attr("max") || $this.val() == "" || +$this.val() == 0){
2843 currentNumber = $this.attr("max");
2844 }
2845 submissionInputs.val(currentNumber);
2846
2847 var submissionIdStr = parent.find('.ays_submissions_id_str').val();
2848 var submissionIdArr = submissionIdStr.split(",");
2849 var submissionElVal = parseInt(parent.find('.ays_number_of_result').val());
2850 var surveyId = $(document).find('.ays_number_of_result').attr('data-id');
2851 var submissionId = '';
2852 var data = {};
2853
2854 if(submissionElVal < 0){
2855 submissionElVal = 1;
2856 parseInt(parent.find('.ays_number_of_result').val(1));
2857 }else if(submissionElVal > parseInt(parent.find('.ays_number_of_result').attr('max'))){
2858 var maxVal = parseInt(parent.find('.ays_number_of_result').attr('max'));
2859 parseInt(parent.find('.ays_number_of_result').val(maxVal));
2860 submissionElVal = maxVal;
2861 }
2862
2863 if(submissionElVal>submissionPrevVal || submissionElVal+1){
2864 submissionId = submissionIdArr[submissionElVal-1];
2865 }else{
2866 submissionId = submissionIdArr[submissionElVal+1];
2867 }
2868
2869 data.action = 'ays_survey_submission_report';
2870 data.submissionId = submissionId;
2871 data.surveyId = surveyId;
2872 data.nonce = SurveyMakerAdmin.nonce;
2873 var preloader = $(this).parents('.ays_survey_container_each_result').find('.question_result_container').find('div.ays_survey_preloader');
2874 preloader.css({'display':'flex'});
2875 $.ajax({
2876 url: ajaxurl,
2877 dataType: 'json',
2878 data: data,
2879 method: 'post',
2880 success: function(response){
2881 if (response.status) {
2882 preloader.css({'display':'none'});
2883 var questionsData = response.questions;
2884 var questionsInHTML = $(document).find('.ays_questions_answers');
2885 $(document).find(".ays_survey_each_sub_user_info_name").html(response.user_info.user_name);
2886 $(document).find(".ays_survey_each_sub_user_info_email").text(response.user_info.user_email);
2887 $(document).find(".ays_survey_each_sub_user_info_user_ip").html(response.user_info.user_ip);
2888 $(document).find(".ays_survey_each_sub_user_info_sub_date").html(response.user_info.submission_date);
2889 $(document).find(".ays_survey_each_sub_user_info_sub_id").html(response.user_info.id);
2890 if(typeof response.user_info.user_device_type != 'undefined' && response.user_info.user_device_type){
2891 $(document).find(".ays_survey_each_sub_user_info_device_type").parents('.ays_survey_each_sub_user_info_columns').show();
2892 $(document).find(".ays_survey_each_sub_user_info_device_type").html(response.user_info.user_device_type);
2893 }
2894 else{
2895 $(document).find(".ays_survey_each_sub_user_info_device_type").parents('.ays_survey_each_sub_user_info_columns').hide();
2896 }
2897 $(document).find(".ays_survey_each_sub_user_info_header_button button").attr("data-clipboard-text", response.user_info_for_copy);
2898 $.each(questionsInHTML, function(){
2899 var question = $(this);
2900 var qId = question.data('id');
2901 var qType = question.data('type');
2902
2903 question.find('.ays_each_question_answer input[type="radio"]').removeAttr('checked');
2904 question.find('.ays_each_question_answer input[type="checkbox"]').removeAttr('checked');
2905 question.find('.ays_each_question_answer .ays-survey-submission-select option').removeAttr('selected');
2906 question.find('.ays_text_answer').html('');
2907
2908 if( typeof questionsData[qId] != 'undefined'){
2909 var surveyAnswer = questionsData[qId];
2910 switch( qType ){
2911 case 'radio':
2912 case 'yesorno':
2913 surveyAnswer = questionsData[qId].answer;
2914 var surveyOtherAnswer = questionsData[qId].otherAnswer;
2915 question.find('.ays_each_question_answer input[type="radio"]').removeAttr('checked');
2916 question.find('.ays_each_question_answer input[type="radio"]').each(function(){
2917 var thisParent = $(this).parents(".ays_each_question_answer");
2918 if( surveyAnswer == $(this).data('id') ){
2919
2920 if(thisParent.hasClass("ays-survey-answer-label-other") && surveyOtherAnswer != ''){
2921 $(this).prop('checked', true);
2922 }
2923 else if(!thisParent.hasClass("ays-survey-answer-label-other")){
2924 $(this).prop('checked', true);
2925 }
2926
2927 }
2928 });
2929
2930 question.find('.ays-survey-answer-other-input').html((surveyOtherAnswer));
2931 break;
2932 case 'checkbox':
2933 surveyAnswer = questionsData[qId].answer;
2934 var surveyOtherAnswer = questionsData[qId].otherAnswer;
2935 question.find('.ays_each_question_answer input[type="checkbox"]').removeAttr('checked');
2936 question.find('.ays_each_question_answer input[type="checkbox"]').each(function(){
2937 if( Array.isArray(surveyAnswer) ){
2938 for(var i=0; i < surveyAnswer.length; i++){
2939 if( surveyAnswer[i] == $(this).data('id') ){
2940 $(this).prop('checked', true);
2941 }
2942 }
2943 }else{
2944 if( surveyAnswer == $(this).data('id') ){
2945 $(this).prop('checked', true);
2946 }
2947 }
2948 });
2949 question.find('.ays-survey-answer-other-input').html((surveyOtherAnswer));
2950 break;
2951 case 'select':
2952 if( parseInt( surveyAnswer ) == 0 ){
2953 question.find('.ays_each_question_answer .ays-survey-submission-select').aysDropdown('clear');
2954 question.find('.ays_each_question_answer .ays-survey-submission-select').aysDropdown('set value', '');
2955 }else{
2956 question.find('.ays_each_question_answer .ays-survey-submission-select').aysDropdown('set selected', surveyAnswer);
2957 question.find('.ays_each_question_answer .ays-survey-submission-select').aysDropdown('set value', surveyAnswer);
2958 }
2959 break;
2960 case 'star':
2961 surveyAnswer = questionsData[qId];
2962 question.find('.ays_each_question_answer input[type="radio"]').removeAttr('checked');
2963 question.find('.ays-survey-star-icon').removeClass('fa_star').addClass('fa_star_o');
2964 question.find('.ays-survey-star-icon').css('color', 'rgb(51, 51, 51)');
2965 question.find('.ays_each_question_answer input[type="radio"]').each(function(){
2966
2967 if( parseInt( surveyAnswer ) >= $(this).data('id') ){
2968 $(this).prop('checked', true);
2969 $(this).parents('.ays-survey-answer-star-radio').find('.ays-survey-star-icon').removeClass('fa_star_o').addClass('fa_star');
2970 $(this).parents('.ays-survey-answer-star-radio').find('.ays-survey-star-icon').css('color', 'rgb(255, 87, 34)');
2971 }
2972 });
2973 break;
2974 case 'text':
2975 if( typeof surveyAnswer !== 'string' ){
2976 surveyAnswer = '';
2977 }
2978 surveyAnswer = nl2br( surveyAnswer );
2979 case 'short_text':
2980 case 'number':
2981 case 'phone':
2982 case 'name':
2983 case 'email':
2984 var elem = question.find('.ays_text_answer');
2985 elem.html( surveyAnswer );
2986 break;
2987 case 'date':
2988 case 'time':
2989 case 'date_time':
2990 surveyAnswer = questionsData[qId];
2991 var elem = question.find('.ays_text_answer');
2992 if( typeof surveyAnswer === 'string' ){
2993 surveyAnswer = surveyAnswer;
2994 }else{
2995 surveyAnswer = surveyAnswer.answer;
2996 }
2997 elem.html( surveyAnswer );
2998 break;
2999 }
3000 }else{
3001 switch( qType ){
3002 case 'radio':
3003 case 'yesorno':
3004 question.find('.ays_each_question_answer input[type="radio"]').removeAttr('checked');
3005 question.find('.ays-survey-answer-other-input').val('');
3006 break;
3007 case 'checkbox':
3008 question.find('.ays_each_question_answer input[type="checkbox"]').removeAttr('checked');
3009 question.find('.ays-survey-answer-other-input').val('');
3010 break;
3011 case 'select':
3012 question.find('.ays_each_question_answer .ays-survey-submission-select').aysDropdown('clear');
3013 question.find('.ays_each_question_answer .ays-survey-submission-select').aysDropdown('set value', '');
3014 break;
3015 case 'star':
3016 question.find('.ays_each_question_answer input[type="radio"]').removeAttr('checked');
3017 question.find('.ays-survey-star-icon').removeClass('fa_star').addClass('fa_star_o');
3018 question.find('.ays-survey-star-icon').css('color', 'rgb(51, 51, 51)');
3019 break;
3020 case 'text':
3021 case 'short_text':
3022 case 'number':
3023 case 'phone':
3024 case 'name':
3025 case 'email':
3026 case 'date':
3027 case 'time':
3028 var elem = question.find('.ays_text_answer');
3029 elem.html( '' );
3030 break;
3031 }
3032 }
3033 });
3034 }
3035 }
3036 });
3037 submissionPrevVal = submissionElVal;
3038 }
3039
3040
3041
3042 // ===============================================================
3043 // ====================== Xcho =========================
3044 // ===============================================================
3045
3046
3047 $('#ays_slack_client').on('input', function () {
3048 var clientId = $(this).val();
3049 if (clientId == '') {
3050 $("#slackOAuth2").addClass('disabled btn-outline-secondary');
3051 $("#slackOAuth2").removeClass('btn-secondary');
3052 return false;
3053 }
3054 var scopes = "channels%3Ahistory%20" +
3055 "channels%3Aread%20" +
3056 "channels%3Awrite%20" +
3057 "groups%3Aread%20" +
3058 "groups%3Awrite%20" +
3059 "mpim%3Aread%20" +
3060 "mpim%3Awrite%20" +
3061 "im%3Awrite%20" +
3062 "im%3Aread%20" +
3063 "chat%3Awrite%3Abot%20" +
3064 "chat%3Awrite%3Auser";
3065 var url = "https://slack.com/oauth/authorize?client_id=" + clientId + "&scope=" + scopes + "&state=" + clientId;
3066 $("#slackOAuth2").attr('data-src', url);//.toggleClass('disabled btn-outline-secondary btn-secondary');
3067 $("#slackOAuth2").removeClass('disabled btn-outline-secondary');
3068 $("#slackOAuth2").addClass('btn-secondary');
3069 });
3070 $("#slackOAuth2").on('click', function () {
3071 var url = $(this).attr('data-src');
3072 if (!url) {
3073 return false;
3074 }
3075 location.replace(url)
3076 });
3077 $('#ays_slack_secret').on('input', function(e) {
3078 if($(this).val() == ''){
3079 $("#slackOAuthGetToken").addClass('disabled btn-outline-secondary');
3080 $("#slackOAuthGetToken").removeClass('btn-secondary');
3081 return false;
3082 }
3083
3084 $("#slackOAuthGetToken").removeClass('disabled btn-outline-secondary');
3085 $("#slackOAuthGetToken").addClass('btn-secondary');
3086 });
3087
3088 // Limitations PRO
3089 $('#ays_survey_users_roles,#ays_survey_users_pro').select2();
3090
3091 $(document).find('#ays_survey_default_type').select2({
3092 allowClear: true,
3093 placeholder: SurveyMakerAdmin.selectQuestionDefaultType
3094 });
3095
3096 $(document).find(".ays-survey-min-votes-field").on("input" , function(){
3097 var $this = $(this);
3098 var minVal = parseInt($(this).val());
3099 var maxField = $this.parents(".ays-survey-question-more-options-wrap").find(".ays-survey-max-votes-field");
3100 if(minVal >= maxField.val())
3101 maxField.val(minVal);
3102 });
3103
3104 $(document).find(".ays-survey-max-votes-field").on("change" , function(){
3105 var $this = $(this);
3106 var maxVal = parseInt($(this).val());
3107 var minField = $this.parents(".ays-survey-question-more-options-wrap").find(".ays-survey-min-votes-field");
3108 var minVal = $this.parents(".ays-survey-question-more-options-wrap").find(".ays-survey-min-votes-field").val();
3109 if(maxVal == ''){
3110 return;
3111 }
3112 if(maxVal < minVal){
3113 $this.val(minVal);
3114 }
3115 });
3116
3117 $(document).on('click', '.ays_toggle_loader_radio', function (e) {
3118 var dataFlag = $(this).attr('data-flag');
3119 var dataType = $(this).attr('data-type');
3120 var state = false;
3121 if (dataFlag == 'true') {
3122 state = true;
3123 }
3124
3125 var parent = $(this).parents('.ays_toggle_loader_parent');
3126 if($(this).hasClass('ays_toggle_loader_slide')){
3127 switch (state) {
3128 case true:
3129 parent.find('.ays_toggle_loader_target').slideDown(250);
3130 break;
3131 case false:
3132 parent.find('.ays_toggle_loader_target').slideUp(250);
3133 break;
3134 }
3135 }else{
3136 switch (state) {
3137 case true:
3138 switch( dataType ){
3139 case 'text':
3140 parent.find('.ays_toggle_loader_target[data-type="'+ dataType +'"]').show(250);
3141 parent.find('.ays_toggle_loader_target[data-type="gif"]').hide(250);
3142 break;
3143 case 'gif':
3144 parent.find('.ays_toggle_loader_target[data-type="'+ dataType +'"]').show(250);
3145 parent.find('.ays_toggle_loader_target.ays_gif_loader_width_container[data-type="'+ dataType +'"]').css({
3146 'display': 'flex',
3147 'justify-content': 'center',
3148 'align-items': 'center'
3149 });
3150 parent.find('.ays_toggle_loader_target[data-type="text"]').hide(250);
3151 break;
3152 default:
3153 parent.find('.ays_toggle_loader_target').show(250);
3154 break;
3155 }
3156 break;
3157 case false:
3158 switch( dataType ){
3159 case 'text':
3160 parent.find('.ays_toggle_loader_target[data-type="'+ dataType +'"]').hide(250);
3161 break;
3162 case 'gif':
3163 parent.find('.ays_toggle_loader_target[data-type="'+ dataType +'"]').hide(250);
3164 break;
3165 default:
3166 parent.find('.ays_toggle_loader_target').hide(250);
3167 break;
3168 }
3169 break;
3170 }
3171 }
3172 });
3173
3174 $(document).find(".add_survey_loader_custom_gif,.ays-edit-survey-loader-custom-gif").on("click" , function(e){
3175 openMediaUploaderForGifLoader(e, $(this));
3176 });
3177
3178 $(document).on('click', '.ays-survey-image-wrapper-delete-wrap', function () {
3179 var wrap = $(this).parents('.ays-survey-image-wrap');
3180 wrap.find('.ays-survey-image-container').fadeOut(500);
3181 setTimeout(function(){
3182 wrap.find('img.ays_survey_img_loader_custom_gif').attr('src', '');
3183 wrap.find('input.ays-survey-image-path').val('');
3184 wrap.find('button.add_survey_loader_custom_gif').show();
3185 }, 450);
3186 });
3187
3188 $(document).find("#ays-survey-form .nav-tab").on("click" , function(){
3189 var $this = $(this);
3190 if($this.data("tab") != "undefined" && $this.data("tab") == 'tab1'){
3191 refreshSurveyColor($this);
3192 }
3193 });
3194
3195 function refreshSurveyColor(element){
3196 var customCss = $(document).find("#ays-survey-custom-css-additional");
3197 var parentElement = element.parents("#ays-survey-form");
3198 var surveyColor = parentElement.find("#ays_survey_color").val();
3199 var isModern = $(document).find('input[name="ays_survey_theme"]:checked').val() == 'modern' ? true : false;
3200 var isMinimal = $(document).find('input[name="ays_survey_theme"]:checked').val() == 'minimal' ? true : false;
3201 if( isMinimal || isModern ){
3202 if( parentElement.find("#ays_survey_color").val() == 'rgba(0,0,0,0)' ){
3203 surveyColor = '#333333';
3204 }
3205 }
3206
3207 var newCss = '#ays-survey-form .ays-survey-section-head-wrap .ays-survey-section-head {'
3208 newCss += 'border-top-color: '+surveyColor;
3209 newCss += '}';
3210 newCss += '#ays-survey-form .ays-survey-section-head-wrap .ays-survey-section-head-top .ays-survey-section-counter {'
3211 newCss += 'background-color: '+surveyColor;
3212 newCss += '}';
3213 newCss += '#ays-survey-form .ays-survey-input:focus ~ .ays-survey-input-underline-animation {'
3214 newCss += 'background-color: '+surveyColor;
3215 newCss += '}';
3216 newCss += '#ays-survey-form .dropdown-item:hover {'
3217 newCss += 'background-color: '+surveyColor+'29;';
3218 newCss += '}';
3219 newCss += '#ays-survey-form .dropdown-item:focus {'
3220 newCss += 'background-color: '+surveyColor+'29;';
3221 newCss += '}';
3222 newCss += '#ays-survey-form .dropdown-item:active {'
3223 newCss += 'background-color: '+surveyColor+';';
3224 newCss += '}';
3225 newCss += '#ays-survey-form input.ays-switch-checkbox:checked + .switch-checkbox-wrap .switch-checkbox-circles .switch-checkbox-thumb {'
3226 newCss += 'border-color: '+surveyColor;
3227 newCss += '}';
3228 newCss += '#ays-survey-form input.ays-switch-checkbox:checked + .switch-checkbox-wrap .switch-checkbox-track {'
3229 newCss += 'border-color: '+surveyColor+'53';
3230 newCss += '}';
3231 customCss.html(newCss);
3232 }
3233
3234 // var checkCountdownIsExists = $(document).find('#ays-survey-maker-countdown-main-container');
3235 var checkCountdownIsExists = $(document).find('#ays-survey-countdown-main-container');
3236
3237 if ( checkCountdownIsExists.length > 0 ) {
3238 var second = 1000,
3239 minute = second * 60,
3240 hour = minute * 60,
3241 day = hour * 24;
3242
3243 // var countdownEndTime = "DEC 05, 2025 23:59:59";
3244 var countdownEndTime = SurveyMakerAdmin.surveyBannerDate;
3245 var countDown = new Date(countdownEndTime).getTime(),
3246
3247 x = setInterval(function() {
3248
3249 var now = new Date().getTime(),
3250 distance = countDown - now;
3251
3252 var countDownDays = document.getElementById("ays-survey-countdown-days");
3253 var countDownHours = document.getElementById("ays-survey-countdown-hours");
3254 var countDownMinutes = document.getElementById("ays-survey-countdown-minutes");
3255 var countDownSeconds = document.getElementById("ays-survey-countdown-seconds");
3256
3257 if(countDownDays !== null || countDownHours !== null || countDownMinutes !== null || countDownSeconds !== null){
3258 countDownDays.innerText = Math.floor(distance / (day)),
3259 countDownHours.innerText = Math.floor((distance % (day)) / (hour)),
3260 countDownMinutes.innerText = Math.floor((distance % (hour)) / (minute)),
3261 countDownSeconds.innerText = Math.floor((distance % (minute)) / second);
3262 // countDownDays.innerText = Math.floor(distance / (day)).toLocaleString(undefined,{minimumIntegerDigits: 2})+" : ",
3263 // countDownHours.innerText = Math.floor((distance % (day)) / (hour)).toLocaleString(undefined,{minimumIntegerDigits: 2})+" : ",
3264 // countDownMinutes.innerText = Math.floor((distance % (hour)) / (minute)).toLocaleString(undefined,{minimumIntegerDigits: 2})+" : ",
3265 // countDownSeconds.innerText = Math.floor((distance % (minute)) / second).toLocaleString(undefined,{minimumIntegerDigits: 2});
3266
3267 }
3268
3269 //do something later when date is reached
3270 if (distance < 0) {
3271 var headline = document.getElementById("ays-survey-countdown-headline"),
3272 countdown = document.getElementById("ays-survey-countdown"),
3273 content = document.getElementById("ays-survey-countdown-content");
3274
3275 // headline.innerText = "Sale is over!";
3276 countdown.style.display = "none";
3277 content.style.display = "block";
3278
3279 clearInterval(x);
3280 }
3281 }, 1000);
3282 }
3283
3284 $(document).on('click', '.ays-survey-add-cover-image', function (e) {
3285 openMediaUploaderForCoverImage(e, $(this));
3286 });
3287
3288 $(document).on('click', '.removeCoverImage', function (e) {
3289 var $this = $(this);
3290 var thisParent = $this.parents('.ays_survey_cover_image_main');
3291 thisParent.find('.ays-survey-add-cover-image').html( SurveyMakerAdmin.addImage );
3292 thisParent.find('.ays-survey-image-body').fadeOut(500);
3293 thisParent.find('.ays-survey-cover-image-options,.ays-survey-cover-image-options-hr').fadeOut(500);
3294 setTimeout(function(){
3295 $this.parents('.ays-survey-image-container').find('.ays-survey-cover-img').removeAttr('src');
3296 $this.parents('.ays-survey-image-container').find('.ays-survey-cover-img-src').val('');
3297 }, 500);
3298 });
3299
3300 $(document).on('click', '.ays_survey_each_sub_user_info_header_button button', function () {
3301 selectElementContentsCopy($(this));
3302 });
3303
3304 var surveyResults = $(document).find('.ays_survey_result');
3305 for (var i in surveyResults) {
3306 surveyResults.eq(i).parents('tr').addClass('ays_survey_results');
3307 }
3308
3309 $(document).on("click", ".ays-survey-view-detailed-button", getEachSubmission);
3310
3311 $(document).on('click', '#ays-surveys-next-button,#ays-surveys-prev-button', function(e){
3312 e.preventDefault();
3313 var confirm;
3314 if($(e.target).hasClass("ays-survey-prev-survey-button")){
3315 confirm = window.confirm( SurveyMakerAdmin.prevSurveyPage );
3316 }
3317 else{
3318 confirm = window.confirm( SurveyMakerAdmin.nextSurveyPage );
3319 }
3320 if(confirm){
3321 window.location.replace($(this).attr('href'));
3322 }
3323 });
3324
3325 $(document).find('#ays-survey-title').on('input', function(e){
3326 var surveyTitleVal = $(this).val();
3327 var surveyTitle = aysSurveystripHTML( surveyTitleVal );
3328 $(document).find('.ays_survey_title_in_top').html( surveyTitle );
3329 });
3330
3331 // Select message vars surveys page
3332 $(document).find('.ays-survey-message-vars-icon').on('click', function(e){
3333 $(this).parents(".ays-survey-message-vars-box").find(".ays-survey-message-vars-data").toggle('fast');
3334 });
3335
3336 $(document).find('.ays-survey-open-surveys-list').on('click', function(e){
3337 $(this).parents(".ays-survey-subtitle-main-box").find(".ays-survey-surveys-data").toggle('fast');
3338 });
3339
3340 $(document).on( "click" , function(e){
3341
3342 if($(e.target).closest('.ays-survey-message-vars-box,.ays-survey-subtitle-main-box').length != 0){
3343
3344 }
3345 else{
3346 $(document).find(".ays-survey-message-vars-box .ays-survey-message-vars-data,.ays-survey-subtitle-main-box .ays-survey-surveys-data").hide('fast');
3347 }
3348 //
3349 });
3350
3351 $(document).find(".ays-survey-go-to-surveys").on("click" , function(e){
3352 e.preventDefault();
3353 var confirmRedirect = window.confirm('Are you sure you want to redirect to another survey? Note that the changes made in this survey will not be saved.');
3354 if(confirmRedirect){
3355 window.location = $(this).attr("href");
3356 }
3357 });
3358
3359 $(document).find('.ays-survey-message-vars-each-data').on('click', function(e){
3360 var messageVar = $(this).find(".ays-survey-message-vars-each-var").val();
3361 var mainParent = $(this).parents('.ays-survey-box-for-mv');
3362 var dataTMCE = mainParent.find('.ays-survey-message-vars-data').attr('data-tmce');
3363
3364 if ( mainParent.find("#wp-"+dataTMCE+"-wrap").hasClass("tmce-active") ){
3365 window.tinyMCE.get(dataTMCE).setContent( window.tinyMCE.get(dataTMCE).getContent() + messageVar + " " );
3366 }else{
3367 mainParent.find('#'+dataTMCE).append( " " + messageVar + " ");
3368 }
3369 });
3370 /* */
3371
3372 $(document).find('.ays-survey-add-new-button-video').on('click', function(e){
3373 $(document).find(".page-title-action").trigger("click");
3374 });
3375
3376 var ays_survey_popup_bg_color_picker = {
3377 defaultColor: '#ffffff',
3378 change: function (e) {
3379 }
3380 };
3381
3382 var ays_survey_popup_bg_color_mobile_picker = {
3383 defaultColor: '#ffffff',
3384 change: function (e) {
3385 }
3386 };
3387
3388 var aysSurveyPopupTitleTextColorPicker = {
3389 defaultColor: '#000000',
3390 change: function (e) {
3391 }
3392 };
3393
3394 var aysSurveyPopupTitleBgColorPicker = {
3395 defaultColor: '#00000000',
3396 change: function (e) {
3397 }
3398 };
3399
3400 $(document).find('#ays_survey_popup_trigger').on('change', function(){
3401 var triggerType = $(this).val();
3402 if(triggerType == 'on_click'){
3403 $(document).find('.ays-survey-popup-selector').show(250);
3404 $(document).find('.ays-survey-popup-selector').css('display','flex');
3405 $(document).find('.ays-survey-popup-selector').prev('hr').show(250);
3406 }else{
3407 $(document).find('.ays-survey-popup-selector').hide(250);
3408 $(document).find('.ays-survey-popup-selector').prev('hr').hide(250);
3409 }
3410 });
3411
3412 $(document).find('table#ays-survey-popup-position-table tr td').on('click', function(e){
3413 var val = $(this).data('value');
3414 $(document).find('.popup_survey_position_block #ays-survey-popup-position-val').val(val);
3415 aysCheckPopupPosition();
3416 });
3417
3418 $(document).find('table#ays-survey-position-table tr td').on('click', function(e){
3419 var val = $(this).data('value');
3420 $(document).find('.survey_position_block #ays-survey-position-val').val(val);
3421 aysCheckPosition();
3422 });
3423
3424 function aysCheckPopupPosition(){
3425 var hiddenVal = $(document).find('.popup_survey_position_block #ays-survey-popup-position-val').val();
3426
3427 if (hiddenVal == "") {
3428 var $this = $(document).find('table#ays-survey-popup-position-table tr td[data-value="center-center"]');
3429 }else{
3430 var $this = $(document).find('table#ays-survey-popup-position-table tr td[data-value='+ hiddenVal +']');
3431 }
3432
3433 if (hiddenVal == 'center-center' || hiddenVal == ''){
3434 $(document).find("#popupMargin").addClass('display_none');
3435 $(document).find(".ays_pb_hr_hide").addClass('display_none');
3436 }else{
3437 $(document).find("#popupMargin").removeClass('display_none');
3438 $(document).find(".ays_pb_hr_hide").removeClass('display_none');
3439 }
3440
3441 $(document).find('table#ays-survey-popup-position-table td').removeAttr('style');
3442 $this.css('background-color','#a2d6e7');
3443 }
3444
3445
3446 function aysCheckPosition(){
3447 var hiddenVal = $(document).find('.survey_position_block #ays-survey-position-val').val();
3448
3449 if (hiddenVal == "") {
3450 var $this = $(document).find('table#ays-survey-position-table tr td[data-value="center-center"]');
3451 }else{
3452 var $this = $(document).find('table#ays-survey-position-table tr td[data-value='+ hiddenVal +']');
3453 }
3454
3455 $(document).find('table#ays-survey-position-table td').removeAttr('style');
3456 $this.css('background-color','#a2d6e7');
3457 }
3458
3459 // Initialize popup survey color picker
3460 $(document).find('#ays_survey_popup_bg_color').wpColorPicker(ays_survey_popup_bg_color_picker);
3461 // Initialize popup survey color picker
3462 $(document).find('#ays_survey_popup_bg_color_mobile').wpColorPicker(ays_survey_popup_bg_color_mobile_picker);
3463 // Initialize popup survey title bg color picker
3464 $(document).find('#ays_survey_popup_title_bg_color,#ays_survey_popup_title_bg_color_mobile').wpColorPicker(aysSurveyPopupTitleBgColorPicker);
3465 // Initialize popup survey title text color picker
3466 $(document).find('#ays_survey_popup_title_text_color,#ays_survey_popup_title_text_color_mobile').wpColorPicker(aysSurveyPopupTitleTextColorPicker);
3467
3468 $(document).find('.ays-survey-aysDropdown-answer-view').on('change', function(e){
3469 var answerViewAligne = $(document).find('.ays-survey-aysDropdown-answer-view-alignment');
3470 answerViewAligne.aysDropdown('destroy');
3471 var answerViewType = $(this).aysDropdown('get value');
3472
3473 var dataObj = {
3474 'list': [
3475 {
3476 name : 'Left',
3477 value : 'flex-start',
3478 selected : true
3479 },
3480 {
3481 name : 'Right',
3482 value : 'flex-end',
3483 },
3484 {
3485 name : 'Center',
3486 value : 'center',
3487 }
3488 ],
3489 'grid': [
3490 {
3491 name : 'Space around',
3492 value : 'space-around',
3493 selected : true
3494 },
3495 {
3496 name : 'Space between',
3497 value : 'space-between',
3498 },
3499 {
3500 name : 'Left',
3501 value : 'flex-start',
3502 },
3503 {
3504 name : 'Right',
3505 value : 'flex-end',
3506 },
3507 {
3508 name : 'Center',
3509 value : 'center',
3510 }
3511 ]
3512 }
3513 answerViewAligne.aysDropdown({
3514 values: dataObj[answerViewType]
3515 });
3516 });
3517
3518 // Survey Templates start
3519 $(document).find(".ays-survey-open-templates-modal").on("click" , function(e){
3520 e.preventDefault();
3521 var $this = $('#ays-survey-templates-modal');
3522 $this.find('.ays-modal-content-survey-templates .ays-survey-templates-box.ays-survey-templates-blank-box').remove();
3523 $(document).find('#ays-survey-templates-modal').aysModal('show');
3524 $(document).find('#ays-survey-templates-modal .ays-modal-content-survey-templates-header .ays-close-templates-popup').attr('data-action' , 'in-edit-page');
3525 $(document).find('#ays-survey-templates-modal .ays-modal-content.ays-modal-content-survey-templates').removeClass('no-confirmation');
3526
3527 });
3528
3529 $(document).find(".ays-survey-templates-box-apply-button-blank").on("click" , function(e){
3530 e.preventDefault();
3531 e.stopPropagation();
3532 $(document).find('#ays-survey-templates-modal').aysModal('hide');
3533 });
3534
3535 $(document).find('.ays-survey-templates-box').on('click' , function(){
3536 var tempType = $(this).attr('data-template');
3537 if(tempType == 'blank-form'){
3538 $(document).find(".ays-survey-templates-box-apply-button-blank").trigger('click');
3539 return;
3540 }
3541 $(this).find('.ays-survey-templates-box-apply-button').trigger('click');
3542 });
3543
3544 $(document).find(".ays-survey-templates-box-apply-button").on("click" , function(e){
3545 e.preventDefault();
3546 e.stopPropagation();
3547 var $this = $(this);
3548 var $thisParent = $this.parents(".ays-modal-content-survey-templates");
3549 if(!$thisParent.hasClass('no-confirmation')){
3550 var confirm = window.confirm(SurveyMakerAdmin.confirmMessageTemplate);
3551 }
3552 else{
3553 var confirm = true;
3554 }
3555 if(confirm == true){
3556
3557
3558 var modal = $('#ays-survey-templates-modal');
3559 var otherTypes = new Array(
3560 'text',
3561 'linear_scale',
3562 'star',
3563 'short_text',
3564 'number',
3565 'phone',
3566 'name',
3567 'email',
3568 'date',
3569 'date_time',
3570 'time',
3571 );
3572 $thisParent.find(".ays_survey_preloader").show();
3573
3574 var action = 'ays_survey_add_survey_template';
3575
3576 var templateName = $this.attr('data-template');
3577
3578 $.ajax({
3579 url: ajaxurl,
3580 type: 'post',
3581 dataType: 'json',
3582 data: {
3583 action: action,
3584 template_file_name: templateName
3585 },
3586 success: function(response) {
3587 if (response.status) {
3588 var sections = response.data.sections;
3589 $(document).find('#ays-survey-title').val(response.data.title);
3590 // For Sections
3591 var newQuestion = "";
3592 var parent = $(document).find(".ays-survey-sections-conteiner");
3593 parent.html("");
3594 for(var key in sections){
3595
3596 aysSurveyAddSection( null, null, true );
3597 var lastAddedSection = parent.find(".ays-survey-new-section:last-child");
3598 lastAddedSection.find(".ays-survey-section-questions").html("");
3599 lastAddedSection.find(".ays-survey-section-title").val(sections[key].title);
3600 // For Questions
3601 for(var questionKey in sections[key].questions){
3602 var allAddedAnswers = new Array();
3603 var questionType = typeof sections[key].questions[questionKey].type != "undefined" ? sections[key].questions[questionKey].type : "";
3604 if(questionType != ""){
3605 aysSurveyAddQuestion(lastAddedSection.attr("data-id"), false, lastAddedSection , true);
3606 newQuestion = lastAddedSection.find("div.ays-survey-new-question[data-template-id='"+(Number(questionKey)+1)+"']");
3607 newQuestion.find('.ays-survey-question-type').aysDropdown('set selected', sections[key].questions[questionKey].type );
3608 newQuestion.find('.ays-survey-question-type').aysDropdown('set value', sections[key].questions[questionKey].type );
3609 newQuestion.find('.ays-survey-check-type-before-change').val( sections[key].questions[questionKey].type );
3610 newQuestion.find(".ays-survey-question-input-textarea").html(sections[key].questions[questionKey].question);
3611 newQuestion.find(".ays-survey-question-description-input-textarea").html(sections[key].questions[questionKey].description);
3612 var thisButton = newQuestion.find(".ays-survey-action-add-answer");
3613
3614 // For Answers
3615 for(var answerKey in sections[key].questions[questionKey].answers){
3616
3617 aysSurveyAddAnswer( thisButton, false, true );
3618 var newAnswer = newQuestion.find("div.ays-survey-new-answer[data-id='"+(Number(answerKey)+1)+"']");
3619 allAddedAnswers.push(newAnswer);
3620 newAnswer.find(".ays-survey-input").val(sections[key].questions[questionKey].answers[answerKey].answer);
3621
3622 }
3623
3624 if(sections[key].questions[questionKey].user_variant == 'on'){
3625 var checkbox = newQuestion.find('.ays-survey-other-answer-checkbox').attr('checked', 'checked');
3626 var oterAnswer = newQuestion.find('.ays-survey-other-answer-row');
3627 oterAnswer.removeAttr('style');
3628 newQuestion.find('.ays-survey-other-answer-add-wrap').css('display','none');
3629 }
3630
3631 newQuestion.find('.ays-survey-input-required-question').prop('checked', sections[key].questions[questionKey].options[0].required == 'on' ? true : false );
3632
3633 if(otherTypes.indexOf(questionType) == -1 && allAddedAnswers.length > 0){
3634 newQuestion.find("div.ays-survey-answers-conteiner").html(allAddedAnswers);
3635 }
3636 }
3637 }
3638 }
3639 setTimeout(function(){
3640 $thisParent.find(".ays_survey_preloader").hide();
3641 modal.aysModal('hide');
3642 } , 100);
3643
3644 }
3645 else{
3646 $thisParent.find(".ays_survey_preloader").hide();
3647 }
3648 },
3649 error: function(){
3650 $thisParent.find(".ays_survey_preloader").hide();
3651 modal.aysModal('hide');
3652 }
3653 });
3654 }
3655 });
3656 // Survey Templates end
3657
3658 // Pro features start
3659 $(document).find(".ays-pro-features-v2-upgrade-button").hover(function() {
3660 // Code to execute when the mouse enters the element
3661 var unlockedImg = "Unlocked_24_24.svg";
3662 var imgBox = $(this).find(".ays-pro-features-v2-upgrade-icon");
3663 var imgUrl = imgBox.attr("data-img-src");
3664 var newString = imgUrl.replace("Locked_24x24.svg", unlockedImg);
3665
3666 imgBox.css("background-image", 'url(' + newString + ')');
3667 imgBox.attr("data-img-src", newString);
3668 }, function() {
3669
3670 var lockedImg = "Locked_24x24.svg";
3671 var imgBox = $(this).find(".ays-pro-features-v2-upgrade-icon");
3672 var imgUrl = imgBox.attr("data-img-src");
3673 var newString = imgUrl.replace("Unlocked_24_24.svg", lockedImg);
3674
3675 imgBox.css("background-image", 'url(' + newString + ')');
3676 imgBox.attr("data-img-src", newString);
3677 });
3678
3679 $(document).find(".ays-pro-features-v2-video-button").hover(function() {
3680 // Code to execute when the mouse enters the element
3681 var unlockedImg = "Video_24x24_Hover.svg";
3682 var imgBox = $(this).find(".ays-pro-features-v2-video-icon");
3683 var imgUrl = imgBox.attr("data-img-src");
3684 var newString = imgUrl.replace("Video_24x24.svg", unlockedImg);
3685
3686 imgBox.css("background-image", 'url(' + newString + ')');
3687 imgBox.attr("data-img-src", newString);
3688 }, function() {
3689
3690 var lockedImg = "Video_24x24.svg";
3691 var imgBox = $(this).find(".ays-pro-features-v2-video-icon");
3692 var imgUrl = imgBox.attr("data-img-src");
3693 var newString = imgUrl.replace("Video_24x24_Hover.svg", lockedImg);
3694
3695 imgBox.css("background-image", 'url(' + newString + ')');
3696 imgBox.attr("data-img-src", newString);
3697 });
3698
3699 $(document).on('click', '.ays-pro-features-v2-video-button,.ays-survey-question-actions-pro-button', function(e){
3700 e.preventDefault();
3701 if($(this).hasClass('ays-survey-question-actions-pro-button')){
3702 var _thisDataParent = $(this);
3703 }
3704 else{
3705 var _thisDataParent = $(this).parents('.ays-pro-features-v2-main-box').find('.ays-pro-pro-features-popup');
3706 }
3707 var popupModal = $(document).find('#pro-features-popup-modal');
3708
3709 // Get option Data
3710 var optionTitle = _thisDataParent.attr('data-option-title');
3711 var optionDesc = _thisDataParent.attr('data-option-text');
3712 var optionVideoUrl = _thisDataParent.attr('data-video-url');
3713
3714 var popupModalTitleBox = popupModal.find('.pro-features-popup-modal-right-box-title');
3715 var popupModalTitleContent = popupModal.find('.pro-features-popup-modal-right-box-content');
3716 popupModalTitleBox.html(optionTitle);
3717 popupModalTitleContent.html(optionDesc);
3718
3719
3720 var leftSection = popupModal.find('.ays-modal-body .pro-features-popup-modal-left-section');
3721
3722 if ( typeof optionVideoUrl != "undefined" && optionVideoUrl != "") {
3723 var videoID = ays_youtube_parser(optionVideoUrl);
3724 var iframeHTML = '<iframe width="560" height="315" src="https://www.youtube.com/embed/'+ videoID +'" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen loading="lazy"></iframe>';
3725
3726 leftSection.html(iframeHTML);
3727 }
3728
3729 popupModal.aysModal('show_flex');
3730 });
3731
3732 $(document).on('click', '.ays-survey-question-actions-pro-redirect-button', function(e){
3733 e.preventDefault();
3734
3735 var href = $(this).attr("data-href");
3736 if (href) {
3737 window.open(href, '_blank');
3738 }
3739 });
3740
3741 // Pro features end
3742
3743 // Check new added Survey start
3744 var createdNewSurvey = getCookie('ays_survey_created_new');
3745 if(createdNewSurvey && createdNewSurvey > 1){
3746 var url = new URL(window.location.href);
3747
3748 // Get a specific GET parameter by name
3749 var parameterValue = url.searchParams.get("action");
3750 var htmlDefaultText = '<p style="margin-top:1rem;">For more detailed configuration visit <a href="admin.php?page=survey-maker&action=edit&id=' + createdNewSurvey + '">edit survey page</a>.</p>';
3751
3752 var getCustomPostId = getCookie('ays_survey_created_new_'+createdNewSurvey+'_post_id');
3753 var htmlCustomPostMessage = '';
3754
3755 var link = "#";
3756 if(getCustomPostId){
3757 link = getCustomPostId;
3758 }
3759 var htmlContent = parameterValue && parameterValue == 'edit' ? '' : htmlDefaultText;
3760 htmlContent += htmlCustomPostMessage;
3761
3762 var previewButtonSvgIcon = '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">'+
3763 '<path d="M11.9999 7.21325C11.8231 7.21325 11.6535 7.28349 11.5285 7.40851C11.4035 7.53354 11.3333 7.70311 11.3333 7.87992V12.6666C11.3333 12.8434 11.263 13.013 11.138 13.138C11.013 13.263 10.8434 13.3333 10.6666 13.3333H3.33325C3.15644 13.3333 2.98687 13.263 2.86185 13.138C2.73682 13.013 2.66659 12.8434 2.66659 12.6666V5.33325C2.66659 5.15644 2.73682 4.98687 2.86185 4.86185C2.98687 4.73682 3.15644 4.66658 3.33325 4.66658H8.11992C8.29673 4.66658 8.4663 4.59635 8.59132 4.47132C8.71635 4.3463 8.78658 4.17673 8.78658 3.99992C8.78658 3.82311 8.71635 3.65354 8.59132 3.52851C8.4663 3.40349 8.29673 3.33325 8.11992 3.33325H3.33325C2.80282 3.33325 2.29411 3.54397 1.91904 3.91904C1.54397 4.29411 1.33325 4.80282 1.33325 5.33325V12.6666C1.33325 13.197 1.54397 13.7057 1.91904 14.0808C2.29411 14.4559 2.80282 14.6666 3.33325 14.6666H10.6666C11.197 14.6666 11.7057 14.4559 12.0808 14.0808C12.4559 13.7057 12.6666 13.197 12.6666 12.6666V7.87992C12.6666 7.70311 12.5963 7.53354 12.4713 7.40851C12.3463 7.28349 12.1767 7.21325 11.9999 7.21325ZM14.6133 1.74659C14.5456 1.58369 14.4162 1.45424 14.2533 1.38659C14.1731 1.35242 14.087 1.33431 13.9999 1.33325H9.99992C9.82311 1.33325 9.65354 1.40349 9.52851 1.52851C9.40349 1.65354 9.33325 1.82311 9.33325 1.99992C9.33325 2.17673 9.40349 2.3463 9.52851 2.47132C9.65354 2.59635 9.82311 2.66659 9.99992 2.66659H12.3933L5.52659 9.52658C5.4641 9.58856 5.4145 9.66229 5.38066 9.74353C5.34681 9.82477 5.32939 9.91191 5.32939 9.99992C5.32939 10.0879 5.34681 10.1751 5.38066 10.2563C5.4145 10.3375 5.4641 10.4113 5.52659 10.4733C5.58856 10.5357 5.66229 10.5853 5.74353 10.6192C5.82477 10.653 5.91191 10.6705 5.99992 10.6705C6.08793 10.6705 6.17506 10.653 6.2563 10.6192C6.33754 10.5853 6.41128 10.5357 6.47325 10.4733L13.3333 3.60659V5.99992C13.3333 6.17673 13.4035 6.3463 13.5285 6.47132C13.6535 6.59635 13.8231 6.66658 13.9999 6.66658C14.1767 6.66658 14.3463 6.59635 14.4713 6.47132C14.5963 6.3463 14.6666 6.17673 14.6666 5.99992V1.99992C14.6655 1.9128 14.6474 1.82673 14.6133 1.74659Z" fill="#007DCB"/>'+
3764 '</svg>';
3765
3766 swal({
3767 title: '<strong>Great job</strong>',
3768 type: 'success',
3769 html: '<p class="ays-survey-maker-swal2-created-row">Your Survey is Created!.</p><p>Copy the generated shortcode and paste it into any post or page to display Survey.</p><input type="text" id="ays-survey-create-new" onClick="this.setSelectionRange(0, this.value.length)" readonly value="[ays_survey id=\'' + createdNewSurvey + '\']" />' + htmlContent,
3770 showCancelButton: true,
3771 showCloseButton: true,
3772 focusConfirm: false,
3773 cancelButtonClass: "ays-survey-preview-popup-cancel-button",
3774 confirmButtonText: '<i class="ays_fa ays_fa_thumbs_up"></i> Done',
3775 cancelButtonText: '<a href="'+ link +'" target="_blank">'+ SurveyMakerAdmin.preivewSurvey + ' ' + previewButtonSvgIcon +'</a>',
3776 confirmButtonAriaLabel: 'Thumbs up, great!',
3777 });
3778 deleteCookie('ays_survey_created_new');
3779 deleteCookie('ays_survey_created_new_'+createdNewSurvey+'_post_id');
3780 }
3781 // Check new added Survey end
3782
3783 $(document).find('input[type="submit"]#doaction, input[type="submit"]#doaction2').on('click', function(e) {
3784 showConfirmationIfDelete(e);
3785 });
3786
3787 $(document).on('mouseover', '.ays-dashicons', function(){
3788 var allRateStars = $(document).find('.ays-dashicons');
3789 var index = allRateStars.index(this);
3790 allRateStars.removeClass('ays-dashicons-star-filled').addClass('ays-dashicons-star-empty');
3791 for (var i = 0; i <= index; i++) {
3792 allRateStars.eq(i).removeClass('ays-dashicons-star-empty').addClass('ays-dashicons-star-filled');
3793 }
3794 });
3795
3796 $(document).on('mouseleave', '.ays-rated-link', function(){
3797 $(document).find('.ays-dashicons').removeClass('ays-dashicons-star-filled').addClass('ays-dashicons-star-empty');
3798 });
3799
3800 $(document).on('click', '.ays-survey-collapse-options', function(){
3801 var $this = $(this);
3802 var $thisRotateButton = $(this).find('.ays-survey-collapse-options-button');
3803 var $collapsibleOptions = $this.siblings('.ays-survey-collapsible-options');
3804 var newRotation = 0;
3805
3806 $collapsibleOptions.toggle();
3807
3808 var currentRotation = $thisRotateButton.data('rotation') || 0;
3809
3810 if(currentRotation === 0){
3811 newRotation = -90;
3812 $thisRotateButton.css('color' , '#c4c4c4')
3813 }
3814 else{
3815 newRotation = 0;
3816 $thisRotateButton.css('color' , '#008cff')
3817 }
3818
3819 $thisRotateButton.css('transform', `rotate(${newRotation}deg)`).data('rotation', newRotation);
3820 });
3821
3822 $(document).on('click', '.ays-survey-collapse-all-options', function(){
3823 var $thisMainParent = $(this).parents('.ays-survey-tab-content');
3824 var $thisRotateButtons = $thisMainParent.find('.ays-survey-collapse-options-button');
3825 var $collapsibleAllOptions = $thisMainParent.find('.ays-survey-collapsible-options');
3826 $collapsibleAllOptions.hide();
3827 $thisRotateButtons.css('color' , '#c4c4c4');
3828 $thisRotateButtons.css('transform', `rotate(-90deg)`).data('rotation', -90);
3829 });
3830
3831 $(document).on('click', '.ays-survey-expand-all-options', function(){
3832 var $thisMainParent = $(this).parents('.ays-survey-tab-content');
3833 var $thisRotateButtons = $thisMainParent.find('.ays-survey-collapse-options-button');
3834 var $collapsibleAllOptions = $thisMainParent.find('.ays-survey-collapsible-options');
3835 $collapsibleAllOptions.show();
3836 $thisRotateButtons.css('color' , '#008cff');
3837 $thisRotateButtons.css('transform', `rotate(0deg)`).data('rotation', 0);
3838 });
3839
3840 // Replace image to YouTube embed video
3841 $(document).on('click', '.ays-survey-youtube-placeholder', function() {
3842 var videoId = $(this).data('video-id');
3843 var iframe = $('<iframe>', {
3844 src: 'https://www.youtube.com/embed/' + videoId + '?autoplay=1',
3845 class: '',
3846 width: 560,
3847 height: 315,
3848 frameborder: 0,
3849 allow: 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture',
3850 allowfullscreen: true,
3851 });
3852 $(this).replaceWith(iframe);
3853 });
3854
3855 $(document).on('click', 'body', function(e){
3856 if($(e.target).hasClass('ays-modal')){
3857 $(e.target).find(".ays-close").trigger("click");
3858 $(e.target).find(".ays-close-editor-popup").trigger("click");
3859 }
3860 });
3861
3862 $(document).on("click", '#ays-survey-add-question-filter', function (e) {
3863 var filterBox = $(document).find('.ays-survey-add-question-filter-option-box');
3864
3865 if( filterBox.hasClass('display_none') ){
3866 filterBox.show(250);
3867 filterBox.removeClass('display_none');
3868 } else {
3869 filterBox.hide(250);
3870 filterBox.addClass('display_none');
3871 }
3872 });
3873
3874 $(document).on('click', '.ays-survey-save-publish-link', function(e){
3875 e.preventDefault();
3876 var saveButton = $(document).find('#ays-button-apply-top.button, #ays-button-apply.button').first();
3877
3878 if (saveButton.length) {
3879 saveButton.trigger('click');
3880 }
3881 });
3882
3883 $(document).on('click', '.ays-survey-copy-shortcode-btn', function(e){
3884 e.preventDefault();
3885 var $this = $(this);
3886 var shortcode = $this.attr('data-shortcode');
3887 var tooltip = $this.parents('.ays-survey-copy-wrapper').find('.ays-survey-copy-tooltip');
3888
3889 if (!shortcode) {
3890 return;
3891 }
3892
3893 if (navigator.clipboard && window.isSecureContext) {
3894 navigator.clipboard.writeText(shortcode);
3895 } else {
3896 var textField = document.createElement('textarea');
3897 textField.value = shortcode;
3898 document.body.appendChild(textField);
3899 textField.select();
3900 document.execCommand('copy');
3901 textField.remove();
3902 }
3903
3904 tooltip.addClass('ays-survey-show');
3905 setTimeout(function(){
3906 tooltip.removeClass('ays-survey-show');
3907 }, 1200);
3908 });
3909
3910 function showConfirmationIfDelete(e) {
3911 var $el = $(e.target);
3912 var elParent = $el.parent();
3913 var actionSelect = elParent.find('select[name="action"]');
3914 var action = actionSelect.val();
3915
3916 if (action === 'bulk-delete') {
3917 e.preventDefault();
3918 var confirmDelete = confirm(SurveyMakerAdmin.deleteElementFromListTable);
3919
3920 if (confirmDelete) {
3921 var form = $el.closest('form');
3922 form.submit();
3923 }
3924 }
3925 }
3926
3927 function getCookie(cname) {
3928 let name = cname + "=";
3929 let decodedCookie = decodeURIComponent(document.cookie);
3930 let ca = decodedCookie.split(';');
3931 for(let i = 0; i <ca.length; i++) {
3932 let c = ca[i];
3933 while (c.charAt(0) == ' ') {
3934 c = c.substring(1);
3935 }
3936 if (c.indexOf(name) == 0) {
3937 return c.substring(name.length, c.length);
3938 }
3939 }
3940 return "";
3941 }
3942
3943 function ays_youtube_parser(url){
3944 var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/;
3945 var match = url.match(regExp);
3946 return (match&&match[7].length==11)? match[7] : false;
3947 }
3948
3949
3950 function deleteCookie(name) {
3951 document.cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
3952 }
3953
3954 });
3955
3956 })( jQuery );
3957
3958 document.addEventListener("DOMContentLoaded", function() {
3959 var startDate = new Date("2025-09-21");
3960 var endDate = new Date("2025-10-21");
3961 var totalLicenses = 50;
3962 var progressionPattern = new Array(3, 2, 1, 4, 2, 3, 1, 2, 4, 3, 2, 1, 3, 2, 4, 1, 3, 2, 2, 3, 1, 2);
3963 function getCurrentProgress() {
3964 var today = new Date();
3965 // today.setDate(today.getDate() + 1);
3966 var daysPassed = Math.floor((today - startDate) / (1000 * 60 * 60 * 24));
3967 var usedLicenses = 0;
3968 for (var i = 0; i < Math.min(daysPassed, progressionPattern.length); i++) {
3969 usedLicenses += progressionPattern[i];
3970 }
3971 return Math.min(usedLicenses, totalLicenses);
3972 }
3973 function updateProgress() {
3974 var usedLicenses = getCurrentProgress();
3975 var remainingLicenses = totalLicenses - usedLicenses;
3976 var progressPercentage = (usedLicenses / totalLicenses) * 100;
3977 var remainingElement = document.getElementById("remaining-licenses");
3978 var progressElement = document.getElementById("progress-fill");
3979 if (remainingElement) remainingElement.textContent = remainingLicenses;
3980 if (progressElement) progressElement.style.width = progressPercentage + "%";
3981 }
3982 updateProgress();
3983 });
3984
3985 // Copy to clipboard function
3986 function surveyCopyToClipboard(text) {
3987 if (navigator.clipboard && window.isSecureContext) {
3988 navigator.clipboard.writeText(text).then(function() {
3989 surveyShowCopyNotification(SurveyMakerAdmin.successCopyCoupon);
3990 }).catch(function() {
3991 fallbackCopyTextToClipboard(text);
3992 });
3993 } else {
3994 fallbackCopyTextToClipboard(text);
3995 }
3996 }
3997
3998 function fallbackCopyTextToClipboard(text) {
3999 var textArea = document.createElement("textarea");
4000 textArea.value = text;
4001 textArea.style.position = "fixed";
4002 textArea.style.top = "-9999px";
4003 textArea.style.left = "-9999px";
4004 document.body.appendChild(textArea);
4005 textArea.focus();
4006 textArea.select();
4007 try {
4008 var successful = document.execCommand("copy");
4009 if (successful) {
4010 surveyShowCopyNotification(SurveyMakerAdmin.successCopyCoupon);
4011 } else {
4012 surveyShowCopyNotification(SurveyMakerAdmin.failedCopyCoupon);
4013 }
4014 } catch (err) {
4015 surveyShowCopyNotification(SurveyMakerAdmin.failedCopyCoupon);
4016 }
4017 document.body.removeChild(textArea);
4018 }
4019
4020 function surveyShowCopyNotification(message) {
4021 var notification = document.createElement("div");
4022 notification.className = "ays-survey-copy-notification show";
4023 console.log(notification);
4024 notification.textContent = message;
4025 document.body.appendChild(notification);
4026 setTimeout(function() {
4027 notification.classList.remove("show");
4028 setTimeout(function() {
4029 document.body.removeChild(notification);
4030 }, 300);
4031 }, 2000);
4032 }