dat.gui/elements/gui-panel/gui-panel.js

121 lines
2.5 KiB
JavaScript
Raw Normal View History

2014-08-23 07:05:22 +00:00
/*
[ ] kill horizontal scroll when docked
*/
2014-08-15 16:32:49 +00:00
Polymer('gui-panel', {
2014-08-21 17:20:06 +00:00
docked: false,
2014-08-23 07:05:22 +00:00
open: true,
2014-08-21 17:20:06 +00:00
2014-08-15 16:32:49 +00:00
ready: function() {
2014-08-21 17:20:06 +00:00
this.anon.values = {};
2014-08-15 22:04:51 +00:00
2014-08-23 07:05:22 +00:00
window.addEventListener( 'resize', this.checkHeight.bind( this ) );
2014-08-15 22:04:51 +00:00
},
2014-08-23 07:05:22 +00:00
anon: function() {
2014-08-15 22:04:51 +00:00
2014-08-21 17:20:06 +00:00
if ( arguments.length == 1 ) {
2014-08-23 07:05:22 +00:00
var name = arguments[ 0 ];
2014-08-21 17:20:06 +00:00
return this.anon.values[ name ];
}
2014-08-15 22:04:51 +00:00
2014-08-23 07:05:22 +00:00
var initialValue = arguments[ 0 ];
var name = arguments[ 1 ];
2014-08-21 17:20:06 +00:00
var args = [ this.anon.values, name ];
args = args.concat( Array.prototype.slice.call( arguments, 2 ) );
2014-08-15 22:04:51 +00:00
2014-08-21 17:20:06 +00:00
this.anon.values[ name ] = initialValue;
2014-08-16 21:16:02 +00:00
2014-08-21 17:20:06 +00:00
return this.add.apply( this, args );
2014-08-16 21:16:02 +00:00
2014-08-21 17:20:06 +00:00
},
2014-08-16 21:16:02 +00:00
2014-08-21 17:20:06 +00:00
add: function( object, path ) {
2014-08-16 21:16:02 +00:00
2014-08-21 17:20:06 +00:00
// Make controller
2014-08-16 21:16:02 +00:00
2014-08-21 17:20:06 +00:00
var value = Path.get( path ).getValueFrom( object );
2014-08-16 21:16:02 +00:00
2014-08-21 17:20:06 +00:00
if ( value == null || value == undefined ) {
2014-08-23 07:05:22 +00:00
return Gui.error( object + ' doesn\'t have a value for path "' + path + '".' );
2014-08-16 21:16:02 +00:00
}
2014-08-21 17:20:06 +00:00
var args = Array.prototype.slice.call( arguments, 2 );
2014-08-16 21:16:02 +00:00
2014-08-21 17:20:06 +00:00
var controller = Gui.getController( value, args );
if ( !controller ) {
2014-08-23 07:05:22 +00:00
return Gui.error( 'Unrecognized type:', value );
2014-08-15 22:04:51 +00:00
}
2014-08-21 17:20:06 +00:00
controller.watch( object, path )
controller.init.apply( controller, args );
// Make row
2014-08-16 21:16:02 +00:00
2014-08-21 17:20:06 +00:00
var row = document.createElement( 'gui-row' );
row.name = path;
2014-08-15 22:04:51 +00:00
controller.name = function( name ) {
row.name = name;
};
2014-08-16 21:16:02 +00:00
controller.comment = function( comment ) {
row.comment = comment;
};
2014-08-15 22:04:51 +00:00
row.appendChild( controller );
this.appendChild( row );
return controller;
},
2014-08-23 07:05:22 +00:00
openChanged: function() {
var y;
if ( this.open ) {
y = 0;
} else {
y = -this.$.controllers.offsetHeight + 'px';
}
this.$.container.style.transform = 'translate3d(0, ' + y + ', 0)';
},
// Events
// -------------------------------
tapClose: function() {
this.open = !this.open;
},
checkHeight: function() {
if ( window.innerHeight < this.$.controllers.offsetHeight ) {
this.docked = true;
} else {
this.docked = false;
}
},
// Legacy
// -------------------------------
2014-08-15 22:04:51 +00:00
listenAll: function() {
2014-08-23 07:05:22 +00:00
Gui.warn( 'controller.listenAll() is deprecated. All controllers are listened for free.' );
},
2014-08-15 22:04:51 +00:00
2014-08-23 07:05:22 +00:00
// domElement
2014-08-15 16:32:49 +00:00
});