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

145 lines
3.2 KiB
JavaScript
Raw Normal View History

2014-09-03 16:16:11 +00:00
// [ ] scrolling when docked
// [ ] scrolling when window short and not docked
2014-08-27 00:01:15 +00:00
Polymer('gui-panel', {
docked: false,
open: true,
2014-09-03 18:47:32 +00:00
touch: 'ontouchstart' in window || !!window.DocumentTouch && document instanceof DocumentTouch,
2014-08-27 00:01:15 +00:00
ready: function() {
2014-09-07 20:18:36 +00:00
this.defined = {};
2014-09-02 17:13:35 +00:00
// window.addEventListener( 'resize', this.checkHeight.bind( this ) );
2014-08-27 00:01:15 +00:00
},
2014-09-07 20:18:36 +00:00
define: function() {
2014-08-27 00:01:15 +00:00
if ( arguments.length == 1 ) {
var name = arguments[ 0 ];
2014-09-07 20:18:36 +00:00
return this.defined[ name ];
2014-08-27 00:01:15 +00:00
}
2014-09-07 20:18:36 +00:00
var initialValue = arguments[ 1 ];
var name = arguments[ 0 ];
2014-08-27 00:01:15 +00:00
2014-09-07 20:18:36 +00:00
var args = [ this.defined, name ];
2014-08-27 00:01:15 +00:00
args = args.concat( Array.prototype.slice.call( arguments, 2 ) );
2014-09-07 20:18:36 +00:00
this.defined[ name ] = initialValue;
2014-08-27 00:01:15 +00:00
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 );
2014-09-07 20:18:36 +00:00
var controllers;
2014-08-27 00:01:15 +00:00
2014-09-07 20:18:36 +00:00
if ( args[ 0 ] instanceof Array || typeof args[ 0 ] == 'object' ) {
controller = document.createElement( 'controller-option' );
} else {
controller = Gui.getController( value );
}
2014-08-27 00:01:15 +00:00
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
// -------------------------------
openChanged: function() {
if ( this.open || this.docked ) {
// let the style sheet take care of things
2014-09-07 20:18:36 +00:00
this.$.panel.style.transform = '';
2014-08-27 00:01:15 +00:00
} else {
// todo: need the rest of the vendor prefixes ...
// wish i could pipe javascript variables into styl.
var y = -this.$.controllers.offsetHeight + 'px';
2014-09-07 20:18:36 +00:00
this.$.panel.style.transform = 'translate3d(0, ' + y + ', 0)';
2014-08-27 00:01:15 +00:00
}
},
dockedChanged: function() {
this.openChanged();
},
// Events
// -------------------------------
2014-09-07 20:18:36 +00:00
toggleOpen: function() {
2014-08-27 00:01:15 +00:00
this.open = !this.open;
},
2014-09-02 17:13:35 +00:00
// checkHeight: function() {
2014-08-27 00:01:15 +00:00
2014-09-02 17:13:35 +00:00
// if ( window.innerHeight < this.$.controllers.offsetHeight ) {
// this.docked = true;
// } else {
// this.docked = false;
// }
2014-08-27 00:01:15 +00:00
2014-09-02 17:13:35 +00:00
// },
2014-08-27 00:01:15 +00:00
// Legacy
// -------------------------------
listenAll: function() {
Gui.warn( 'controller.listenAll() is deprecated. All controllers are listened for free.' );
},
// todo: domElement
});