ui.editor.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.constructor = UI.CodeEditor;
  21. UI.CodeEditor.prototype.setWidth = function ( value ) {
  22. UI.Element.prototype.setWidth.call( this, value );
  23. this.editor.setSize( this.dom.style.width, this.dom.style.height );
  24. return this;
  25. };
  26. UI.CodeEditor.prototype.setHeight = function ( value ) {
  27. UI.Element.prototype.setHeight.call( this, value );
  28. this.editor.setSize( this.dom.style.width, this.dom.style.height );
  29. return this;
  30. };
  31. UI.CodeEditor.prototype.getValue = function () {
  32. return this.editor.getValue();
  33. };
  34. UI.CodeEditor.prototype.setValue = function ( value ) {
  35. this.editor.setValue( value );
  36. return this;
  37. };
  38. UI.CodeEditor.prototype.onKeyUp = function ( callback ) {
  39. this.onKeyUpCallback = callback;
  40. return this;
  41. };