mirror of
https://github.com/dataarts/dat.gui.git
synced 2024-12-12 04:08:27 +00:00
automated style formatting on save of all js files and updated gulp build
This commit is contained in:
parent
1f05d74eb2
commit
4f0222f812
@ -1,4 +1,4 @@
|
||||
[*.js]
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
|
44
.jscsrc
44
.jscsrc
@ -1,44 +0,0 @@
|
||||
{
|
||||
|
||||
"fileExtensions": [".js", ".json"],
|
||||
"excludeFiles": ["node_modules/**", "build/**"],
|
||||
|
||||
"maximumLineLength": 120,
|
||||
"validateLineBreaks": "LF",
|
||||
"validateIndentation": 4,
|
||||
|
||||
"requireSpaceAfterKeywords": [
|
||||
"if",
|
||||
"else",
|
||||
"for",
|
||||
"while",
|
||||
"do",
|
||||
"switch",
|
||||
"return",
|
||||
"try",
|
||||
"catch"
|
||||
],
|
||||
|
||||
"requireSpaceBeforeBlockStatements": true,
|
||||
|
||||
"requireSpacesInConditionalExpression": {
|
||||
"afterTest": true,
|
||||
"beforeConsequent": true,
|
||||
"afterConsequent": true,
|
||||
"beforeAlternate": true
|
||||
},
|
||||
|
||||
"requireSpacesInsideParentheses": "all",
|
||||
"requireSpacesInsideObjectBrackets": "all",
|
||||
"requireSpacesInsideArrayBrackets": "all",
|
||||
|
||||
"requireParenthesesAroundIIFE": true,
|
||||
|
||||
"disallowSpacesInFunctionExpression": {
|
||||
"beforeOpeningRoundBrace": true
|
||||
},
|
||||
|
||||
"disallowKeywords": ["with"],
|
||||
"disallowImplicitTypeConversion": ["string"]
|
||||
|
||||
}
|
2
TODO.md
2
TODO.md
@ -2,6 +2,7 @@ BUILD
|
||||
|
||||
- [x] single import
|
||||
- [x] browsersync
|
||||
- [ ] remove platform, dependent on fix of bug in gulp-vulcanize
|
||||
|
||||
REFACTOR
|
||||
|
||||
@ -9,6 +10,7 @@ REFACTOR
|
||||
- [ ] Gui.js => gui-panel => dat-gui
|
||||
- [x] controller-* => dat-gui-*
|
||||
- [x] kill strict
|
||||
- [x] Reorg gulpfile and add standardized formatting
|
||||
|
||||
PARITY
|
||||
|
||||
|
@ -20,5 +20,10 @@
|
||||
"dependencies": {
|
||||
"polymer": "Polymer/polymer#>=0.4.0",
|
||||
"platform": "Polymer/platform#>=0.4.0"
|
||||
},
|
||||
"resolutions": {
|
||||
"core-action-icons": "0.2.4",
|
||||
"platform": ">=0.4.0 <1.0.0",
|
||||
"core-component-page": ">=0.4.0 <1.0.0"
|
||||
}
|
||||
}
|
||||
|
12
build/dat-gui.html
Normal file → Executable file
12
build/dat-gui.html
Normal file → Executable file
File diff suppressed because one or more lines are too long
14
build/dat-gui.js
Normal file → Executable file
14
build/dat-gui.js
Normal file → Executable file
File diff suppressed because one or more lines are too long
@ -28,7 +28,6 @@ h1
|
||||
margin-bottom unit * 3
|
||||
|
||||
h3
|
||||
|
||||
padding unit 0
|
||||
margin-bottom unit * 2
|
||||
|
||||
|
@ -15,7 +15,9 @@
|
||||
<body>
|
||||
|
||||
<!-- Copied from README.md -->
|
||||
<div id="readme"></div>
|
||||
<div id="readme">
|
||||
<%= contents %>
|
||||
</div>
|
||||
|
||||
<script src="docs/main.js"></script>
|
||||
<script src="docs/examples.js"></script>
|
||||
|
@ -78,10 +78,7 @@
|
||||
|
||||
};
|
||||
|
||||
Gui.prototype.remember = function( object ) {
|
||||
|
||||
|
||||
};
|
||||
Gui.prototype.remember = function( object ) {};
|
||||
|
||||
Gui.prototype.var = function() {
|
||||
|
||||
|
@ -9,9 +9,7 @@ Gui.register( 'dat-gui-boolean', function( value ) {
|
||||
|
||||
Polymer( 'dat-gui-boolean', {
|
||||
|
||||
ready: function() {
|
||||
|
||||
},
|
||||
ready: function() {},
|
||||
|
||||
toggle: function() {
|
||||
|
||||
|
@ -158,7 +158,9 @@ Polymer( 'dat-gui-number', {
|
||||
|
||||
e.preventDefault();
|
||||
this._rect = this.$.track.getBoundingClientRect();
|
||||
if ( !this._alt ) { this.value = this.valueFromX( e.x ); }
|
||||
if ( !this._alt ) {
|
||||
this.value = this.valueFromX( e.x );
|
||||
}
|
||||
|
||||
this.fire( 'sliderDown' );
|
||||
|
||||
@ -184,7 +186,9 @@ Polymer( 'dat-gui-number', {
|
||||
|
||||
var dv = this.valueFromDX( e.ddx );
|
||||
|
||||
if ( this._alt ) { dv /= 10; }
|
||||
if ( this._alt ) {
|
||||
dv /= 10;
|
||||
}
|
||||
|
||||
this.value += dv * this._dragFriction;
|
||||
|
||||
|
@ -5,9 +5,7 @@ Polymer( 'gui-row', {
|
||||
comment: null,
|
||||
commentOpen: false,
|
||||
|
||||
ready: function() {
|
||||
|
||||
},
|
||||
ready: function() {},
|
||||
|
||||
openComment: function() {
|
||||
this.commentOpen = true;
|
||||
|
@ -27,7 +27,9 @@
|
||||
|
||||
};
|
||||
|
||||
var identity = function() { return this; };
|
||||
var identity = function() {
|
||||
return this;
|
||||
};
|
||||
|
||||
var controllerShim = {
|
||||
on: identity
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
<script src="../build/dat-gui.js"></script>
|
||||
<!--
|
||||
<script src="../platform/platform.js"></script>
|
||||
<script src="../../platform/platform.js"></script>
|
||||
<link rel="import" href="../dat-gui.html">
|
||||
-->
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
body content.
|
||||
|
||||
<script>
|
||||
/* globals Gui */
|
||||
|
||||
var object = {
|
||||
"boolean": false,
|
||||
@ -40,7 +41,7 @@
|
||||
// How do we kill polymer-ready ...
|
||||
Gui.ready( function() {
|
||||
|
||||
gui = new Gui();
|
||||
var gui = new Gui();
|
||||
|
||||
gui.panel.docked = true;
|
||||
|
||||
|
304
gulpfile.js
304
gulpfile.js
@ -1,66 +1,37 @@
|
||||
var gulp = require( 'gulp' ),
|
||||
nib = require( 'nib' ),
|
||||
fs = require( 'fs' ),
|
||||
marked = require( 'marked' ),
|
||||
karma = require( 'karma' ),
|
||||
browserSync = require( 'browser-sync' ),
|
||||
$ = require( 'gulp-load-plugins' )();
|
||||
/*
|
||||
|
||||
var paths = {
|
||||
build: [ 'elements/**/*.styl', 'elements/**/*.html', 'elements/**/*.js' , 'dat-gui.html' ],
|
||||
lint: [ 'gulpfile.js', 'elements/**/*.js' ],
|
||||
test: [ 'build/dat-gui.js', 'tests/*.js' ],
|
||||
clean: [ 'build/*', '**/*.css' ],
|
||||
docs: [ 'README.md', 'docs/*' ],
|
||||
shim: [ 'elements/shim.js' ]
|
||||
};
|
||||
Main Gulp tasks
|
||||
-----------------
|
||||
|
||||
gulp.task( 'default', [ 'docs', 'lint', 'shim', 'build' ] );
|
||||
* default - dev
|
||||
|
||||
gulp.task( 'watch', [ 'default' ], function() {
|
||||
* build - create a vulcanized compiled version after linting and formatting
|
||||
* dev - launch server, watch for code changes, lint, format
|
||||
* docs - compile the docs and update gh-pages
|
||||
* release - build js and docs and update version tag
|
||||
* test - run the tests
|
||||
* watch - watch for code changes and update styles but serve it yourself
|
||||
|
||||
karma.server.start( {
|
||||
frameworks: [ 'jasmine' ],
|
||||
files: paths.test
|
||||
} );
|
||||
Gulp tasks used by the main gulp tasks
|
||||
--------------------------------------
|
||||
|
||||
gulp.watch( paths.docs, [ 'docs' ] );
|
||||
gulp.watch( paths.lint, [ 'lint' ] );
|
||||
gulp.watch( paths.build, [ 'build' ] );
|
||||
gulp.watch( paths.shim, [ 'shim' ] );
|
||||
* clean - remove build files
|
||||
* style - convert stylus to css
|
||||
* fmt - format the js with esformater
|
||||
* lint - lint the js with jshint
|
||||
* readme - convert the readme.md into interactive html doc
|
||||
* reload - reload the webserver
|
||||
* serve - start the webserver
|
||||
* shim - create the shim loader
|
||||
* vulcanize - vulcanize the into one file
|
||||
|
||||
} );
|
||||
*/
|
||||
|
||||
gulp.task( 'reload', function() {
|
||||
browserSync.reload();
|
||||
} );
|
||||
var gulp = require( 'gulp' );
|
||||
|
||||
gulp.task( 'dev', [ 'default', 'browser' ], function() {
|
||||
|
||||
karma.server.start( {
|
||||
frameworks: [ 'jasmine' ],
|
||||
files: paths.test
|
||||
} );
|
||||
|
||||
gulp.watch( paths.docs, [ 'docs', 'reload' ] );
|
||||
gulp.watch( paths.lint, [ 'lint', 'reload' ] );
|
||||
gulp.watch( paths.build, [ 'build', 'reload' ] );
|
||||
gulp.watch( paths.shim, [ 'shim', 'reload' ] );
|
||||
|
||||
} );
|
||||
|
||||
gulp.task( 'browser', [], function() {
|
||||
browserSync.init( null, {
|
||||
browser: [ 'google-chrome', 'google chrome' ], // linux uses the -
|
||||
server: {
|
||||
baseDir: [ '..' ]
|
||||
},
|
||||
startPath: '/dat.gui/'
|
||||
} );
|
||||
} );
|
||||
|
||||
gulp.task( 'build', [ 'vulcanize' ], function() {
|
||||
gulp.task( 'default', [ 'dev' ] );
|
||||
|
||||
gulp.task( 'build', [ 'readme', 'lint', 'vulcanize', 'shim' ], function() {
|
||||
return gulp.src( 'build/dat-gui.html' )
|
||||
.pipe( $.replace( /\\/g, '\\\\' ) )
|
||||
.pipe( $.replace( /'/g, '\\\'' ) )
|
||||
@ -71,10 +42,133 @@ gulp.task( 'build', [ 'vulcanize' ], function() {
|
||||
|
||||
} );
|
||||
|
||||
gulp.task( 'vulcanize', [ 'css' ], function() {
|
||||
gulp.task( 'dev', [ 'watch', 'test', 'serve' ] );
|
||||
|
||||
gulp.task( 'docs', [ 'style', 'readme' ] );
|
||||
|
||||
gulp.task( 'release', function() {
|
||||
console.log( 'Task not yet implemented.' );
|
||||
} );
|
||||
|
||||
gulp.task( 'test', function() {
|
||||
|
||||
karma.server.start( {
|
||||
frameworks: [ 'jasmine' ],
|
||||
files: paths.test
|
||||
} );
|
||||
|
||||
} );
|
||||
|
||||
gulp.task( 'watch', [ 'build' ], function() {
|
||||
// watches and builds all tasks
|
||||
// gulp.watch( paths.html.concat(paths.styl).concat(paths.js).concat(paths.shim), [ 'build' ] );
|
||||
|
||||
gulp.watch( paths.docs, [ 'readme' ] );
|
||||
gulp.watch( paths.styl, [ 'style' ] );
|
||||
|
||||
gulp.watch( paths.html.concat( paths.styl )
|
||||
.concat( paths.js ).concat( paths.shim )
|
||||
.concat( paths.docs ), [ 'reload' ] );
|
||||
|
||||
// fmt
|
||||
$.watch( paths.js, {
|
||||
base: './'
|
||||
} )
|
||||
.pipe( $.esformatter( formattingOptions ) )
|
||||
.pipe( gulp.dest( './' ) );
|
||||
} );
|
||||
|
||||
////////////////////////////////////////////////
|
||||
|
||||
gulp.task( 'clean', function() {
|
||||
return gulp.src( 'build/*' )
|
||||
.pipe( $.rimraf() );
|
||||
} );
|
||||
|
||||
gulp.task( 'style', function() {
|
||||
return gulp.src( paths.styl, {
|
||||
base: './'
|
||||
} )
|
||||
.pipe( $.stylus( {
|
||||
use: [ nib() ]
|
||||
} ) )
|
||||
.pipe( gulp.dest( './' ) )
|
||||
.pipe( $.filter( '**/*.css' ) )
|
||||
.pipe( $.if( browserSync.active, browserSync.reload( {
|
||||
stream: true
|
||||
} ) ) );
|
||||
|
||||
} );
|
||||
|
||||
gulp.task( 'fmt', function() {
|
||||
|
||||
return gulp.src( paths.js, {
|
||||
base: './'
|
||||
} )
|
||||
.pipe( $.esformatter( formattingOptions ) )
|
||||
.pipe( gulp.dest( './' ) );
|
||||
|
||||
} );
|
||||
|
||||
gulp.task( 'lint', [ 'fmt' ], function() {
|
||||
|
||||
return gulp.src( paths.js )
|
||||
.pipe( browserSync.reload( {
|
||||
stream: true,
|
||||
once: true
|
||||
} ) )
|
||||
.pipe( $.jshint( '.jshintrc' ) )
|
||||
.pipe( $.jshint.reporter( 'jshint-stylish' ) )
|
||||
.pipe( $.if( !browserSync.active, $.jshint.reporter( 'fail' ) ) );
|
||||
|
||||
} );
|
||||
|
||||
gulp.task( 'readme', function() {
|
||||
return gulp.src( 'README.md' )
|
||||
.pipe( $.marked( { // convert the markdown
|
||||
gfm: true, // use github flavor markdown
|
||||
highlight: function( code ) { // highlight the code
|
||||
return highlight.highlightAuto( code ).value;
|
||||
}
|
||||
} ) )
|
||||
.pipe( $.wrap( {
|
||||
src: 'docs/template.html'
|
||||
} ) )
|
||||
.pipe( $.rename( 'index.html' ) )
|
||||
.pipe( gulp.dest( './' ) );
|
||||
|
||||
} );
|
||||
|
||||
gulp.task( 'reload', function() {
|
||||
if ( browserSync.active ) {
|
||||
browserSync.reload();
|
||||
}
|
||||
} );
|
||||
|
||||
gulp.task( 'serve', function() {
|
||||
browserSync.init( null, {
|
||||
browser: [ 'google-chrome', 'google chrome' ], // linux uses the -
|
||||
server: {
|
||||
baseDir: [ '..' ]
|
||||
},
|
||||
startPath: '/dat.gui/'
|
||||
} );
|
||||
} );
|
||||
|
||||
gulp.task( 'shim', function() {
|
||||
|
||||
return gulp.src( paths.shim )
|
||||
.pipe( $.uglify() )
|
||||
.pipe( $.rename( 'dat-gui.shim.js' ) )
|
||||
.pipe( gulp.dest( 'build' ) );
|
||||
|
||||
} );
|
||||
|
||||
gulp.task( 'vulcanize', [ 'style' ], function() {
|
||||
|
||||
return gulp.src( 'dat-gui.html' )
|
||||
.pipe( $.insert.prepend( '<script src="../platform/platform.js"></script>"\n' ) )
|
||||
// must use the latest version of gulp-vulcanize otherwise it grabs the file from disk
|
||||
.pipe( $.insert.prepend( '<script src="../platform/platform.js"></script>\n' ) )
|
||||
.pipe( $.vulcanize( {
|
||||
dest: 'build',
|
||||
inline: true,
|
||||
@ -88,66 +182,46 @@ gulp.task( 'vulcanize', [ 'css' ], function() {
|
||||
|
||||
} );
|
||||
|
||||
gulp.task( 'lint', [ 'jscs', 'jshint' ] );
|
||||
var nib = require( 'nib' ),
|
||||
highlight = require( 'highlight.js' ),
|
||||
karma = require( 'karma' ),
|
||||
browserSync = require( 'browser-sync' ),
|
||||
$ = require( 'gulp-load-plugins' )();
|
||||
|
||||
gulp.task( 'jscs', function() {
|
||||
|
||||
return gulp.src( paths.lint )
|
||||
.pipe( $.jscs() );
|
||||
|
||||
} );
|
||||
|
||||
gulp.task( 'jshint', function() {
|
||||
|
||||
return gulp.src( paths.lint )
|
||||
.pipe( browserSync.reload( { stream: true, once: true } ) )
|
||||
.pipe( $.jshint( '.jshintrc' ) )
|
||||
.pipe( $.jshint.reporter( 'jshint-stylish' ) )
|
||||
.pipe( $.if( !browserSync.active, $.jshint.reporter( 'fail' ) ) );
|
||||
|
||||
} );
|
||||
|
||||
gulp.task( 'css', function() {
|
||||
|
||||
return css( 'elements/**/*.styl', 'elements' );
|
||||
|
||||
} );
|
||||
|
||||
gulp.task( 'shim', function() {
|
||||
|
||||
return gulp.src( paths.shim )
|
||||
.pipe( $.uglify() )
|
||||
.pipe( $.rename( 'gui.shim.js' ) )
|
||||
.pipe( gulp.dest( 'build' ) );
|
||||
|
||||
} );
|
||||
|
||||
gulp.task( 'docs', function() {
|
||||
|
||||
css( 'docs/*.styl', 'docs' );
|
||||
|
||||
var content = {
|
||||
readme: marked( fs.readFileSync( 'README.md', 'utf8' ) )
|
||||
var paths = {
|
||||
docs: [ 'README.md', 'docs/template.html' ],
|
||||
js: [ 'gulpfile.js', 'elements/**/*.js' ],
|
||||
html: [ 'dat-gui.html', 'elements/**/*.html' ],
|
||||
shim: [ 'elements/shim.js' ],
|
||||
styl: [ 'docs/*.styl', 'elements/**/*.styl' ],
|
||||
test: [ 'build/dat-gui.js', 'tests/*.js' ]
|
||||
};
|
||||
|
||||
return gulp.src( 'docs/template.html' )
|
||||
.pipe( $.plates( content ) )
|
||||
.pipe( $.rename( 'index.html' ) )
|
||||
.pipe( gulp.dest( './' ) );
|
||||
|
||||
} );
|
||||
|
||||
gulp.task( 'clean', function() {
|
||||
|
||||
return gulp.src( paths.clean )
|
||||
.pipe( $.rimraf() );
|
||||
|
||||
} );
|
||||
|
||||
function css( src, dest ) {
|
||||
|
||||
return gulp.src( src )
|
||||
.pipe( $.stylus( { use: [ nib() ] } ) )
|
||||
.pipe( gulp.dest( dest ) );
|
||||
|
||||
var formattingOptions = {
|
||||
'preset': 'jquery',
|
||||
'plugins': [
|
||||
'esformatter-quotes',
|
||||
'esformatter-semicolons',
|
||||
'esformatter-braces'
|
||||
],
|
||||
'quotes': {
|
||||
'type': 'single',
|
||||
'avoidEscape': false
|
||||
},
|
||||
'indent': {
|
||||
'value': ' '
|
||||
},
|
||||
'whiteSpace': {
|
||||
'before': {
|
||||
'ArgumentListObjectExpression': 1,
|
||||
'ArgumentListFunctionExpression': 1,
|
||||
'ArgumentListArrayExpression': 1
|
||||
},
|
||||
'after': {
|
||||
'ArgumentListObjectExpression': 1,
|
||||
'ArgumentListFunctionExpression': 1,
|
||||
'ArgumentListArrayExpression': 1
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
161
index.html
161
index.html
@ -15,7 +15,8 @@
|
||||
<body>
|
||||
|
||||
<!-- Copied from README.md -->
|
||||
<div id="readme"><h1 id="dat-gui">dat-gui</h1>
|
||||
<div id="readme">
|
||||
<h1 id="dat-gui">dat-gui</h1>
|
||||
<p>dat-gui creates an interface that you can use to modify variables with very little code. </p>
|
||||
<p><a href="#basic-usage"> Basic Usage </a> •
|
||||
<a href="#limits"> Limits </a> •
|
||||
@ -25,72 +26,64 @@
|
||||
<a href="#saving"> Saving </a></p>
|
||||
<h3 id="basic-usage">Basic Usage</h3>
|
||||
<p>Download the <a href="todo">minified library</a> and include it in your html.</p>
|
||||
<pre><code class="lang-html"><script src="gui.js"></script>
|
||||
</code></pre>
|
||||
<pre><code class="lang-html"><span class="hljs-tag"><<span class="hljs-title">script</span> <span class="hljs-attribute">src</span>=<span class="hljs-value">"gui.js"</span>></span><span class="javascript"></span><span class="hljs-tag"></<span class="hljs-title">script</span>></span></code></pre>
|
||||
<p>Create controllers by adding objects and their properties. dat-gui chooses a controller based on the variable's initial value.</p>
|
||||
<pre><code class="lang-javascript">var gui = new Gui();
|
||||
gui.add( object, 'numberProperty', 0, 1 ); // Slider
|
||||
gui.add( object, 'stringProperty' ); // Text box
|
||||
gui.add( object, 'booleanProperty' ); // Check box
|
||||
gui.add( object, 'functionProperty' ); // Button
|
||||
</code></pre>
|
||||
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> gui = <span class="hljs-keyword">new</span> Gui();
|
||||
gui.<span class="hljs-keyword">add</span>( object, <span class="hljs-string">'numberProperty'</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span> ); <span class="hljs-comment">// Slider</span>
|
||||
gui.<span class="hljs-keyword">add</span>( object, <span class="hljs-string">'stringProperty'</span> ); <span class="hljs-comment">// Text box</span>
|
||||
gui.<span class="hljs-keyword">add</span>( object, <span class="hljs-string">'booleanProperty'</span> ); <span class="hljs-comment">// Check box</span>
|
||||
gui.<span class="hljs-keyword">add</span>( object, <span class="hljs-string">'functionProperty'</span> ); <span class="hljs-comment">// Button</span></code></pre>
|
||||
<h3 id="limits">Limits</h3>
|
||||
<p>You can specify limits on numbers. A number with a min and max value becomes a slider.</p>
|
||||
<pre><code class="lang-javascript">gui.add( text, 'growthSpeed', -5, 5 ); // Min and max
|
||||
gui.add( text, 'noiseStrength' ).step( 5 ); // Increment amount
|
||||
gui.add( text, 'maxSize' ).min( 0 ).step( 0.25 ); // Mix and match
|
||||
</code></pre>
|
||||
<pre><code class="lang-javascript"><span class="hljs-keyword">gui</span>.<span class="hljs-built_in">add</span>( text, <span class="hljs-string">'growthSpeed'</span>, -<span class="hljs-number">5</span>, <span class="hljs-number">5</span> ); // Min <span class="hljs-built_in">and</span> <span class="hljs-built_in">max</span>
|
||||
<span class="hljs-keyword">gui</span>.<span class="hljs-built_in">add</span>( text, <span class="hljs-string">'noiseStrength'</span> ).step( <span class="hljs-number">5</span> ); // Increment amount
|
||||
<span class="hljs-keyword">gui</span>.<span class="hljs-built_in">add</span>( text, <span class="hljs-string">'maxSize'</span> ).<span class="hljs-built_in">min</span>( <span class="hljs-number">0</span> ).step( <span class="hljs-number">0.25</span> ); // Mix <span class="hljs-built_in">and</span> <span class="hljs-built_in">match</span></code></pre>
|
||||
<p>You can also provide a list of accepted values for a dropdown.</p>
|
||||
<pre><code class="lang-javascript">// Choose from accepted values
|
||||
gui.add( text, 'message', [ 'pizza', 'chrome', 'hooray' ] );
|
||||
<pre><code class="lang-javascript"><span class="hljs-comment">// Choose from accepted values</span>
|
||||
gui.add( text, <span class="hljs-string">'message'</span>, [ <span class="hljs-string">'pizza'</span>, <span class="hljs-string">'chrome'</span>, <span class="hljs-string">'hooray'</span> ] );
|
||||
|
||||
// Choose from named values
|
||||
gui.add( text, 'speed', { Stopped: 0, Slow: 0.1, Fast: 5 } );
|
||||
</code></pre>
|
||||
<span class="hljs-comment">// Choose from named values</span>
|
||||
gui.add( text, <span class="hljs-string">'speed'</span>, { <span class="hljs-string">Stopped:</span> <span class="hljs-number">0</span>, <span class="hljs-string">Slow:</span> <span class="hljs-number">0.1</span>, <span class="hljs-string">Fast:</span> <span class="hljs-number">5</span> } );</code></pre>
|
||||
<h3 id="colors">Colors</h3>
|
||||
<p>dat-gui has a color selector and understands many different representations of color. The following creates color controllers for color variables of different formats.</p>
|
||||
<pre><code class="lang-javascript">text.color0 = "#ffae23"; // CSS string
|
||||
text.color1 = [ 0, 128, 255 ]; // RGB array
|
||||
text.color2 = [ 0, 128, 255, 0.3 ]; // RGB with alpha
|
||||
text.color3 = { h: 350, s: 0.9, v: 0.3 }; // Hue, saturation, value
|
||||
<pre><code class="lang-javascript"><span class="hljs-keyword">text</span>.color0 = <span class="hljs-string">"#ffae23"</span>; <span class="hljs-comment">// CSS string</span>
|
||||
<span class="hljs-keyword">text</span>.color1 = [ <span class="hljs-number">0</span>, <span class="hljs-number">128</span>, <span class="hljs-number">255</span> ]; <span class="hljs-comment">// RGB array</span>
|
||||
<span class="hljs-keyword">text</span>.color2 = [ <span class="hljs-number">0</span>, <span class="hljs-number">128</span>, <span class="hljs-number">255</span>, <span class="hljs-number">0.3</span> ]; <span class="hljs-comment">// RGB with alpha</span>
|
||||
<span class="hljs-keyword">text</span>.color3 = { h: <span class="hljs-number">350</span>, s: <span class="hljs-number">0.9</span>, v: <span class="hljs-number">0.3</span> }; <span class="hljs-comment">// Hue, saturation, value</span>
|
||||
|
||||
var gui = new Gui();
|
||||
|
||||
gui.addColor(text, 'color0');
|
||||
gui.addColor(text, 'color1');
|
||||
gui.addColor(text, 'color2');
|
||||
gui.addColor(text, 'color3');
|
||||
</code></pre>
|
||||
gui.addColor(<span class="hljs-keyword">text</span>, <span class="hljs-string">'color0'</span>);
|
||||
gui.addColor(<span class="hljs-keyword">text</span>, <span class="hljs-string">'color1'</span>);
|
||||
gui.addColor(<span class="hljs-keyword">text</span>, <span class="hljs-string">'color2'</span>);
|
||||
gui.addColor(<span class="hljs-keyword">text</span>, <span class="hljs-string">'color3'</span>);</code></pre>
|
||||
<h3 id="events">Events</h3>
|
||||
<p>You can listen for events on individual controllers using an event listener syntax.</p>
|
||||
<pre><code class="lang-javascript">var controller = gui.add(fizzyText, 'maxSize', 0, 10);
|
||||
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> controller = gui.add(fizzyText, <span class="hljs-string">'maxSize'</span>, <span class="hljs-number">0</span>, <span class="hljs-number">10</span>);
|
||||
|
||||
controller.onChange(function(value) {
|
||||
// Fires on every change, drag, keypress, etc.
|
||||
controller.onChange(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(value)</span> </span>{
|
||||
<span class="hljs-comment">// Fires on every change, drag, keypress, etc.</span>
|
||||
});
|
||||
|
||||
controller.onFinishChange(function(value) {
|
||||
// Fires when a controller loses focus.
|
||||
alert("The new value is " + value);
|
||||
});
|
||||
</code></pre>
|
||||
controller.onFinishChange(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(value)</span> </span>{
|
||||
<span class="hljs-comment">// Fires when a controller loses focus.</span>
|
||||
alert(<span class="hljs-string">"The new value is "</span> + value);
|
||||
});</code></pre>
|
||||
<h3 id="folders">Folders</h3>
|
||||
<p>You can nest as many dat-gui as you want. Nested dat-gui act as collapsible folders.</p>
|
||||
<pre><code class="lang-javascript">var gui = new Gui();
|
||||
<pre><code class="lang-javascript">var <span class="hljs-keyword">gui</span> = <span class="hljs-keyword">new</span> Gui();
|
||||
|
||||
var f1 = gui.addFolder('Flow Field');
|
||||
f1.add(text, 'speed');
|
||||
f1.add(text, 'noiseStrength');
|
||||
var f1 = <span class="hljs-keyword">gui</span>.addFolder(<span class="hljs-string">'Flow Field'</span>);
|
||||
f1.<span class="hljs-built_in">add</span>(text, <span class="hljs-string">'speed'</span>);
|
||||
f1.<span class="hljs-built_in">add</span>(text, <span class="hljs-string">'noiseStrength'</span>);
|
||||
|
||||
var f2 = gui.addFolder('Letters');
|
||||
f2.add(text, 'growthSpeed');
|
||||
f2.add(text, 'maxSize');
|
||||
var f2 = <span class="hljs-keyword">gui</span>.addFolder(<span class="hljs-string">'Letters'</span>);
|
||||
f2.<span class="hljs-built_in">add</span>(text, <span class="hljs-string">'growthSpeed'</span>);
|
||||
f2.<span class="hljs-built_in">add</span>(text, <span class="hljs-string">'maxSize'</span>);
|
||||
|
||||
f2.open();
|
||||
</code></pre>
|
||||
f2.<span class="hljs-keyword">open</span>();</code></pre>
|
||||
<p>The comment method adds a tooltip to a controller.</p>
|
||||
<pre><code class="lang-javascript">f2.add(text, 'message').comment( 'This is the comment.' );
|
||||
</code></pre>
|
||||
<pre><code class="lang-javascript">f2.add(text, <span class="hljs-attribute">'message</span>').comment( <span class="hljs-attribute">'This</span> <span class="hljs-keyword">is</span> the comment.' );</code></pre>
|
||||
<h3 id="saving">Saving</h3>
|
||||
<p>Add a save menu to the interface by calling <code>gui.remember</code> on all the objects you've added to the Gui.</p>
|
||||
<pre><code class="lang-javascript">var fizzyText = new FizzyText();
|
||||
@ -98,59 +91,52 @@ var gui = new Gui();
|
||||
|
||||
gui.remember(fizzyText);
|
||||
|
||||
// Add controllers ...
|
||||
</code></pre>
|
||||
// Add controllers <span class="hljs-keyword">...</span></code></pre>
|
||||
<p>Click the gear icon to change your save settings. You can either save your dat-gui values to localStorage, or by copying and pasting a JSON object into your source code as follows:</p>
|
||||
<pre><code class="lang-javascript">var fizzyText = new FizzyText();
|
||||
var gui = new Gui( { load: JSON } );
|
||||
|
||||
gui.remember( fizzyText );
|
||||
|
||||
// Add controllers ...
|
||||
</code></pre>
|
||||
// Add controllers <span class="hljs-keyword">...</span></code></pre>
|
||||
<h3 id="presets">Presets</h3>
|
||||
<p>The save menu also allows you to save all of your settings as presets. Click Save to modify the current preset, or New to create a new preset from existing settings. Clicking Revert will clear all unsaved changes to the current preset.</p>
|
||||
<p>Switch between presets using the dropdown in the save menu. You can specify the default like this:</p>
|
||||
<pre><code class="lang-javascript">var gui = new Gui({
|
||||
load: JSON,
|
||||
preset: 'Flow'
|
||||
});
|
||||
</code></pre>
|
||||
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> gui = <span class="hljs-keyword">new</span> Gui({
|
||||
load: <span class="hljs-built_in">JSON</span>,
|
||||
preset: <span class="hljs-string">'Flow'</span>
|
||||
});</code></pre>
|
||||
<p>A word of caution about localStorage:</p>
|
||||
<p>Paste the JSON save object into your source frequently. Using localStorage to save presets can make you faster, but its easy to lose your settings by clearing browsing data, changing browsers, or even by changing the URL of the page you're working on.</p>
|
||||
<h3 id="save-to-disk">Save to Disk</h3>
|
||||
<p>dat-gui comes with a node server that saves your settings to disk. This way you don't have to worry about losing your values to local storage or copying and pasting a JSON string.</p>
|
||||
<p>First, run the node script:</p>
|
||||
<pre><code class="lang-sh">$ node gui-server
|
||||
</code></pre>
|
||||
<pre><code class="lang-sh"><span class="hljs-variable">$ </span>node gui-server</code></pre>
|
||||
<p>Next, instantiate your Gui with a path to a JSON file to store settings. dat-gui will read from this file on load and write to this file on change.</p>
|
||||
<pre><code class="lang-javascript">var gui = new Gui( { load: 'path/to/file.json' } );
|
||||
</code></pre>
|
||||
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> gui = <span class="hljs-keyword">new</span> Gui( { load: <span class="hljs-string">'path/to/file.json'</span> } );</code></pre>
|
||||
<h3 id="custom-placement">Custom Placement</h3>
|
||||
<p>By default, Gui panels are created with fixed position, and are automatically appended to the body. You can change this behavior by setting the <code>autoPlace</code> parameter to <code>false</code>.</p>
|
||||
<pre><code class="lang-javascript">var gui = new Gui( { autoPlace: false } );
|
||||
<pre><code class="lang-javascript"><span class="hljs-reserved">var</span> gui = <span class="hljs-keyword">new</span> Gui( { <span class="hljs-attribute">autoPlace</span>: <span class="hljs-literal">false</span> } );
|
||||
|
||||
var customContainer = document.getElementById('my-gui-container');
|
||||
customContainer.appendChild(gui.domElement);
|
||||
</code></pre>
|
||||
<span class="hljs-reserved">var</span> customContainer = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'my-gui-container'</span>);
|
||||
customContainer.appendChild(gui.domElement);</code></pre>
|
||||
<p>Since dat-gui is built using <a href="todo">Web Components</a>, you can also use HTML syntax to add controllers to the page.</p>
|
||||
<pre><code class="lang-html"><body>
|
||||
<pre><code class="lang-html"><span class="hljs-tag"><<span class="hljs-title">body</span>></span>
|
||||
|
||||
<dat-gui-number min="-2" max="2" step="1" value="0"></dat-gui-number>
|
||||
<span class="hljs-tag"><<span class="hljs-title">dat-gui-number</span> <span class="hljs-attribute">min</span>=<span class="hljs-value">"-2"</span> <span class="hljs-attribute">max</span>=<span class="hljs-value">"2"</span> <span class="hljs-attribute">step</span>=<span class="hljs-value">"1"</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">"0"</span>></span><span class="hljs-tag"></<span class="hljs-title">dat-gui-number</span>></span>
|
||||
|
||||
<script>
|
||||
<span class="hljs-tag"><<span class="hljs-title">script</span>></span><span class="javascript">
|
||||
|
||||
var controller = document.querySelector( 'dat-gui-number' );
|
||||
controller.onChange( function() {
|
||||
<span class="hljs-keyword">var</span> controller = <span class="hljs-built_in">document</span>.querySelector( <span class="hljs-string">'dat-gui-number'</span> );
|
||||
controller.onChange( <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{
|
||||
|
||||
// react to UI changes ...
|
||||
<span class="hljs-comment">// react to UI changes ...</span>
|
||||
|
||||
} );
|
||||
|
||||
</script>
|
||||
</span><span class="hljs-tag"></<span class="hljs-title">script</span>></span>
|
||||
|
||||
</body>
|
||||
</code></pre>
|
||||
<span class="hljs-tag"></<span class="hljs-title">body</span>></span></code></pre>
|
||||
<h3 id="defining-custom-controllers">Defining Custom Controllers</h3>
|
||||
<p>dat-gui uses <a href="todo">Polymer</a> under the hood to define custom elements. A dat-gui controller is just a <a href="todo">Polymer element</a> with two important requirements:</p>
|
||||
<ul>
|
||||
@ -158,37 +144,34 @@ controller.onChange( function() {
|
||||
<li>Controllers must be associated with a data type.</li>
|
||||
</ul>
|
||||
<p>Take for example this (simplified) source for dat-gui's <code><dat-gui-number></code>:</p>
|
||||
<pre><code class="lang-javascript">Polymer( 'dat-gui-number', {
|
||||
<pre><code class="lang-javascript">Polymer( <span class="hljs-string">'dat-gui-number'</span>, {
|
||||
|
||||
// Define element ...
|
||||
// Define element <span class="hljs-keyword">...</span>
|
||||
|
||||
} );
|
||||
|
||||
Gui.register( 'dat-gui-number', function( value ) {
|
||||
Gui.register( <span class="hljs-string">'dat-gui-number'</span>, <span class="hljs-keyword">function</span>( value ) {
|
||||
|
||||
return typeof value == 'number';
|
||||
<span class="hljs-keyword">return</span> typeof value == <span class="hljs-string">'number'</span>;
|
||||
|
||||
} );
|
||||
</code></pre>
|
||||
} );</code></pre>
|
||||
<p><code>Gui.register</code> takes an element name and a test function. The test function tells dat-gui to add a <code><dat-gui-number></code> to the panel when the user adds a variable whose type is <code>'number'</code>.</p>
|
||||
<p>A test function determines if a controller is appropriate for a given value. This example registers <code><vector-controller></code> for values that have properties <code>x</code>, <code>y</code> and <code>z</code>.</p>
|
||||
<pre><code class="lang-javascript">Gui.register( 'vector-controller', function( value ) {
|
||||
<pre><code class="lang-javascript">Gui.register( <span class="hljs-string">'vector-controller'</span>, function( <span class="hljs-keyword">value</span> ) {
|
||||
|
||||
return value.hasOwnProperty( 'x' ) &&
|
||||
value.hasOwnProperty( 'y' ) &&
|
||||
value.hasOwnProperty( 'z' );
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">value</span>.hasOwnProperty( <span class="hljs-string">'x'</span> ) &&
|
||||
<span class="hljs-keyword">value</span>.hasOwnProperty( <span class="hljs-string">'y'</span> ) &&
|
||||
<span class="hljs-keyword">value</span>.hasOwnProperty( <span class="hljs-string">'z'</span> );
|
||||
|
||||
} );
|
||||
</code></pre>
|
||||
} );</code></pre>
|
||||
<h3 id="publishing-custom-controllers">Publishing Custom Controllers</h3>
|
||||
<p>You should use <a href="todo">Bower</a> and format your plugin all nice and it should have a certain prefix yada yada.</p>
|
||||
<p>Installing third-party controllers ... </p>
|
||||
<pre><code class="lang-sh">$ bower install gui-three
|
||||
</code></pre>
|
||||
<pre><code class="lang-sh"><span class="hljs-variable">$ </span>bower install gui-three</code></pre>
|
||||
<p>Include the source for the third-party controllers after dat-gui.</p>
|
||||
<pre><code class="lang-html"><script src="gui.js"></script>
|
||||
<script src="gui-three.js"></script>
|
||||
</code></pre>
|
||||
<pre><code class="lang-html"><span class="hljs-tag"><<span class="hljs-title">script</span> <span class="hljs-attribute">src</span>=<span class="hljs-value">"gui.js"</span>></span><span class="javascript"></span><span class="hljs-tag"></<span class="hljs-title">script</span>></span>
|
||||
<span class="hljs-tag"><<span class="hljs-title">script</span> <span class="hljs-attribute">src</span>=<span class="hljs-value">"gui-three.js"</span>></span><span class="javascript"></span><span class="hljs-tag"></<span class="hljs-title">script</span>></span></code></pre>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="docs/main.js"></script>
|
||||
|
19
package.json
19
package.json
@ -3,26 +3,31 @@
|
||||
"version": "0.0.0",
|
||||
"devDependencies": {
|
||||
"browser-sync": "^1.3.6",
|
||||
"esformatter-braces": "^0.1.7",
|
||||
"esformatter-quotes": "^1.0.0",
|
||||
"esformatter-semicolons": "^1.0.3",
|
||||
"gulp": "^3.8.7",
|
||||
"gulp-esformatter": "^1.0.0",
|
||||
"gulp-filter": "^1.0.2",
|
||||
"gulp-if": "^1.2.4",
|
||||
"gulp-insert": "^0.4.0",
|
||||
"gulp-jscs": "^1.1.2",
|
||||
"gulp-jshint": "^1.8.4",
|
||||
"gulp-load-plugins": "^0.6.0",
|
||||
"gulp-plates": "0.0.5",
|
||||
"gulp-reload": "0.0.4",
|
||||
"gulp-marked": "^0.2.0",
|
||||
"gulp-rename": "^1.2.0",
|
||||
"gulp-replace": "^0.4.0",
|
||||
"gulp-rimraf": "^0.1.0",
|
||||
"gulp-stylus": "^1.3.0",
|
||||
"gulp-uglify": "^1.0.1",
|
||||
"gulp-vulcanize": "^1.0.0",
|
||||
"gulp-watch": "^0.6.9",
|
||||
"gulp-vulcanize": "^1.1.0",
|
||||
"gulp-watch": "^1.0.3",
|
||||
"gulp-wrap": "^0.3.0",
|
||||
"highlight.js": "^8.2.0",
|
||||
"jshint-stylish": "^0.4.0",
|
||||
"karma": "^0.12.23",
|
||||
"karma-chrome-launcher": "^0.1.4",
|
||||
"karma-jasmine": "^0.1.5",
|
||||
"marked": "^0.3.2",
|
||||
"nib": "^1.0.3"
|
||||
"nib": "^1.0.3",
|
||||
"through2": "^0.6.1"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user