diff --git a/public/src/modules/settings.js b/public/src/modules/settings.js index fa9ac0ac3d..2cb33163bb 100644 --- a/public/src/modules/settings.js +++ b/public/src/modules/settings.js @@ -2,6 +2,7 @@ define(function () { const DEFAULT_PLUGINS = [ 'settings/checkbox', + 'settings/number', 'settings/textarea', 'settings/select', 'settings/array', diff --git a/public/src/modules/settings/number.js b/public/src/modules/settings/number.js new file mode 100644 index 0000000000..5c98a86abc --- /dev/null +++ b/public/src/modules/settings/number.js @@ -0,0 +1,14 @@ +define(function () { + + return { + types: ['number'], + get: function (element, trim, empty) { + var value = element.val(); + if (!empty) { + return value ? +value : void 0; + } + return value ? +value : 0; + } + }; + +}); diff --git a/src/settings.js b/src/settings.js index 2286f26b1d..dfb65aaf9d 100644 --- a/src/settings.js +++ b/src/settings.js @@ -1,16 +1,20 @@ var meta = require('./meta'); function expandObjBy(obj1, obj2) { - var key, val1, val2; + var key, val1, val2, changed = false; for (key in obj2) { val2 = obj2[key]; val1 = obj1[key]; if (!obj1.hasOwnProperty(key) || typeof val2 !== typeof val1) { obj1[key] = val2; + changed = true; } else if (typeof val2 === 'object') { - expandObjBy(val1, val2); + if (expandObjBy(val1, val2)) { + changed = true; + } } } + return changed; } function trim(obj1, obj2) { @@ -76,7 +80,9 @@ Settings.prototype.sync = function (callback) { } } catch (_error) {} _this.cfg = settings; - if (typeof callback === 'function') { + if (expandObjBy(_this.cfg._, _this.defCfg)) { + _this.persist(callback); + } else if (typeof callback === 'function') { callback.apply(_this, err); } });