2014-08-15 22:04:51 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
[ ] onChange( )
|
|
|
|
[ ] onFinishChange( )
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2014-08-16 16:43:48 +00:00
|
|
|
Polymer('controller-base', {
|
2014-08-15 16:32:49 +00:00
|
|
|
|
|
|
|
ready: function() {
|
|
|
|
|
2014-08-15 22:04:51 +00:00
|
|
|
this.update();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-08-21 17:20:06 +00:00
|
|
|
update: function() {},
|
|
|
|
|
|
|
|
init: function() {},
|
|
|
|
|
|
|
|
|
|
|
|
// Observers
|
|
|
|
// -------------------------------
|
|
|
|
|
|
|
|
watch: function( object, path ) {
|
|
|
|
|
|
|
|
this.object = object;
|
|
|
|
this.path = path;
|
2014-08-15 22:04:51 +00:00
|
|
|
|
|
|
|
if ( this._observer ) {
|
|
|
|
this._observer.close();
|
|
|
|
delete this._observer;
|
|
|
|
}
|
|
|
|
|
|
|
|
var _this = this;
|
2014-08-15 16:32:49 +00:00
|
|
|
|
2014-08-21 17:20:06 +00:00
|
|
|
this._observer = new PathObserver( this.object, this.path );
|
2014-08-15 22:04:51 +00:00
|
|
|
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-21 17:20:06 +00:00
|
|
|
this.value = this.object[ this.path ];
|
2014-08-15 22:04:51 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-08-21 17:20:06 +00:00
|
|
|
valueChanged: function() {
|
2014-08-15 22:04:51 +00:00
|
|
|
|
2014-08-21 17:20:06 +00:00
|
|
|
if ( this._observer ) {
|
|
|
|
|
|
|
|
Path.get( this.path ).setValueFrom( this.object, this.value );
|
2014-08-15 22:04:51 +00:00
|
|
|
|
2014-08-21 17:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.update();
|
2014-08-15 16:32:49 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2014-08-21 17:20:06 +00:00
|
|
|
// Helpers
|
2014-08-15 16:32:49 +00:00
|
|
|
// -------------------------------
|
|
|
|
|
2014-08-21 17:20:06 +00:00
|
|
|
map: function( x, a, b, c, d ) {
|
|
|
|
return ( x - a ) / ( b - a ) * ( d - c ) + c;
|
|
|
|
},
|
2014-08-15 16:32:49 +00:00
|
|
|
|
|
|
|
|
2014-08-21 17:20:06 +00:00
|
|
|
// Legacy
|
|
|
|
// -------------------------------
|
2014-08-15 16:32:49 +00:00
|
|
|
|
2014-08-21 17:20:06 +00:00
|
|
|
listen: function() {
|
2014-08-15 16:32:49 +00:00
|
|
|
|
2014-08-23 07:05:22 +00:00
|
|
|
Gui.warn( 'controller.listen() is deprecated. All controllers are listened for free.' );
|
2014-08-21 17:20:06 +00:00
|
|
|
return this;
|
2014-08-15 16:32:49 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-08-21 17:20:06 +00:00
|
|
|
getValue: function() {
|
2014-08-15 16:32:49 +00:00
|
|
|
|
2014-08-21 17:20:06 +00:00
|
|
|
return this.value;
|
2014-08-15 16:32:49 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-08-21 17:20:06 +00:00
|
|
|
setValue: function( v ) {
|
2014-08-15 16:32:49 +00:00
|
|
|
|
2014-08-21 17:20:06 +00:00
|
|
|
this.value = v;
|
2014-08-15 16:32:49 +00:00
|
|
|
|
|
|
|
}
|
2014-08-21 17:20:06 +00:00
|
|
|
|
2014-08-15 16:32:49 +00:00
|
|
|
|
|
|
|
});
|