ui.editor.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // CodeEditor
  2. UI.CodeEditor = function ( mode ) {
  3. UI.Element.call( this );
  4. var scope = this;
  5. var dom = document.createElement( 'div' );
  6. dom.className = 'CodeEditor';
  7. var editor = CodeMirror( dom, { mode: mode, indentWithTabs: true, lineWrapping: true, matchBrackets: true } );
  8. editor.onKeyUp( 'keyup', function () {
  9. if ( scope.onKeyUpCallback !== undefined ) {
  10. scope.onKeyUpCallback();
  11. }
  12. });
  13. this.dom = dom;
  14. this.editor = editor;
  15. return this;
  16. };
  17. UI.CodeEditor.prototype = Object.create( UI.Element.prototype );
  18. UI.CodeEditor.prototype.setWidth = function ( value ) {
  19. UI.Element.prototype.setWidth.call( this, value );
  20. this.editor.setSize( this.dom.style.width, this.dom.style.height );
  21. return this;
  22. };
  23. UI.CodeEditor.prototype.setHeight = function ( value ) {
  24. UI.Element.prototype.setHeight.call( this, value );
  25. this.editor.setSize( this.dom.style.width, this.dom.style.height );
  26. return this;
  27. };
  28. UI.CodeEditor.prototype.getValue = function () {
  29. return this.editor.getValue();
  30. };
  31. UI.CodeEditor.prototype.setValue = function ( value ) {
  32. this.editor.setValue( value );
  33. return this;
  34. };
  35. UI.CodeEditor.prototype.onKeyUp = function ( callback ) {
  36. this.onKeyUpCallback = callback;
  37. return this;
  38. };