dat.gui/elements/gui-panel/gui-panel.js

145 lines
2.7 KiB
JavaScript
Raw Normal View History

2014-09-03 16:16:11 +00:00
// [ ] scrolling when docked
// [ ] scrolling when window short and not docked
2014-08-27 00:01:15 +00:00
Polymer('gui-panel', {
docked: false,
open: true,
touch: ('ontouchstart' in window) ||
(!!window.DocumentTouch && document instanceof DocumentTouch),
2014-08-27 00:01:15 +00:00
ready: function() {
2014-08-27 00:01:15 +00:00
this.anon.values = {};
2014-08-27 00:01:15 +00:00
// window.addEventListener( 'resize', this.checkHeight.bind( this));
2014-08-27 00:01:15 +00:00
},
2014-08-27 00:01:15 +00:00
anon: function() {
2014-08-27 00:01:15 +00:00
if (arguments.length == 1) {
var name = arguments[0];
return this.anon.values[name];
}
2014-08-27 00:01:15 +00:00
var initialValue = arguments[0];
var name = arguments[1];
2014-08-27 00:01:15 +00:00
var args = [this.anon.values, name];
args = args.concat(Array.prototype.slice.call(arguments, 2));
2014-08-27 00:01:15 +00:00
this.anon.values[name] = initialValue;
2014-08-27 00:01:15 +00:00
return this.add.apply(this, args);
2014-08-27 00:01:15 +00:00
},
2014-08-27 00:01:15 +00:00
add: function(object, path) {
2014-08-27 00:01:15 +00:00
// Make controller
2014-08-27 00:01:15 +00:00
var value = Path.get(path).getValueFrom(object);
2014-08-27 00:01:15 +00:00
if (value == null || value == undefined) {
return Gui.error(object +
' doesn\'t have a value for path "' + path + '".');
}
2014-08-27 00:01:15 +00:00
var args = Array.prototype.slice.call(arguments, 2);
2014-08-27 00:01:15 +00:00
var controller = Gui.getController(value, args);
2014-08-27 00:01:15 +00:00
if (!controller) {
return Gui.error('Unrecognized type:', value);
}
2014-08-27 00:01:15 +00:00
controller.watch(object, path);
controller.init.apply(controller, args);
2014-08-27 00:01:15 +00:00
// Make row
2014-08-27 00:01:15 +00:00
var row = document.createElement('gui-row');
row.name = path;
2014-08-27 00:01:15 +00:00
controller.row = row;
2014-08-27 00:01:15 +00:00
controller.name = function(name) {
row.name = name;
};
2014-08-27 00:01:15 +00:00
controller.comment = function(comment) {
row.comment = comment;
};
2014-08-27 00:01:15 +00:00
row.appendChild(controller);
this.appendChild(row);
2014-08-27 00:01:15 +00:00
return controller;
2014-08-27 00:01:15 +00:00
},
2014-08-27 00:01:15 +00:00
// Observers
// -------------------------------
2014-08-27 00:01:15 +00:00
openChanged: function() {
2014-08-27 00:01:15 +00:00
if (this.open || this.docked) {
2014-08-27 00:01:15 +00:00
// let the style sheet take care of things
2014-08-27 00:01:15 +00:00
this.$.container.style.transform = '';
2014-08-27 00:01:15 +00:00
} else {
2014-08-27 00:01:15 +00:00
// todo: need the rest of the vendor prefixes ...
// wish i could pipe javascript variables into styl.
2014-08-27 00:01:15 +00:00
var y = -this.$.controllers.offsetHeight + 'px';
this.$.container.style.transform = 'translate3d(0, ' + y + ', 0)';
2014-08-27 00:01:15 +00:00
}
2014-08-27 00:01:15 +00:00
},
2014-08-27 00:01:15 +00:00
dockedChanged: function() {
2014-08-27 00:01:15 +00:00
this.openChanged();
2014-08-27 00:01:15 +00:00
},
2014-08-27 00:01:15 +00:00
// Events
// -------------------------------
2014-08-27 00:01:15 +00:00
tapClose: function() {
this.open = !this.open;
},
2014-08-27 00:01:15 +00:00
// checkHeight: function() {
2014-08-27 00:01:15 +00:00
// if ( window.innerHeight < this.$.controllers.offsetHeight) {
// this.docked = true;
// } else {
// this.docked = false;
// }
2014-08-27 00:01:15 +00:00
// },
2014-08-27 00:01:15 +00:00
// Legacy
// -------------------------------
listenAll: function() {
Gui.warn('controller.listenAll() is deprecated. ' +
'All controllers are listened for free.');
}
// todo: domElement
});