CustomController

This commit is contained in:
Andrej 2019-05-29 07:37:00 +07:00
parent 880a802483
commit e56ba62d3d
2 changed files with 6 additions and 11 deletions

View File

@ -14,8 +14,7 @@ import Controller from './Controller';
/**
* @class Represents a custom controller.
* @param {Object} object
* @param {string} property
* @param {init} callback function for adding of elements into this.domElement
*/
class CustomController extends Controller{
constructor(init) {

View File

@ -567,13 +567,12 @@ common.extend(
* @instance
*
*/
addCustomController: function(object, property) {
addCustomController: function(init, property) {
return add(
this,
object,
new dat.controllers.CustomController( init ),
property,
{
custom: true,
factoryArgs: Array.prototype.slice.call(arguments, 2)
}
);
@ -1165,9 +1164,7 @@ function add(gui, object, property, params) {
controller = new ColorController(object, property);
} else if(customObject && ( property === undefined )){
controller = object;
} else if (!(customObject) && params.custom && (object[property] === undefined)) {
controller = new CustomController(object, property);
}else {
} else {
const factoryArgs = customObject ?
[property].concat(params.factoryArgs) : [object, property].concat(params.factoryArgs);
controller = ControllerFactory.apply(gui, factoryArgs);
@ -1183,9 +1180,8 @@ function add(gui, object, property, params) {
const container = document.createElement('div');
const name = params.custom && ( controller instanceof CustomController === false ) ?
( customObject ? object.domElement : new CustomController(object).domElement ) : document.createElement('span');
if (!params.custom)
const name = customObject ? object.domElement : document.createElement('span');
if (!customObject)
name.innerHTML = controller.property;
dom.addClass(name, 'property-name');
container.appendChild(name);