mirror of
https://github.com/dataarts/dat.gui.git
synced 2024-12-12 04:08:27 +00:00
72 lines
1.7 KiB
JavaScript
72 lines
1.7 KiB
JavaScript
|
/**
|
||
|
* 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
|
||
|
*/
|
||
|
|
||
|
define([
|
||
|
'dat/controllers/Controller',
|
||
|
'dat/dom/dom',
|
||
|
'dat/utils/common'
|
||
|
], function(Controller, dom, common) {
|
||
|
|
||
|
/**
|
||
|
* @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) {
|
||
|
|
||
|
FunctionController.superclass.call(this, object, property);
|
||
|
|
||
|
var _this = this;
|
||
|
|
||
|
this.__button = document.createElement('div');
|
||
|
this.__button.innerHTML = text === undefined ? 'Fire' : text;
|
||
|
dom.bind(this.__button, 'click', function() {
|
||
|
_this.fire();
|
||
|
});
|
||
|
|
||
|
dom.addClass(this.__button, 'button');
|
||
|
|
||
|
this.domElement.appendChild(this.__button);
|
||
|
|
||
|
|
||
|
};
|
||
|
|
||
|
FunctionController.superclass = Controller;
|
||
|
|
||
|
common.extend(
|
||
|
|
||
|
FunctionController.prototype,
|
||
|
Controller.prototype,
|
||
|
{
|
||
|
|
||
|
fire: function() {
|
||
|
if (this.__onChange) {
|
||
|
this.__onChange.call(this);
|
||
|
}
|
||
|
if (this.__onFinishChange) {
|
||
|
this.__onFinishChange.call(this, this.getValue());
|
||
|
}
|
||
|
this.getValue().call(this.object);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
);
|
||
|
|
||
|
return FunctionController;
|
||
|
|
||
|
});
|