diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1e501e3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +bower_components +node_modules \ No newline at end of file diff --git a/elements/base-controller.html b/elements/base-controller.html index 3dd2fc5..13d18e0 100644 --- a/elements/base-controller.html +++ b/elements/base-controller.html @@ -1,66 +1,3 @@ - - - - - - - - - - \ No newline at end of file + + \ No newline at end of file diff --git a/elements/base-controller.js b/elements/base-controller.js new file mode 100644 index 0000000..8f7bc15 --- /dev/null +++ b/elements/base-controller.js @@ -0,0 +1,87 @@ +Polymer('base-controller', { + + value: null, + object: null, + property: null, + + ready: function() { + + var _this = this; + this._observer = function( changes ) { + + changes.forEach( function( c ) { + + if ( c.name == _this.property ) { + _this.value = _this.object[ _this.property ]; + } + + } ); + + }; + + this.update(); + + }, + + + // Observers + // ------------------------------- + + objectChanged: function( oldObject, newObject ) { + + if ( oldObject && this.property ) { + this.unbind( oldObject ); + } + + if ( newObject && this.property ) { + this.bind(); + } + + }, + + propertyChanged: function( oldProperty, newProperty ) { + + if ( oldProperty && this.object ) { + this.unbind( this.object ); + } + + if ( newProperty && this.object ) { + this.bind(); + } + + }, + + valueChanged: function() { + + if ( this.object && this.property ) { + this.object[ this.property ] = this.value; + } + + this.update(); + + }, + + bind: function() { + + Object.observe( this.object, this._observer ); + this.value = this.object[ this.property ]; + + }, + + unbind: function( object ) { + + Object.unobserve( object, this._observer ); + + }, + + update: function() {}, + + + // Helpers + // ------------------------------- + + map: function( x, a, b, c, d ) { + return ( x - a ) / ( b - a ) * ( d - c ) + c; + } + +}); \ No newline at end of file diff --git a/elements/gui-panel.css b/elements/gui-panel.css new file mode 100644 index 0000000..022e7de --- /dev/null +++ b/elements/gui-panel.css @@ -0,0 +1,6 @@ +:host { + position: absolute; + top: 0; + right: 20px; + width: 300px; +} diff --git a/elements/gui-panel.html b/elements/gui-panel.html index cfd4527..ce86945 100644 --- a/elements/gui-panel.html +++ b/elements/gui-panel.html @@ -1,17 +1,12 @@ - +