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 15:28:30 +00:00
|
|
|
import Controller from './Controller';
|
|
|
|
import dom from '../dom/dom';
|
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
|
|
|
|
*/
|
2015-08-14 22:16:18 +00:00
|
|
|
class FunctionController extends Controller {
|
2015-08-14 16:27:54 +00:00
|
|
|
constructor(object, property, text) {
|
|
|
|
super(object, property);
|
2011-11-07 21:29:37 +00:00
|
|
|
|
2015-08-14 22:16:18 +00:00
|
|
|
const _this = this;
|
2011-11-07 21:29:37 +00:00
|
|
|
|
|
|
|
this.__button = document.createElement('div');
|
|
|
|
this.__button.innerHTML = text === undefined ? 'Fire' : text;
|
2015-08-14 20:29:30 +00:00
|
|
|
|
2015-08-14 22:16:18 +00:00
|
|
|
dom.bind(this.__button, 'click', function(e) {
|
2015-08-14 16:27:54 +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 16:27:54 +00:00
|
|
|
}
|
2011-11-07 21:29:37 +00:00
|
|
|
|
2015-08-14 16:27:54 +00:00
|
|
|
fire() {
|
|
|
|
if (this.__onChange) {
|
|
|
|
this.__onChange.call(this);
|
2015-08-14 13:24:30 +00:00
|
|
|
}
|
2015-08-14 16:27:54 +00:00
|
|
|
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 22:16:18 +00:00
|
|
|
export default FunctionController;
|