mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-06 23:52:58 +01:00
Merge pull request #1514 from frissdiegurke/master
added number-type to settings framework. persist expanded object on serv...
This commit is contained in:
@@ -151,7 +151,7 @@ Additionally the following plugins are registered by default:
|
||||
Uses ``data-new`` to define the value of new created elements.
|
||||
* key (types: key)
|
||||
A field to input keyboard-combinations.
|
||||
* checkbox, select, textarea
|
||||
* checkbox, number, select, textarea
|
||||
Handle appropriate fields.
|
||||
|
||||
A full list of all attributes that may influence the behavior of the default Framework:
|
||||
@@ -303,4 +303,4 @@ For further impression take a look at the
|
||||
|
||||
You should also take a look at the helper-functions within
|
||||
`Settings <https://github.com/designcreateplay/NodeBB/tree/master/public/src/modules/settings.js>`_ in order to create
|
||||
your own plugins. There are a few methods that take response to call the methods of other plugins when fittingly.
|
||||
your own plugins. There are a few methods that take response to call the methods of other plugins when fittingly.
|
||||
|
||||
@@ -2,6 +2,7 @@ define(function () {
|
||||
|
||||
const DEFAULT_PLUGINS = [
|
||||
'settings/checkbox',
|
||||
'settings/number',
|
||||
'settings/textarea',
|
||||
'settings/select',
|
||||
'settings/array',
|
||||
|
||||
14
public/src/modules/settings/number.js
Normal file
14
public/src/modules/settings/number.js
Normal file
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user