2014-09-04 04:14:36 +00:00
|
|
|
/* globals Gui, Polymer, PathObserver */
|
2014-09-08 01:27:32 +00:00
|
|
|
|
2014-09-04 04:14:36 +00:00
|
|
|
|
2014-08-27 00:01:15 +00:00
|
|
|
/*
|
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
[ ] onChange()
|
|
|
|
[ ] onFinishChange()
|
2014-08-27 00:01:15 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
Polymer('controller-base', {
|
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
ready: function() {
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
this.update();
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
},
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
update: function() {},
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
init: function() {},
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
// Observers
|
|
|
|
// -------------------------------
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
watch: function(object, path) {
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
this.object = object;
|
|
|
|
this.path = path;
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
this.bind('value', new PathObserver(this.object, this.path));
|
2014-08-15 16:32:49 +00:00
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
},
|
2014-09-08 00:22:30 +00:00
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
valueChanged: function() {
|
2014-09-08 00:22:30 +00:00
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
this.update();
|
2014-09-08 00:22:30 +00:00
|
|
|
this.fire( 'change', this.value );
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
},
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
// Helpers
|
|
|
|
// -------------------------------
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 00:22:30 +00:00
|
|
|
on: function( event, listener ) {
|
|
|
|
this.addEventListener( event, listener );
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
map: function(x, a, b, c, d) {
|
|
|
|
return (x - a) / (b - a) * (d - c) + c;
|
|
|
|
},
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
// Legacy
|
|
|
|
// -------------------------------
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
listen: function() {
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
Gui.warn('controller.listen() is deprecated. ' +
|
|
|
|
'All controllers are listened for free.');
|
|
|
|
return this;
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
},
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
getValue: function() {
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
return this.value;
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
},
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
setValue: function(v) {
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
this.value = v;
|
2014-09-08 00:22:30 +00:00
|
|
|
return this;
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 00:22:30 +00:00
|
|
|
},
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-08 00:22:30 +00:00
|
|
|
onChange: function( v ) {
|
2014-09-07 20:18:36 +00:00
|
|
|
|
2014-09-08 00:22:30 +00:00
|
|
|
this.addEventListener( 'change', function( e ) {
|
|
|
|
v( e.detail );
|
|
|
|
} );
|
|
|
|
return this;
|
2014-09-07 20:18:36 +00:00
|
|
|
|
2014-09-08 00:22:30 +00:00
|
|
|
},
|
2014-08-27 00:01:15 +00:00
|
|
|
|
2014-09-03 23:33:28 +00:00
|
|
|
});
|