codemirror = {}

codemirror.create = function( name ){

  if ( !document.getElementById(name) ){
    alert('empty name "'+name+'": '+$(name).size())
    return false;
  }
  
 
  var editor = CodeMirror.fromTextArea( document.getElementById(name), {
    mode: "text/html",
    matchBrackets: true,
    tabMode: "indent",
      //  добавляем функцию раскрытия на весь экран по нажатию клавищи esc
    onKeyEvent: function(i, e) {
          // Hook into F11
          if ((e.keyCode == 122 || e.keyCode == 27) && e.type == 'keydown') {
            e.stop();
            return toggleFullscreenEditing();
          }
    },
    lineNumbers: true,
  });



  $(".CodeMirror").css('width', $('#'+name).css('width'))
  return editor;
} //  end create

codemirror.remove = function( element ){
   editor_id = element.attr('link_editor');
  HL.editor.get(editor_id).toTextArea();
  
}

codemirror.getText = function(  ){
 alert('codemirror')
}


  //  регистрируем
HL.editor.register('codemirror',codemirror);


 function toggleFullscreenEditing(){
        var editorDiv = $('.CodeMirror-scroll');
        if (!editorDiv.hasClass('fullscreen')) {
            toggleFullscreenEditing.beforeFullscreen = { height: editorDiv.height(), width: editorDiv.width() }
            editorDiv.addClass('fullscreen');
            editorDiv.height('100%');
            editorDiv.width('100%');
            editor.refresh();
        }
        else {
            editorDiv.removeClass('fullscreen');
            editorDiv.height(toggleFullscreenEditing.beforeFullscreen.height);
            editorDiv.width(toggleFullscreenEditing.beforeFullscreen.width);
            editor.refresh();
        }
    }