2014-09-04 04:14:36 +00:00
|
|
|
/* globals Gui, Polymer, PathObserver */
|
2014-09-08 01:27:32 +00:00
|
|
|
|
2014-09-09 19:53:30 +00:00
|
|
|
Polymer( 'dat-gui-base', {
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
ready: function() {
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
this.update();
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
},
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-16 03:44:07 +00:00
|
|
|
|
|
|
|
// Overrides
|
|
|
|
// -------------------------------
|
|
|
|
|
|
|
|
// Update the UI
|
2014-09-08 01:31:51 +00:00
|
|
|
update: function() {},
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-16 03:44:07 +00:00
|
|
|
// Process arguments from gui.add
|
2014-09-08 01:31:51 +00:00
|
|
|
init: function() {},
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-16 03:44:07 +00:00
|
|
|
// Return a valid JSON representation of value
|
|
|
|
serialize: function() {
|
|
|
|
|
|
|
|
return JSON.stringify( this.value );
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
// Parse and set JSON representation of value;
|
|
|
|
unserialize: function( obj ) {
|
|
|
|
|
|
|
|
this.value = JSON.parse( obj );
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
// Observers
|
|
|
|
// -------------------------------
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-16 03:44:07 +00:00
|
|
|
ignore: function() {
|
|
|
|
|
|
|
|
// todo: makes the data binding one way
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
watch: function( object, path ) {
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
this.object = object;
|
|
|
|
this.path = path;
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 02:43:10 +00:00
|
|
|
this.bind( 'value', new PathObserver( this.object, this.path ) );
|
2014-08-15 16:32:49 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
},
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
valueChanged: function() {
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-10-11 19:39:16 +00:00
|
|
|
if ( this.__firstChange ) {
|
|
|
|
this.fire( 'change', this.value );
|
|
|
|
}
|
|
|
|
this.__firstChange = true;
|
|
|
|
|
2014-09-08 02:43:10 +00:00
|
|
|
this.update();
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
},
|
2014-08-27 00:01:15 +00:00
|
|
|
|
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
// Helpers
|
|
|
|
// -------------------------------
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
on: function( event, listener ) {
|
2014-09-16 03:44:07 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
this.addEventListener( event, listener );
|
|
|
|
return this;
|
2014-09-16 03:44:07 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
},
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
map: function( x, a, b, c, d ) {
|
2014-09-16 03:44:07 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
return ( x - a ) / ( b - a ) * ( d - c ) + c;
|
2014-09-16 03:44:07 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
},
|
2014-09-15 02:48:00 +00:00
|
|
|
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
// Legacy
|
|
|
|
// -------------------------------
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
listen: function() {
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 03:36:20 +00:00
|
|
|
Gui.warn( 'controller.listen() is deprecated. All controllers are listened for free.' );
|
2014-09-15 02:48:00 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
return this;
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
},
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
getValue: function() {
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
return this.value;
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
},
|
2014-09-07 20:18:36 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
setValue: function( v ) {
|
2014-09-07 20:18:36 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
this.value = v;
|
|
|
|
return this;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
onChange: function( v ) {
|
|
|
|
|
2014-10-11 19:39:16 +00:00
|
|
|
var _this = this;
|
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
this.addEventListener( 'change', function( e ) {
|
2014-09-15 02:48:00 +00:00
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
v( e.detail );
|
|
|
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-09-16 03:44:07 +00:00
|
|
|
onFinishChange: function( v ) {
|
|
|
|
|
|
|
|
return this.onChange( v );
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-10-11 19:39:16 +00:00
|
|
|
disable: function( disabled ) {
|
|
|
|
|
|
|
|
if ( disabled === undefined ) {
|
|
|
|
disabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.row.disabled = disabled;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-09-08 01:31:51 +00:00
|
|
|
} );
|