Merge pull request #1514 from frissdiegurke/master

added number-type to settings framework. persist expanded object on serv...
v1.18.x
psychobunny 11 years ago
commit 2b4da7ebcd

@ -151,7 +151,7 @@ Additionally the following plugins are registered by default:
Uses ``data-new`` to define the value of new created elements. Uses ``data-new`` to define the value of new created elements.
* key (types: key) * key (types: key)
A field to input keyboard-combinations. A field to input keyboard-combinations.
* checkbox, select, textarea * checkbox, number, select, textarea
Handle appropriate fields. Handle appropriate fields.
A full list of all attributes that may influence the behavior of the default Framework: A full list of all attributes that may influence the behavior of the default Framework:

@ -2,6 +2,7 @@ define(function () {
const DEFAULT_PLUGINS = [ const DEFAULT_PLUGINS = [
'settings/checkbox', 'settings/checkbox',
'settings/number',
'settings/textarea', 'settings/textarea',
'settings/select', 'settings/select',
'settings/array', 'settings/array',

@ -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'); var meta = require('./meta');
function expandObjBy(obj1, obj2) { function expandObjBy(obj1, obj2) {
var key, val1, val2; var key, val1, val2, changed = false;
for (key in obj2) { for (key in obj2) {
val2 = obj2[key]; val2 = obj2[key];
val1 = obj1[key]; val1 = obj1[key];
if (!obj1.hasOwnProperty(key) || typeof val2 !== typeof val1) { if (!obj1.hasOwnProperty(key) || typeof val2 !== typeof val1) {
obj1[key] = val2; obj1[key] = val2;
changed = true;
} else if (typeof val2 === 'object') { } else if (typeof val2 === 'object') {
expandObjBy(val1, val2); if (expandObjBy(val1, val2)) {
changed = true;
}
} }
} }
return changed;
} }
function trim(obj1, obj2) { function trim(obj1, obj2) {
@ -76,7 +80,9 @@ Settings.prototype.sync = function (callback) {
} }
} catch (_error) {} } catch (_error) {}
_this.cfg = settings; _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); callback.apply(_this, err);
} }
}); });

Loading…
Cancel
Save