dat.gui/src/dat/controllers/FunctionController.js

70 lines
1.7 KiB
JavaScript
Raw Normal View History

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 Controller = require('./Controller'),
dom = require('../dom/dom'),
common = require('../utils/common');
2011-11-07 21:29:37 +00:00
2015-08-14 13:24:30 +00:00
/**
* @class Provides a GUI interface to fire a specified method, a property of an object.
*
* @extends dat.controllers.Controller
*
* @param {Object} object The object to be manipulated
* @param {string} property The name of the property to be manipulated
*
* @member dat.controllers
*/
var FunctionController = function(object, property, text) {
2011-11-07 21:29:37 +00:00
FunctionController.superclass.call(this, object, property);
var _this = this;
this.__button = document.createElement('div');
this.__button.innerHTML = text === undefined ? 'Fire' : text;
2011-11-08 03:31:28 +00:00
dom.bind(this.__button, 'click', function(e) {
2015-08-14 13:24:30 +00:00
e.preventDefault();
_this.fire();
return false;
2011-11-07 21:29:37 +00:00
});
dom.addClass(this.__button, 'button');
this.domElement.appendChild(this.__button);
2015-08-14 13:24:30 +00:00
};
FunctionController.superclass = Controller;
2011-11-07 21:29:37 +00:00
2015-08-14 13:24:30 +00:00
common.extend(
2011-11-07 21:29:37 +00:00
2015-08-14 13:24:30 +00:00
FunctionController.prototype,
Controller.prototype,
{
2011-11-07 21:29:37 +00:00
fire: function() {
2015-08-14 13:24:30 +00:00
if (this.__onChange) {
this.__onChange.call(this);
}
this.getValue().call(this.object);
if (this.__onFinishChange) {
this.__onFinishChange.call(this, this.getValue());
}
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:24:30 +00:00
);
2011-11-07 21:29:37 +00:00
2015-08-14 13:24:30 +00:00
module.exports = FunctionController;