Bläddra i källkod

Editor: Refactored edit button code once again.

Mr.doob 7 år sedan
förälder
incheckning
c04e8d1a71
4 ändrade filer med 34 tillägg och 25 borttagningar
  1. 2 0
      editor/js/Config.js
  2. 17 0
      editor/js/Menubar.File.js
  3. 14 1
      editor/js/Sidebar.Project.js
  4. 1 24
      editor/js/libs/app/index.html

+ 2 - 0
editor/js/Config.js

@@ -13,6 +13,8 @@ var Config = function ( name ) {
 		'project/renderer/gammaInput': false,
 		'project/renderer/gammaOutput': false,
 		'project/renderer/shadows': true,
+
+		'project/editable': false,
 		'project/vr': false,
 
 		'settings/history': false

+ 17 - 0
editor/js/Menubar.File.js

@@ -285,6 +285,23 @@ Menubar.File = function ( editor ) {
 
 			content = content.replace( '<!-- includes -->', includes.join( '\n\t\t' ) );
 
+			var editButton = '';
+
+			if ( editor.config.getKey( 'project/editable' ) ) {
+
+				editButton = `
+			var button = document.createElement( 'a' );
+			button.href = 'https://threejs.org/editor/#file=' + location.href.split( '/' ).slice( 0, - 1 ).join( '/' ) + '/app.json';
+			button.style.cssText = 'position: absolute; bottom: 20px; right: 20px; padding: 7px 10px 6px 10px; color: #fff; border: 1px solid #fff; text-decoration: none;';
+			button.target = '_blank';
+			button.textContent = 'EDIT';
+			document.body.appendChild( button );
+				`;
+
+			}
+
+			content = content.replace( '/* edit button */', editButton );
+
 			zip.file( 'index.html', content );
 
 		} );

+ 14 - 1
editor/js/Sidebar.Project.js

@@ -101,13 +101,26 @@ Sidebar.Project = function ( editor ) {
 
 	container.add( rendererPropertiesRow );
 
+	// Editable
+
+	var editableRow = new UI.Row();
+	var editable = new UI.Checkbox( config.getKey( 'project/editable' ) ).setLeft( '100px' ).onChange( function () {
+
+		config.setKey( 'project/editable', this.getValue() );
+
+	} );
+
+	editableRow.add( new UI.Text( 'Editable' ).setWidth( '90px' ) );
+	editableRow.add( editable );
+
+	container.add( editableRow );
+
 	// VR
 
 	var vrRow = new UI.Row();
 	var vr = new UI.Checkbox( config.getKey( 'project/vr' ) ).setLeft( '100px' ).onChange( function () {
 
 		config.setKey( 'project/vr', this.getValue() );
-		// updateRenderer();
 
 	} );
 

+ 1 - 24
editor/js/libs/app/index.html

@@ -13,19 +13,6 @@
 				margin: 0px;
 				overflow: hidden;
 			}
-			#edit {
-				position: absolute;
-				bottom: 20px;
-				right: 20px;
-				padding: 8px;
-				text-decoration: none;
-				background-color: #fff;
-				color: #555;
-				opacity: 0.5;
-			}
-			#edit:hover {
-				opacity: 1;
-			}
 		</style>
 	</head>
 	<body ontouchstart="">
@@ -47,18 +34,8 @@
 				window.addEventListener( 'resize', function () {
 					player.setSize( window.innerWidth, window.innerHeight );
 				} );
-
-				if ( location.search === '?edit' ) {
-					var button = document.createElement( 'a' );
-					button.id = 'edit';
-					button.href = 'https://threejs.org/editor/#file=' + location.href.split( '/' ).slice( 0, - 1 ).join( '/' ) + '/app.json';
-					button.target = '_blank';
-					button.textContent = 'EDIT';
-					document.body.appendChild( button );
-				}
-
 			} );
-
+			/* edit button */
 		</script>
 	</body>
 </html>