Fixed forEach iterator TypeError, made localStorage usage easier and behave closer to expectation.

This commit is contained in:
Drew Lustro 2014-01-23 02:26:25 -05:00
parent fcfe534e5d
commit 4a0ed99a62
3 changed files with 30 additions and 8 deletions

View File

@ -106,8 +106,9 @@ dat.utils.common = (function () {
each: function(obj, itr, scope) { each: function(obj, itr, scope) {
if (!obj) return;
if (ARR_EACH && obj.forEach === ARR_EACH) { if (ARR_EACH && obj.forEach && obj.forEach === ARR_EACH) {
obj.forEach(itr, scope); obj.forEach(itr, scope);
@ -779,6 +780,8 @@ dat.controllers.NumberController = (function (Controller, common) {
*/ */
step: function(v) { step: function(v) {
this.__step = v; this.__step = v;
this.__impliedStep = v;
this.__precision = numDecimals(v);
return this; return this;
} }
@ -1671,6 +1674,8 @@ dat.GUI = dat.gui.GUI = (function (css, saveDialogueContents, styleSheet, contro
SUPPORTS_LOCAL_STORAGE && SUPPORTS_LOCAL_STORAGE &&
localStorage.getItem(getLocalStorageHash(this, 'isLocal')) === 'true'; localStorage.getItem(getLocalStorageHash(this, 'isLocal')) === 'true';
var saveToLocalStorage;
Object.defineProperties(this, Object.defineProperties(this,
/** @lends dat.gui.GUI.prototype */ /** @lends dat.gui.GUI.prototype */
@ -1926,10 +1931,15 @@ dat.GUI = dat.gui.GUI = (function (css, saveDialogueContents, styleSheet, contro
addResizeHandle(this); addResizeHandle(this);
} }
function saveToLocalStorage() { saveToLocalStorage = function () {
localStorage.setItem(getLocalStorageHash(_this, 'gui'), JSON.stringify(_this.getSaveObject())); if (SUPPORTS_LOCAL_STORAGE && localStorage.getItem(getLocalStorageHash(_this, 'isLocal')) === 'true') {
localStorage.setItem(getLocalStorageHash(_this, 'gui'), JSON.stringify(_this.getSaveObject()));
}
} }
// expose this method publicly
this.saveToLocalStorageIfPossible = saveToLocalStorage;
var root = _this.getRoot(); var root = _this.getRoot();
function resetWidth() { function resetWidth() {
var root = _this.getRoot(); var root = _this.getRoot();
@ -2226,6 +2236,7 @@ dat.GUI = dat.gui.GUI = (function (css, saveDialogueContents, styleSheet, contro
this.load.remembered[this.preset] = getCurrentPreset(this); this.load.remembered[this.preset] = getCurrentPreset(this);
markPresetModified(this, false); markPresetModified(this, false);
this.saveToLocalStorageIfPossible();
}, },
@ -2242,6 +2253,7 @@ dat.GUI = dat.gui.GUI = (function (css, saveDialogueContents, styleSheet, contro
this.load.remembered[presetName] = getCurrentPreset(this); this.load.remembered[presetName] = getCurrentPreset(this);
this.preset = presetName; this.preset = presetName;
addPresetOption(this, presetName, true); addPresetOption(this, presetName, true);
this.saveToLocalStorageIfPossible();
}, },

View File

@ -179,6 +179,8 @@ define([
SUPPORTS_LOCAL_STORAGE && SUPPORTS_LOCAL_STORAGE &&
localStorage.getItem(getLocalStorageHash(this, 'isLocal')) === 'true'; localStorage.getItem(getLocalStorageHash(this, 'isLocal')) === 'true';
var saveToLocalStorage;
Object.defineProperties(this, Object.defineProperties(this,
/** @lends dat.gui.GUI.prototype */ /** @lends dat.gui.GUI.prototype */
@ -434,10 +436,15 @@ define([
addResizeHandle(this); addResizeHandle(this);
} }
function saveToLocalStorage() { saveToLocalStorage = function () {
localStorage.setItem(getLocalStorageHash(_this, 'gui'), JSON.stringify(_this.getSaveObject())); if (SUPPORTS_LOCAL_STORAGE && localStorage.getItem(getLocalStorageHash(_this, 'isLocal')) === 'true') {
localStorage.setItem(getLocalStorageHash(_this, 'gui'), JSON.stringify(_this.getSaveObject()));
}
} }
// expose this method publicly
this.saveToLocalStorageIfPossible = saveToLocalStorage;
var root = _this.getRoot(); var root = _this.getRoot();
function resetWidth() { function resetWidth() {
var root = _this.getRoot(); var root = _this.getRoot();
@ -734,6 +741,7 @@ define([
this.load.remembered[this.preset] = getCurrentPreset(this); this.load.remembered[this.preset] = getCurrentPreset(this);
markPresetModified(this, false); markPresetModified(this, false);
this.saveToLocalStorageIfPossible();
}, },
@ -750,6 +758,7 @@ define([
this.load.remembered[presetName] = getCurrentPreset(this); this.load.remembered[presetName] = getCurrentPreset(this);
this.preset = presetName; this.preset = presetName;
addPresetOption(this, presetName, true); addPresetOption(this, presetName, true);
this.saveToLocalStorageIfPossible();
}, },

View File

@ -68,8 +68,9 @@ define([
each: function(obj, itr, scope) { each: function(obj, itr, scope) {
if (!obj) return;
if (ARR_EACH && obj.forEach === ARR_EACH) { if (ARR_EACH && obj.forEach && obj.forEach === ARR_EACH) {
obj.forEach(itr, scope); obj.forEach(itr, scope);