Edit in JSFiddle

requirejs.config({ 
		paths: {
			'ace':'/cs/' + getSiteName() + '/ace-master/lib/ace'
		}
    
});

require(['jquery', 'ace/ace', 'jqueryui'], function (JetCSKJQ, ace) {

	var jqACE = JetCSKJQ;

	//% Check if TextArea exists;
	if ( jqACE("textarea[id='PTBR_MGOBJ_WRK_PTBR_HTMLAREA1'").length) {

		//% Inject Bootstrap CSS;
		cskLoadCSS(getCSSUrl('CSK_BOOTSTRAP_V_3_0_0_CSS'));
		cskLoadCSS(getCSSUrl('PSJQUERY_BASE_1_8_17'));

		//% Get the delivered TextArea (PTBR_MGOBJ_WRK.HTMLAREA1);
        var textarea = jqACE("#PTBR_MGOBJ_WRK_PTBR_HTMLAREA1");

		//% Create ACE Editor DIV;
        var editDiv = jqACE('<div>', {
            position: 'absolute',
            width: textarea.width(),
            height: textarea.height(),
			id: 'cskACEEditor'
        }).insertBefore(textarea);

		//% Hide the delivered TextArea (PTBR_MGOBJ_WRK.HTMLAREA1);
        textarea.css('display', 'none');

		//% ACE Editor Configuration;
        var editor = ace.edit(editDiv[0]);

		//% Use a Theme of choice (optional);
		//% editor.setTheme("ace/theme/monokai");

		//% Set Mode (JS/HTML/CSS);
	    editor.getSession().setMode("ace/mode/javascript");
		if (jqACE("span:contains('Edit HTML')").length > 0) {
	        editor.getSession().setMode("ace/mode/html");
		} 
		if (jqACE("span:contains('Edit Style Sheet')").length > 0) {
			editor.getSession().setMode("ace/mode/css");
		}

		//% Set Editor to existing TextArea value;
        editor.getSession().setValue(textarea.val());

		//% React to Resizing;
		jqACE("#cskACEEditor").resizable({
      		resize: function( event, ui ) {
        		editor.resize();
      		}
		});

		//% copy back to textarea on change;
		editor.getSession().on('change', function(){
						eval("addchg_" + cskGetFormName() + "(textarea[0])");
						textarea.val(editor.getSession().getValue());
			});
	}

});