const root = $('#editor-root') Sortable.create(root.get(0), {handle: '.move-handle', onEnd: function(evt) {renumber_blocks()}}) var element_index = 0 var question_index = 0 root.on('click', '.panel-controls > a', function(event) { event.preventDefault() event.stopPropagation() var action = $(this).data('action') var element = $(this).closest('.accordion-item') var root_container = $(this).closest('.accordion') if (action == 'delete') { element.remove() console.log(root_container.get(0) == root.get(0)) if (root_container.get(0) != root.get(0) && root_container.children().length < 2 ) { root_container.find('.panel-controls > a[data-action="delete"]').addClass('disabled') } } else if (action == 'add-question') { var question = generate_single_question(root_container_id=`#${root_container.attr('id')}`) $(question).insertBefore(element) if (root_container.get(0) != root.get(0) && root_container.children().length > 1 ) { root_container.find('.panel-controls > a[data-action="delete"]').removeClass('disabled') } } else if (action == 'add-block') { var block = generate_block(root_container_id=`#${root_container.attr('id')}`) $(block).insertBefore(element) } renumber_blocks() }) root.on('change', '.form-select.question-type', function(event) { event.preventDefault() var type = $(this).val() var options = $(this).closest('div.input-group').siblings('.options') var option_controls = $(this).closest('div.input-group').siblings('.option-controls') var correct = $(this).closest('div.input-group').siblings().find('.question-correct') if (type == 'Yes/No') { options.empty() correct.empty() var opt = `