Prechádzať zdrojové kódy

Editor/UI: Scripts can now be removed.

Mr.doob 10 rokov pred
rodič
commit
bf6c250523
2 zmenil súbory, kde vykonal 28 pridanie a 0 odobranie
  1. 22 0
      editor/js/libs/ui.editor.js
  2. 6 0
      editor/js/libs/ui.js

+ 22 - 0
editor/js/libs/ui.editor.js

@@ -13,11 +13,33 @@ UI.ScriptEditor = function () {
 	var event = new UI.Text( '' );
 	this.add( event );
 
+	var remove = new UI.Text( 'x' );
+	remove.setPosition( 'absolute' );
+	remove.setRight( '8px' );
+	remove.setCursor( 'pointer' );
+	remove.onClick( function () {
+
+		if ( confirm( 'Are you sure?' ) ) {
+
+			scope.parent.remove( scope );
+
+			if ( scope.onChangeCallback !== undefined ) {
+
+				scope.onChangeCallback();
+
+			}
+
+		}
+
+	} );
+	this.add( remove );
+
 	this.add( new UI.Break() );
 
 	var textarea = new UI.TextArea();
 	textarea.setWidth( '100%' );
 	textarea.setHeight( '100px' );
+	textarea.setMarginTop( '8px' );
 	textarea.onKeyUp( function () {
 
 		clearTimeout( timeout );

+ 6 - 0
editor/js/libs/ui.js

@@ -100,6 +100,8 @@ UI.Panel = function () {
 	dom.className = 'Panel';
 
 	this.dom = dom;
+
+	this.parent = null;
 	this.children = [];
 
 	return this;
@@ -119,6 +121,8 @@ UI.Panel.prototype.add = function () {
 			this.dom.appendChild( argument.dom );
 			this.children.push( argument );
 
+			argument.parent = this;
+
 		} else {
 
 			console.error( 'UI.Panel:', argument, 'is not an instance of UI.Element.' )
@@ -150,6 +154,8 @@ UI.Panel.prototype.remove = function () {
 
 			}
 
+			argument.parent = null;
+
 		} else {
 
 			console.error( 'UI.Panel:', argument, 'is not an instance of UI.Element.' )