Free and Open source Web Builder Framework. Next generation tool for building templates without coding
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

56 lines
1.2 KiB

define(['backbone',
'codemirror/lib/codemirror',
'codemirror/mode/htmlmixed/htmlmixed',
'codemirror/mode/css/css',
'formatting'
],
function(Backbone, CodeMirror, htmlMode, cssMode, formatting) {
/**
* @class CodeViewer
* */
return Backbone.Model.extend({
defaults: {
input : '',
label : '',
codeName : '',
theme : '',
readOnly : true,
lineNumbers : true,
},
/** @inheritdoc */
getId : function()
{
return 'CodeMirror';
},
/** @inheritdoc */
init: function(el)
{
this.editor = CodeMirror.fromTextArea(el, {
dragDrop : false,
lineNumbers : this.get('lineNumbers'),
readOnly : this.get('readOnly'),
mode : this.get('codeName'),
theme : this.get('theme'),
});
return this;
},
/** @inheritdoc */
setContent : function(v)
{
if(!this.editor)
return;
this.editor.setValue(v);
if(this.editor.autoFormatRange){
CodeMirror.commands.selectAll(this.editor);
this.editor.autoFormatRange(this.editor.getCursor(true), this.editor.getCursor(false) );
CodeMirror.commands.goDocStart(this.editor);
}
},
});
});