dat.gui/elements/controller-base/controller-base.js

89 lines
1.5 KiB
JavaScript
Raw Normal View History

2014-08-15 22:04:51 +00:00
/*
[ ] onChange( )
[ ] onFinishChange( )
*/
Polymer('controller-base', {
2014-08-15 16:32:49 +00:00
value: null,
object: null,
property: null,
ready: function() {
var _this = this;
2014-08-15 22:04:51 +00:00
this.update();
},
bind: function() {
if ( this._observer ) {
this._observer.close();
delete this._observer;
}
var _this = this;
2014-08-15 16:32:49 +00:00
2014-08-15 22:04:51 +00:00
this._observer = new PathObserver( this.object, this.property );
this._observer.open( function( newValue ) {
2014-08-15 16:32:49 +00:00
2014-08-15 22:04:51 +00:00
_this.value = newValue;
2014-08-15 16:32:49 +00:00
2014-08-15 22:04:51 +00:00
} );
2014-08-15 16:32:49 +00:00
2014-08-15 22:04:51 +00:00
this.value = this.object[ this.property ];
2014-08-15 16:32:49 +00:00
2014-08-15 22:04:51 +00:00
},
update: function() {},
listen: function() {
console.warn( 'controller.listen() is deprecated. All controllers are listened for free.' );
2014-08-15 16:32:49 +00:00
},
// Observers
// -------------------------------
objectChanged: function( oldObject, newObject ) {
if ( newObject && this.property ) {
this.bind();
}
},
propertyChanged: function( oldProperty, newProperty ) {
if ( newProperty && this.object ) {
this.bind();
}
},
valueChanged: function() {
if ( this.object && this.property ) {
this.object[ this.property ] = this.value;
}
this.update();
},
// Helpers
// -------------------------------
map: function( x, a, b, c, d ) {
return ( x - a ) / ( b - a ) * ( d - c ) + c;
}
});