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

77 lines
1.1 KiB
JavaScript
Raw Permalink 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-09 19:53:30 +00:00
Polymer( 'dat-gui-option', {
2014-09-07 20:18:36 +00:00
2014-09-07 23:55:40 +00:00
key: null,
2014-09-07 20:18:36 +00:00
ready: function() {
2014-09-07 20:18:36 +00:00
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 {
2014-09-07 20:18:36 +00:00
this.options = options;
}
},
2014-09-16 03:44:07 +00:00
// Return a valid JSON representation of value
serialize: function() {
return JSON.stringify( this.key );
},
// Parse and set JSON representation of value;
unserialize: function( obj ) {
this.value = this.options[ JSON.parse( obj ) ];
},
2014-09-07 23:55:40 +00:00
valueChanged: function() {
2014-09-07 23:55:40 +00:00
for ( var i in this.options ) {
if ( this.options[ i ] === this.value ) {
this.key = i;
break;
}
}
this.super();
2014-09-07 23:55:40 +00:00
},
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 ) {
2014-09-08 01:31:51 +00:00
return Object.keys( object );
2014-09-08 01:31:51 +00:00
}
2014-09-07 20:18:36 +00:00
}
2014-09-07 20:18:36 +00:00
2014-09-08 01:38:29 +00:00
} );