This commit is contained in:
George Michael Brower 2014-09-07 23:36:20 -04:00
parent 8b13c1b403
commit 8bc90e0a37
9 changed files with 142 additions and 159 deletions

13
build/gui.html Normal file → Executable file

File diff suppressed because one or more lines are too long

13
build/gui.js Normal file → Executable file

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,6 @@
( function( scope ) {
/* globals Path */
'use strict';
var Gui = function( params ) {
@ -10,15 +11,103 @@
params = params || {};
var panel = document.createElement( 'gui-panel' );
// Properties
panel.autoPlace = params.autoPlace !== false;
this.defined = {};
this.localStorage = params.localStorage || false;
if ( panel.autoPlace ) {
document.body.appendChild( panel );
// Make domElement
this.panel = document.createElement( 'gui-panel' );
this.panel.autoPlace = params.autoPlace !== false;
if ( this.panel.autoPlace ) {
document.body.appendChild( this.panel );
}
return panel;
};
// Instance methods
// -------------------------------
Gui.prototype.add = function( object, path ) {
// Make controller
var value = Path.get( path ).getValueFrom( object );
if ( value === null || value === undefined ) {
return Gui.error( object + ' doesn\'t have a value for path "' + path + '".' );
}
var args = Array.prototype.slice.call( arguments, 2 );
var controller;
if ( args[ 0 ] instanceof Array || typeof args[ 0 ] == 'object' ) {
controller = document.createElement( 'controller-option' );
} else {
controller = Gui.getController( value );
}
if ( !controller ) {
return Gui.error( 'Unrecognized type:', value );
}
controller.watch( object, path );
controller.init.apply( controller, args );
// Make row
var row = document.createElement( 'gui-row' );
row.name = path;
controller.row = row;
controller.name = function( name ) {
row.name = name;
};
controller.comment = function( comment ) {
row.comment = comment;
};
row.appendChild( controller );
this.panel.appendChild( row );
return controller;
};
Gui.prototype.remember = function( object ) {
};
Gui.prototype.define = function() {
var name, initialValue, args;
if ( arguments.length == 1 ) {
name = arguments[ 0 ];
return this.defined[ name ];
}
initialValue = arguments[ 1 ];
name = arguments[ 0 ];
args = [ this.defined, name ];
args = args.concat( Array.prototype.slice.call( arguments, 2 ) );
this.defined[ name ] = initialValue;
return this.add.apply( this, args );
};
Gui.prototype.listenAll = function() {
Gui.warn( 'controller.listenAll() is deprecated. All controllers are listened for free.' );
};
@ -83,7 +172,7 @@
};
// Error
// Console
// -------------------------------
Gui.error = function() {

View File

@ -54,8 +54,8 @@ Polymer( 'controller-base', {
listen: function() {
Gui.warn( 'controller.listen() is deprecated. ' +
'All controllers are listened for free.' );
Gui.warn( 'controller.listen() is deprecated. All controllers are listened for free.' );
return this;
},

View File

@ -1,12 +1,7 @@
/* globals Gui, Polymer */
/*
[ ] arrow keys
[ ] min() max() step() commands of yore
*/
// [ ] arrow keys
// [ ] min() max() step() commands of yore
Gui.register( 'controller-number', function( value ) {

View File

@ -1,5 +1,4 @@
/* globals Polymer, Path, Gui */
/* globals Polymer */
// [ ] scrolling when docked
// [ ] scrolling when window short and not docked
@ -8,85 +7,8 @@ Polymer( 'gui-panel', {
docked: false,
open: true,
touch: ( 'ontouchstart' in window ) ||
( !!window.DocumentTouch && document instanceof window.DocumentTouch ),
touch: ( 'ontouchstart' in window ) || ( !!window.DocumentTouch && document instanceof window.DocumentTouch ),
ready: function() {
this.domElement = this;
this.defined = {};
},
define: function() {
var name, initialValue, args;
if ( arguments.length == 1 ) {
name = arguments[ 0 ];
return this.defined[ name ];
}
initialValue = arguments[ 1 ];
name = arguments[ 0 ];
args = [ this.defined, name ];
args = args.concat( Array.prototype.slice.call( arguments, 2 ) );
this.defined[ name ] = initialValue;
return this.add.apply( this, args );
},
add: function( object, path ) {
// Make controller
var value = Path.get( path ).getValueFrom( object );
if ( value === null || value === undefined ) {
return Gui.error( object + ' doesn\'t have a value for path "' + path + '".' );
}
var args = Array.prototype.slice.call( arguments, 2 );
var controller;
if ( args[ 0 ] instanceof Array || typeof args[ 0 ] == 'object' ) {
controller = document.createElement( 'controller-option' );
} else {
controller = Gui.getController( value );
}
if ( !controller ) {
return Gui.error( 'Unrecognized type:', value );
}
controller.watch( object, path );
controller.init.apply( controller, args );
// Make row
var row = document.createElement( 'gui-row' );
row.name = path;
controller.row = row;
controller.name = function( name ) {
row.name = name;
};
controller.comment = function( comment ) {
row.comment = comment;
};
row.appendChild( controller );
this.appendChild( row );
return controller;
},
// Observers
// -------------------------------
@ -96,7 +18,6 @@ Polymer( 'gui-panel', {
if ( this.open || this.docked ) {
// let the style sheet take care of things
this.$.container.style.transform = '';
this.$.panel.style.transform = '';
@ -104,7 +25,6 @@ Polymer( 'gui-panel', {
// todo: need the rest of the vendor prefixes ...
// wish i could pipe javascript variables into styl.
var y = -this.$.controllers.offsetHeight + 'px';
this.$.container.style.transform = 'translate3d( 0, ' + y + ', 0 )';
@ -118,6 +38,7 @@ Polymer( 'gui-panel', {
},
// Events
// -------------------------------
@ -127,16 +48,6 @@ Polymer( 'gui-panel', {
toggleOpen: function() {
this.open = !this.open;
},
// Legacy
// -------------------------------
listenAll: function() {
Gui.warn( 'controller.listenAll() is deprecated. All controllers are listened for free.' );
}
} );

View File

@ -1,7 +1,6 @@
@import '../shared/shared'
// redefine touch because we are the host ...
touch( val = true )
{ '.touch-' + val } &
{ block }
@ -70,6 +69,8 @@ gui-button
width row-height*1.5
height row-height*1.5
box-sizing border-box
background color-panel
.docked-true.open-false &
transform translate3d( - panel-width, 0, 0 )

View File

@ -40,11 +40,11 @@
gui = new Gui();
gui.docked = true;
gui.panel.docked = true;
gui.add( gui, 'docked' );
gui.add( gui, 'panel.docked' );
var r = gui.add( gui, 'open' );
var r = gui.add( gui, 'panel.open' );
gui.add( r.row, 'name' );
gui.add( object, 'boolean' );

View File

@ -1,15 +1,11 @@
'use strict';
var gulp = require( 'gulp' ),
nib = require( 'nib' ),
fs = require( 'fs' ),
marked = require( 'marked' ),
karma = require( 'karma' ),
browserSync = require( 'browser-sync' ),
reload = browserSync.reload,
$ = require( 'gulp-load-plugins' )();
var paths = {
build: [ 'elements/**/*.styl', 'elements/**/*.html', 'elements/**/*.js' , 'gui.html' ],
lint: [ 'gulpfile.js', 'elements/**/*.js' ],
@ -52,7 +48,12 @@ gulp.task( 'vulcanize', [ 'css' ], function() {
dest: 'build',
inline: true,
strip: true
} ) );
} ) )
// clean up some vulcanize ...
.pipe( $.replace( /\n\n/gm, '' ) )
.pipe( $.replace( /<!-- .* -->/gm, '' ) )
.pipe( $.replace( /^<div hidden>undefined<\/div>\n/gm, '' ) )
.pipe( gulp.dest( 'build' ) );
} );
@ -68,7 +69,7 @@ gulp.task( 'jscs', function() {
gulp.task( 'jshint', function() {
return gulp.src( paths.lint )
.pipe( reload( { stream: true, once: true } ) )
.pipe( browserSync.reload( { stream: true, once: true } ) )
.pipe( $.jshint( '.jshintrc' ) )
.pipe( $.jshint.reporter( 'jshint-stylish' ) )
.pipe( $.if( !browserSync.active, $.jshint.reporter( 'fail' ) ) );