HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/keystud.komma-mediadesign.nl/wwwroot/kms/public/js/tinymce.js
var isFocused = false;

$(document).ready(function(){
    /*
     * Tiny MCE
     */
    $('textarea.tiny_mce').tinymce({
        // general options
        entity_encoding : "raw",
        mode : 	"textareas",
        theme : "motheme",
        skin : 	"mikeontwerpt",
        width : "380",
        height : "370",
        plugins : "inlinepopups,tabfocus,paste",

        // Theme options
        theme_motheme_buttons1 : "bold,italic,underline,|,bullist,numlist,|,link,unlink,|,formatselect",
        theme_motheme_buttons2 : "",
        theme_motheme_buttons3 : "",
        theme_motheme_buttons4 : "",
        theme_motheme_blockformats : "h2,blockquote",

        theme_motheme_toolbar_location : "top",
        theme_motheme_toolbar_align : "left",
        theme_motheme_statusbar_location : "bottom",
        theme_motheme_resizing : false,

        setup: function(ed){
            ed.onInit.add(function(ed){
                // Get value from editor
                var val = ed.getContent();
                val = val.replace(/(<([^>]+)>)/ig,"");

                // Get data-label attr
                var id = ed.id;
                var label = $('#'+id).attr('data-label');

                // Functions
                tinyMceInitReset(ed,label);
                $(ed.getDoc()).contents().find('body').focus(function(){tinyMceFocus(ed, label);});
                $(ed.getDoc()).contents().find('body').blur(function(){tinyMceBlur(ed, label);});
            });
        }
    });

    /*
     * Insert shortCode in tiny mce
     */
    $('.insert_image_link').click(function(){ insertShortCode(this,'image'); });
    $('.insert_video_link').click(function(){ insertShortCode(this,'video'); });

});

function tinyMceInitReset(ed,label)
{
    // Get new value from editor
    var val = ed.getContent();
    val = val.replace(/(<([^>]+)>)/ig,"");

    if(val != label)
    {
        var body = ed.getBody();
        $(body).addClass("active");
    }
}

function tinyMceFocus(ed,label)
{
    var body = ed.getBody();
    $(body).addClass("active");

    isFocused = ed;
    var val = ed.getContent();
    val = val.replace(/(<([^>]+)>)/ig,"");

    if(val == label)
    {
        ed.setContent('');
    }

}
function tinyMceBlur(ed,label)
{
    // Get new value from editor
    var val = ed.getContent();
    val = val.replace(/(<([^>]+)>)/ig,"");
    if(val == '')
    {
        ed.setContent(label);

        var body = ed.getBody();
        $(body).removeClass("active");
    }
}

function insertShortCode(obj,pre)
{
    if(isFocused)
    {
        var sc = $(obj).attr('data-sc');
        console.log(sc);
        var insert = '['+pre+'_'+sc+']';
        isFocused.execCommand('mceInsertContent', false, insert);
    }
}