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

63 lines
919 B
JavaScript
Raw Normal View History

2014-09-08 01:31:51 +00:00
/* globals Polymer, Object, Array */
2014-09-08 02:43:10 +00:00
2014-09-08 01:31:51 +00:00
2014-09-07 20:18:36 +00:00
Polymer( 'controller-option', {
2014-09-07 23:55:40 +00:00
key: null,
2014-09-07 20:18:36 +00:00
ready: function() {
this.options = {};
},
init: function( options ) {
2014-09-08 01:31:51 +00:00
if ( Array.isArray( options ) ) {
2014-09-07 20:18:36 +00:00
options.forEach( function( opt ) {
this.options[ opt ] = opt;
}, this );
} else {
this.options = options;
}
},
2014-09-07 23:55:40 +00:00
valueChanged: function() {
for ( var i in this.options ) {
if ( this.options[ i ] === this.value ) {
this.key = i;
break;
}
}
this.super();
},
keyChanged: function() {
this.value = this.options[ this.key ];
},
keys: function( object ) {
2014-09-07 20:18:36 +00:00
2014-09-08 01:31:51 +00:00
if ( object ) {
return Object.keys( object );
}
2014-09-07 20:18:36 +00:00
}
2014-09-08 01:38:29 +00:00
} );