mirror of
https://github.com/dataarts/dat.gui.git
synced 2024-12-12 04:08:27 +00:00
Fixed eslint issues
This commit is contained in:
parent
6c7bb46b69
commit
963154824e
@ -21,7 +21,6 @@ import BooleanController from '../controllers/BooleanController';
|
|||||||
import FunctionController from '../controllers/FunctionController';
|
import FunctionController from '../controllers/FunctionController';
|
||||||
import NumberControllerBox from '../controllers/NumberControllerBox';
|
import NumberControllerBox from '../controllers/NumberControllerBox';
|
||||||
import NumberControllerSlider from '../controllers/NumberControllerSlider';
|
import NumberControllerSlider from '../controllers/NumberControllerSlider';
|
||||||
import OptionController from '../controllers/OptionController';
|
|
||||||
import ColorController from '../controllers/ColorController';
|
import ColorController from '../controllers/ColorController';
|
||||||
import requestAnimationFrame from '../utils/requestAnimationFrame';
|
import requestAnimationFrame from '../utils/requestAnimationFrame';
|
||||||
import CenteredDiv from '../dom/CenteredDiv';
|
import CenteredDiv from '../dom/CenteredDiv';
|
||||||
@ -31,36 +30,36 @@ import common from '../utils/common';
|
|||||||
css.inject(styleSheet);
|
css.inject(styleSheet);
|
||||||
|
|
||||||
/** Outer-most className for GUI's */
|
/** Outer-most className for GUI's */
|
||||||
var CSS_NAMESPACE = 'dg';
|
const CSS_NAMESPACE = 'dg';
|
||||||
|
|
||||||
var HIDE_KEY_CODE = 72;
|
const HIDE_KEY_CODE = 72;
|
||||||
|
|
||||||
/** The only value shared between the JS and SCSS. Use caution. */
|
/** The only value shared between the JS and SCSS. Use caution. */
|
||||||
var CLOSE_BUTTON_HEIGHT = 20;
|
const CLOSE_BUTTON_HEIGHT = 20;
|
||||||
|
|
||||||
var DEFAULT_DEFAULT_PRESET_NAME = 'Default';
|
const DEFAULT_DEFAULT_PRESET_NAME = 'Default';
|
||||||
|
|
||||||
var SUPPORTS_LOCAL_STORAGE = (function() {
|
const SUPPORTS_LOCAL_STORAGE = (function() {
|
||||||
try {
|
try {
|
||||||
return 'localStorage' in window && window['localStorage'] !== null;
|
return 'localStorage' in window && window.localStorage !== null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
var SAVE_DIALOGUE;
|
let SAVE_DIALOGUE;
|
||||||
|
|
||||||
/** Have we yet to create an autoPlace GUI? */
|
/** Have we yet to create an autoPlace GUI? */
|
||||||
var auto_place_virgin = true;
|
let autoPlaceVirgin = true;
|
||||||
|
|
||||||
/** Fixed position div that auto place GUI's go inside */
|
/** Fixed position div that auto place GUI's go inside */
|
||||||
var auto_place_container;
|
let autoPlaceContainer;
|
||||||
|
|
||||||
/** Are we hiding the GUI's ? */
|
/** Are we hiding the GUI's ? */
|
||||||
var hide = false;
|
let hide = false;
|
||||||
|
|
||||||
/** GUI's which should be hidden */
|
/** GUI's which should be hidden */
|
||||||
var hideable_guis = [];
|
const hideableGuis = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A lightweight controller library for JavaScript. It allows you to easily
|
* A lightweight controller library for JavaScript. It allows you to easily
|
||||||
@ -77,8 +76,10 @@ var hideable_guis = [];
|
|||||||
* @param {dat.gui.GUI} [params.parent] The GUI I'm nested in.
|
* @param {dat.gui.GUI} [params.parent] The GUI I'm nested in.
|
||||||
* @param {Boolean} [params.closed] If true, starts closed
|
* @param {Boolean} [params.closed] If true, starts closed
|
||||||
*/
|
*/
|
||||||
var GUI = function(params) {
|
const GUI = function(pars) {
|
||||||
var _this = this;
|
const _this = this;
|
||||||
|
|
||||||
|
let params = pars || {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Outermost DOM Element
|
* Outermost DOM Element
|
||||||
@ -126,8 +127,6 @@ var GUI = function(params) {
|
|||||||
|
|
||||||
this.__listening = [];
|
this.__listening = [];
|
||||||
|
|
||||||
params = params || {};
|
|
||||||
|
|
||||||
// Default parameters
|
// Default parameters
|
||||||
params = common.defaults(params, {
|
params = common.defaults(params, {
|
||||||
autoPlace: true,
|
autoPlace: true,
|
||||||
@ -149,7 +148,7 @@ var GUI = function(params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (common.isUndefined(params.parent) && params.hideable) {
|
if (common.isUndefined(params.parent) && params.hideable) {
|
||||||
hideable_guis.push(this);
|
hideableGuis.push(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only root level GUI's are resizable.
|
// Only root level GUI's are resizable.
|
||||||
@ -162,11 +161,11 @@ var GUI = function(params) {
|
|||||||
|
|
||||||
// Not part of params because I don't want people passing this in via
|
// Not part of params because I don't want people passing this in via
|
||||||
// constructor. Should be a 'remembered' value.
|
// constructor. Should be a 'remembered' value.
|
||||||
var use_local_storage =
|
let useLocalStorage =
|
||||||
SUPPORTS_LOCAL_STORAGE &&
|
SUPPORTS_LOCAL_STORAGE &&
|
||||||
localStorage.getItem(getLocalStorageHash(this, 'isLocal')) === 'true';
|
localStorage.getItem(getLocalStorageHash(this, 'isLocal')) === 'true';
|
||||||
|
|
||||||
var saveToLocalStorage;
|
let saveToLocalStorage;
|
||||||
|
|
||||||
Object.defineProperties(this,
|
Object.defineProperties(this,
|
||||||
/** @lends dat.gui.GUI.prototype */
|
/** @lends dat.gui.GUI.prototype */
|
||||||
@ -205,9 +204,9 @@ var GUI = function(params) {
|
|||||||
get: function() {
|
get: function() {
|
||||||
if (_this.parent) {
|
if (_this.parent) {
|
||||||
return _this.getRoot().preset;
|
return _this.getRoot().preset;
|
||||||
} else {
|
|
||||||
return params.load.preset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return params.load.preset;
|
||||||
},
|
},
|
||||||
|
|
||||||
set: function(v) {
|
set: function(v) {
|
||||||
@ -247,8 +246,8 @@ var GUI = function(params) {
|
|||||||
set: function(v) {
|
set: function(v) {
|
||||||
// TODO Check for collisions among sibling folders
|
// TODO Check for collisions among sibling folders
|
||||||
params.name = v;
|
params.name = v;
|
||||||
if (title_row_name) {
|
if (titleRowName) {
|
||||||
title_row_name.innerHTML = params.name;
|
titleRowName.innerHTML = params.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -297,11 +296,11 @@ var GUI = function(params) {
|
|||||||
useLocalStorage: {
|
useLocalStorage: {
|
||||||
|
|
||||||
get: function() {
|
get: function() {
|
||||||
return use_local_storage;
|
return useLocalStorage;
|
||||||
},
|
},
|
||||||
set: function(bool) {
|
set: function(bool) {
|
||||||
if (SUPPORTS_LOCAL_STORAGE) {
|
if (SUPPORTS_LOCAL_STORAGE) {
|
||||||
use_local_storage = bool;
|
useLocalStorage = bool;
|
||||||
if (bool) {
|
if (bool) {
|
||||||
dom.bind(window, 'unload', saveToLocalStorage);
|
dom.bind(window, 'unload', saveToLocalStorage);
|
||||||
} else {
|
} else {
|
||||||
@ -315,7 +314,6 @@ var GUI = function(params) {
|
|||||||
|
|
||||||
// Are we a root level GUI?
|
// Are we a root level GUI?
|
||||||
if (common.isUndefined(params.parent)) {
|
if (common.isUndefined(params.parent)) {
|
||||||
|
|
||||||
params.closed = false;
|
params.closed = false;
|
||||||
|
|
||||||
dom.addClass(this.domElement, GUI.CLASS_MAIN);
|
dom.addClass(this.domElement, GUI.CLASS_MAIN);
|
||||||
@ -323,13 +321,13 @@ var GUI = function(params) {
|
|||||||
|
|
||||||
// Are we supposed to be loading locally?
|
// Are we supposed to be loading locally?
|
||||||
if (SUPPORTS_LOCAL_STORAGE) {
|
if (SUPPORTS_LOCAL_STORAGE) {
|
||||||
if (use_local_storage) {
|
if (useLocalStorage) {
|
||||||
_this.useLocalStorage = true;
|
_this.useLocalStorage = true;
|
||||||
|
|
||||||
var saved_gui = localStorage.getItem(getLocalStorageHash(this, 'gui'));
|
const savedGui = localStorage.getItem(getLocalStorageHash(this, 'gui'));
|
||||||
|
|
||||||
if (saved_gui) {
|
if (savedGui) {
|
||||||
params.load = JSON.parse(saved_gui);
|
params.load = JSON.parse(savedGui);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -348,12 +346,12 @@ var GUI = function(params) {
|
|||||||
params.closed = true;
|
params.closed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var title_row_name = document.createTextNode(params.name);
|
const titleRowName = document.createTextNode(params.name);
|
||||||
dom.addClass(title_row_name, 'controller-name');
|
dom.addClass(titleRowName, 'controller-name');
|
||||||
|
|
||||||
var title_row = addRow(_this, title_row_name);
|
const titleRow = addRow(_this, titleRowName);
|
||||||
|
|
||||||
var on_click_title = function(e) {
|
const onClickTitle = function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
_this.closed = !_this.closed;
|
_this.closed = !_this.closed;
|
||||||
return false;
|
return false;
|
||||||
@ -361,8 +359,8 @@ var GUI = function(params) {
|
|||||||
|
|
||||||
dom.addClass(this.__ul, GUI.CLASS_CLOSED);
|
dom.addClass(this.__ul, GUI.CLASS_CLOSED);
|
||||||
|
|
||||||
dom.addClass(title_row, 'title');
|
dom.addClass(titleRow, 'title');
|
||||||
dom.bind(title_row, 'click', on_click_title);
|
dom.bind(titleRow, 'click', onClickTitle);
|
||||||
|
|
||||||
if (!params.closed) {
|
if (!params.closed) {
|
||||||
this.closed = false;
|
this.closed = false;
|
||||||
@ -371,16 +369,16 @@ var GUI = function(params) {
|
|||||||
|
|
||||||
if (params.autoPlace) {
|
if (params.autoPlace) {
|
||||||
if (common.isUndefined(params.parent)) {
|
if (common.isUndefined(params.parent)) {
|
||||||
if (auto_place_virgin) {
|
if (autoPlaceVirgin) {
|
||||||
auto_place_container = document.createElement('div');
|
autoPlaceContainer = document.createElement('div');
|
||||||
dom.addClass(auto_place_container, CSS_NAMESPACE);
|
dom.addClass(autoPlaceContainer, CSS_NAMESPACE);
|
||||||
dom.addClass(auto_place_container, GUI.CLASS_AUTO_PLACE_CONTAINER);
|
dom.addClass(autoPlaceContainer, GUI.CLASS_AUTO_PLACE_CONTAINER);
|
||||||
document.body.appendChild(auto_place_container);
|
document.body.appendChild(autoPlaceContainer);
|
||||||
auto_place_virgin = false;
|
autoPlaceVirgin = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put it in the dom for you.
|
// Put it in the dom for you.
|
||||||
auto_place_container.appendChild(this.domElement);
|
autoPlaceContainer.appendChild(this.domElement);
|
||||||
|
|
||||||
// Apply the auto styles
|
// Apply the auto styles
|
||||||
dom.addClass(this.domElement, GUI.CLASS_AUTO_PLACE);
|
dom.addClass(this.domElement, GUI.CLASS_AUTO_PLACE);
|
||||||
@ -394,16 +392,16 @@ var GUI = function(params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dom.bind(window, 'resize', function() {
|
dom.bind(window, 'resize', function() {
|
||||||
_this.onResize()
|
_this.onResize();
|
||||||
});
|
});
|
||||||
dom.bind(this.__ul, 'webkitTransitionEnd', function() {
|
dom.bind(this.__ul, 'webkitTransitionEnd', function() {
|
||||||
_this.onResize();
|
_this.onResize();
|
||||||
});
|
});
|
||||||
dom.bind(this.__ul, 'transitionend', function() {
|
dom.bind(this.__ul, 'transitionend', function() {
|
||||||
_this.onResize()
|
_this.onResize();
|
||||||
});
|
});
|
||||||
dom.bind(this.__ul, 'oTransitionEnd', function() {
|
dom.bind(this.__ul, 'oTransitionEnd', function() {
|
||||||
_this.onResize()
|
_this.onResize();
|
||||||
});
|
});
|
||||||
this.onResize();
|
this.onResize();
|
||||||
|
|
||||||
@ -420,10 +418,8 @@ var GUI = function(params) {
|
|||||||
// expose this method publicly
|
// expose this method publicly
|
||||||
this.saveToLocalStorageIfPossible = saveToLocalStorage;
|
this.saveToLocalStorageIfPossible = saveToLocalStorage;
|
||||||
|
|
||||||
var root = _this.getRoot();
|
|
||||||
|
|
||||||
function resetWidth() {
|
function resetWidth() {
|
||||||
var root = _this.getRoot();
|
const root = _this.getRoot();
|
||||||
root.width += 1;
|
root.width += 1;
|
||||||
common.defer(function() {
|
common.defer(function() {
|
||||||
root.width -= 1;
|
root.width -= 1;
|
||||||
@ -437,7 +433,7 @@ var GUI = function(params) {
|
|||||||
|
|
||||||
GUI.toggleHide = function() {
|
GUI.toggleHide = function() {
|
||||||
hide = !hide;
|
hide = !hide;
|
||||||
common.each(hideable_guis, function(gui) {
|
common.each(hideableGuis, function(gui) {
|
||||||
gui.domElement.style.zIndex = hide ? -999 : 999;
|
gui.domElement.style.zIndex = hide ? -999 : 999;
|
||||||
gui.domElement.style.opacity = hide ? 0 : 1;
|
gui.domElement.style.opacity = hide ? 0 : 1;
|
||||||
});
|
});
|
||||||
@ -458,7 +454,7 @@ GUI.TEXT_OPEN = 'Open Controls';
|
|||||||
|
|
||||||
dom.bind(window, 'keydown', function(e) {
|
dom.bind(window, 'keydown', function(e) {
|
||||||
if (document.activeElement.type !== 'text' &&
|
if (document.activeElement.type !== 'text' &&
|
||||||
(e.which === HIDE_KEY_CODE || e.keyCode == HIDE_KEY_CODE)) {
|
(e.which === HIDE_KEY_CODE || e.keyCode === HIDE_KEY_CODE)) {
|
||||||
GUI.toggleHide();
|
GUI.toggleHide();
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
@ -511,7 +507,7 @@ common.extend(
|
|||||||
// TODO listening?
|
// TODO listening?
|
||||||
this.__ul.removeChild(controller.__li);
|
this.__ul.removeChild(controller.__li);
|
||||||
this.__controllers.splice(this.__controllers.indexOf(controller), 1);
|
this.__controllers.splice(this.__controllers.indexOf(controller), 1);
|
||||||
var _this = this;
|
const _this = this;
|
||||||
common.defer(function() {
|
common.defer(function() {
|
||||||
_this.onResize();
|
_this.onResize();
|
||||||
});
|
});
|
||||||
@ -519,7 +515,7 @@ common.extend(
|
|||||||
|
|
||||||
destroy: function() {
|
destroy: function() {
|
||||||
if (this.autoPlace) {
|
if (this.autoPlace) {
|
||||||
auto_place_container.removeChild(this.domElement);
|
autoPlaceContainer.removeChild(this.domElement);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -538,12 +534,12 @@ common.extend(
|
|||||||
' name "' + name + '"');
|
' name "' + name + '"');
|
||||||
}
|
}
|
||||||
|
|
||||||
var new_gui_params = {name: name, parent: this};
|
const newGuiParams = {name: name, parent: this};
|
||||||
|
|
||||||
// We need to pass down the autoPlace trait so that we can
|
// We need to pass down the autoPlace trait so that we can
|
||||||
// attach event listeners to open/close folder actions to
|
// attach event listeners to open/close folder actions to
|
||||||
// ensure that a scrollbar appears if the window is too short.
|
// ensure that a scrollbar appears if the window is too short.
|
||||||
new_gui_params.autoPlace = this.autoPlace;
|
newGuiParams.autoPlace = this.autoPlace;
|
||||||
|
|
||||||
// Do we have saved appearance data for this folder?
|
// Do we have saved appearance data for this folder?
|
||||||
|
|
||||||
@ -552,17 +548,16 @@ common.extend(
|
|||||||
this.load.folders[name]) { // Did daddy remember me?
|
this.load.folders[name]) { // Did daddy remember me?
|
||||||
|
|
||||||
// Start me closed if I was closed
|
// Start me closed if I was closed
|
||||||
new_gui_params.closed = this.load.folders[name].closed;
|
newGuiParams.closed = this.load.folders[name].closed;
|
||||||
|
|
||||||
// Pass down the loaded data
|
// Pass down the loaded data
|
||||||
new_gui_params.load = this.load.folders[name];
|
newGuiParams.load = this.load.folders[name];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var gui = new GUI(new_gui_params);
|
const gui = new GUI(newGuiParams);
|
||||||
this.__folders[name] = gui;
|
this.__folders[name] = gui;
|
||||||
|
|
||||||
var li = addRow(this, gui.domElement);
|
const li = addRow(this, gui.domElement);
|
||||||
dom.addClass(li, 'folder');
|
dom.addClass(li, 'folder');
|
||||||
return gui;
|
return gui;
|
||||||
},
|
},
|
||||||
@ -576,14 +571,15 @@ common.extend(
|
|||||||
},
|
},
|
||||||
|
|
||||||
onResize: function() {
|
onResize: function() {
|
||||||
var root = this.getRoot();
|
const root = this.getRoot();
|
||||||
if (root.scrollable) {
|
if (root.scrollable) {
|
||||||
var top = dom.getOffset(root.__ul).top;
|
const top = dom.getOffset(root.__ul).top;
|
||||||
var h = 0;
|
let h = 0;
|
||||||
|
|
||||||
common.each(root.__ul.childNodes, function(node) {
|
common.each(root.__ul.childNodes, function(node) {
|
||||||
if (!(root.autoPlace && node === root.__save_row))
|
if (!(root.autoPlace && node === root.__save_row)) {
|
||||||
h += dom.getHeight(node);
|
h += dom.getHeight(node);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (window.innerHeight - top - CLOSE_BUTTON_HEIGHT < h) {
|
if (window.innerHeight - top - CLOSE_BUTTON_HEIGHT < h) {
|
||||||
@ -622,16 +618,16 @@ common.extend(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.parent) {
|
if (this.parent) {
|
||||||
throw new Error("You can only call remember on a top level GUI.");
|
throw new Error('You can only call remember on a top level GUI.');
|
||||||
}
|
}
|
||||||
|
|
||||||
var _this = this;
|
const _this = this;
|
||||||
|
|
||||||
common.each(Array.prototype.slice.call(arguments), function(object) {
|
common.each(Array.prototype.slice.call(arguments), function(object) {
|
||||||
if (_this.__rememberedObjects.length == 0) {
|
if (_this.__rememberedObjects.length === 0) {
|
||||||
addSaveMenu(_this);
|
addSaveMenu(_this);
|
||||||
}
|
}
|
||||||
if (_this.__rememberedObjects.indexOf(object) == -1) {
|
if (_this.__rememberedObjects.indexOf(object) === -1) {
|
||||||
_this.__rememberedObjects.push(object);
|
_this.__rememberedObjects.push(object);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -647,7 +643,7 @@ common.extend(
|
|||||||
* @instance
|
* @instance
|
||||||
*/
|
*/
|
||||||
getRoot: function() {
|
getRoot: function() {
|
||||||
var gui = this;
|
let gui = this;
|
||||||
while (gui.parent) {
|
while (gui.parent) {
|
||||||
gui = gui.parent;
|
gui = gui.parent;
|
||||||
}
|
}
|
||||||
@ -660,7 +656,7 @@ common.extend(
|
|||||||
* @instance
|
* @instance
|
||||||
*/
|
*/
|
||||||
getSaveObject: function() {
|
getSaveObject: function() {
|
||||||
var toReturn = this.load;
|
const toReturn = this.load;
|
||||||
toReturn.closed = this.closed;
|
toReturn.closed = this.closed;
|
||||||
|
|
||||||
// Am I remembering any values?
|
// Am I remembering any values?
|
||||||
@ -725,9 +721,11 @@ common.extend(
|
|||||||
},
|
},
|
||||||
|
|
||||||
listen: function(controller) {
|
listen: function(controller) {
|
||||||
var init = this.__listening.length == 0;
|
const init = this.__listening.length === 0;
|
||||||
this.__listening.push(controller);
|
this.__listening.push(controller);
|
||||||
if (init) updateDisplays(this.__listening);
|
if (init) {
|
||||||
|
updateDisplays(this.__listening);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -1008,7 +1006,7 @@ function addPresetOption(gui, name, setSelected) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function showHideExplain(explain) {
|
function showHideExplain(gui, explain) {
|
||||||
explain.style.display = gui.useLocalStorage ? 'block' : 'none';
|
explain.style.display = gui.useLocalStorage ? 'block' : 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1076,12 +1074,12 @@ function addSaveMenu(gui) {
|
|||||||
localStorageCheckBox.setAttribute('checked', 'checked');
|
localStorageCheckBox.setAttribute('checked', 'checked');
|
||||||
}
|
}
|
||||||
|
|
||||||
showHideExplain(explain);
|
showHideExplain(gui, explain);
|
||||||
|
|
||||||
// TODO: Use a boolean controller, fool!
|
// TODO: Use a boolean controller, fool!
|
||||||
dom.bind(localStorageCheckBox, 'change', function() {
|
dom.bind(localStorageCheckBox, 'change', function() {
|
||||||
gui.useLocalStorage = !gui.useLocalStorage;
|
gui.useLocalStorage = !gui.useLocalStorage;
|
||||||
showHideExplain(explain);
|
showHideExplain(gui, explain);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user