| 1 |
(function ($) { |
| 2 |
$(document).ready(function () { |
| 3 |
|
| 4 |
$(document).find('#ays_create_quick_poll').on('click', function () { |
| 5 |
$('#ays-poll-quick-create').aysModal('show'); |
| 6 |
}); |
| 7 |
|
| 8 |
$(document).find('.ays-close-quick-create').on('click', hideModalContainer); |
| 9 |
$(document).find('#ays-poll-quick-create').on('click', hideModalContainer); |
| 10 |
|
| 11 |
$(document).find('#ays-poll-quick-create-content').on('click', function (e) { |
| 12 |
e.stopPropagation(); |
| 13 |
}); |
| 14 |
|
| 15 |
$(document).keydown(function (e) { |
| 16 |
// ESCAPE key pressed |
| 17 |
if ($('.ays_poll_modal').css('display') != 'none' && e.keyCode == 27) { |
| 18 |
hideModalContainer(); |
| 19 |
} |
| 20 |
}); |
| 21 |
|
| 22 |
$(document).find('.quick_poll_answer_remove').on('click', function () { |
| 23 |
var answerBoxesArr = $(document).find('.quick_poll_answer_box'); |
| 24 |
var answerBoxesAmount = answerBoxesArr.length; |
| 25 |
|
| 26 |
if (answerBoxesAmount > 2) { |
| 27 |
$(this).parent().remove(); |
| 28 |
} else { |
| 29 |
swal.fire({ |
| 30 |
type: 'info', |
| 31 |
html: '<h2>Sorry minimum count of answers should be 2</h2>' |
| 32 |
}); |
| 33 |
} |
| 34 |
}) |
| 35 |
|
| 36 |
$(document).find('.quick_poll_add_option').on('click', function () { |
| 37 |
var answerBoxesArr = $(document).find('.quick_poll_answer_box'); |
| 38 |
var lastAnswerBox = answerBoxesArr.eq(answerBoxesArr.length - 1); |
| 39 |
var lastInputID = lastAnswerBox.children('input').attr('data-id'); |
| 40 |
|
| 41 |
var clonedElement = lastAnswerBox.clone(true); |
| 42 |
var clonedInputID = Number(lastInputID) + 1; |
| 43 |
clonedElement.children('input').attr('data-id', clonedInputID); |
| 44 |
clonedElement.children('input').val(''); |
| 45 |
|
| 46 |
clonedElement.insertBefore($(this)); |
| 47 |
}) |
| 48 |
|
| 49 |
$(document).find('#allow_multivote_switch').on('change', function () { |
| 50 |
var multivoteSettingsDiv = $(document).find('.quick_poll_multivote_settings'); |
| 51 |
var multivoteSettingsInputArr = multivoteSettingsDiv.children(); |
| 52 |
|
| 53 |
if ($(this).is(':checked')) { |
| 54 |
multivoteSettingsDiv.css('visibility', 'visible'); |
| 55 |
multivoteSettingsInputArr.css('visibility', 'visible'); |
| 56 |
} else { |
| 57 |
multivoteSettingsInputArr.css('visibility', 'visible'); |
| 58 |
multivoteSettingsInputArr.css('visibility', 'hidden'); |
| 59 |
multivoteSettingsDiv.children().eq(0).val(''); |
| 60 |
multivoteSettingsDiv.children().eq(1).val(''); |
| 61 |
} |
| 62 |
}) |
| 63 |
|
| 64 |
function hideModalContainer() { |
| 65 |
$(document).find('.ays_poll_modal').aysModal('hide'); |
| 66 |
} |
| 67 |
|
| 68 |
}); |
| 69 |
})(jQuery); |
| 70 |
|