$(document).ready(function() {
    $('.data-markers a').on('click', insertExpression);
    $('.js-thankyou-type').change(togglePageType);
    $('.js-display-conditions').change(toggleDisplayConditions);
});


function togglePageType() {
    $('.js-content-container').toggleClass('d-none');
}

function toggleDisplayConditions() {
    var setState = $(this).val() == 0;
    $('#pageOptions').toggleClass('d-none', setState);
}

function insertExpression(){
    var expr = $(this),
        typeLink = expr.data('type') === 'link',
        text = expr.data('marker');

    if(typeLink) {
        var link = ('<a href="TEXT">TEXT</a>').replace(/TEXT/g, text);
        CKEDITOR.instances['html_content'].insertHtml(link);
    } else {
        CKEDITOR.instances['html_content'].insertText(text);
    }
    return false;
}
