ui.editor.js 1.3 KB

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