2011-11-07 21:29:37 +00:00
|
|
|
/**
|
|
|
|
* dat-gui JavaScript Controller Library
|
|
|
|
* http://code.google.com/p/dat-gui
|
|
|
|
*
|
|
|
|
* Copyright 2011 Data Arts Team, Google Creative Lab
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*/
|
|
|
|
|
2015-08-14 13:24:30 +00:00
|
|
|
var OptionController = require('./OptionController'),
|
|
|
|
NumberControllerBox = require('./NumberControllerBox'),
|
|
|
|
NumberControllerSlider = require('./NumberControllerSlider'),
|
|
|
|
StringController = require('./StringController'),
|
|
|
|
FunctionController = require('./FunctionController'),
|
|
|
|
BooleanController = require('./BooleanController'),
|
|
|
|
common = require('../utils/common');
|
2011-11-07 21:29:37 +00:00
|
|
|
|
2015-08-14 13:48:40 +00:00
|
|
|
module.exports = function (object, property) {
|
2011-11-07 21:29:37 +00:00
|
|
|
|
2015-08-14 13:48:40 +00:00
|
|
|
var initialValue = object[property];
|
2011-11-07 21:29:37 +00:00
|
|
|
|
2015-08-14 13:48:40 +00:00
|
|
|
// Providing options?
|
|
|
|
if (common.isArray(arguments[2]) || common.isObject(arguments[2])) {
|
|
|
|
return new OptionController(object, property, arguments[2]);
|
|
|
|
}
|
2011-11-07 21:29:37 +00:00
|
|
|
|
2015-08-14 13:48:40 +00:00
|
|
|
// Providing a map?
|
2011-11-07 21:29:37 +00:00
|
|
|
|
2015-08-14 13:48:40 +00:00
|
|
|
if (common.isNumber(initialValue)) {
|
2011-11-07 21:29:37 +00:00
|
|
|
|
2015-08-14 13:48:40 +00:00
|
|
|
if (common.isNumber(arguments[2]) && common.isNumber(arguments[3])) {
|
2011-11-07 21:29:37 +00:00
|
|
|
|
|
|
|
// Has min and max.
|
2014-06-27 12:19:25 +00:00
|
|
|
if (common.isNumber(arguments[4])) // has step
|
|
|
|
return new NumberControllerSlider(object, property, arguments[2], arguments[3], arguments[4]);
|
|
|
|
else
|
|
|
|
return new NumberControllerSlider(object, property, arguments[2], arguments[3]);
|
2011-11-07 21:29:37 +00:00
|
|
|
|
2015-08-14 13:48:40 +00:00
|
|
|
} else {
|
2011-11-07 21:29:37 +00:00
|
|
|
|
2015-08-14 13:48:40 +00:00
|
|
|
return new NumberControllerBox(object, property, {min: arguments[2], max: arguments[3]});
|
2011-11-07 21:29:37 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-14 13:24:30 +00:00
|
|
|
}
|
2011-11-07 21:29:37 +00:00
|
|
|
|
2015-08-14 13:48:40 +00:00
|
|
|
if (common.isString(initialValue)) {
|
|
|
|
return new StringController(object, property);
|
|
|
|
}
|
2011-11-07 21:29:37 +00:00
|
|
|
|
2015-08-14 13:48:40 +00:00
|
|
|
if (common.isFunction(initialValue)) {
|
|
|
|
return new FunctionController(object, property, '');
|
|
|
|
}
|
2011-11-07 21:29:37 +00:00
|
|
|
|
2015-08-14 13:48:40 +00:00
|
|
|
if (common.isBoolean(initialValue)) {
|
|
|
|
return new BooleanController(object, property);
|
|
|
|
}
|
2011-11-07 21:29:37 +00:00
|
|
|
|
2015-08-14 13:24:30 +00:00
|
|
|
};
|