Allow floats in the slider component and update docs

This commit is contained in:
Keegan
2016-03-11 01:07:17 +11:00
parent 1142d1adee
commit 878fea0340
11 changed files with 323 additions and 133 deletions
+4
View File
@@ -29,6 +29,10 @@ module.exports = {
$valuePad.set('innerHTML', value);
}
var step = self.$manipulatorTarget.get('step');
step = step.toString(10).split('.')[1];
self.precision = step ? step.length : 0;
self.on('change', setValueDisplay);
setValueDisplay();
+7 -1
View File
@@ -158,7 +158,13 @@ function ClayConfig(settings, config, $rootContainer, meta) {
self.serialize = function() {
_checkBuilt('serialize');
_.eachObj(_itemsByAppKey, function(appKey, item) {
_settings[appKey] = item.get();
_settings[appKey] = {
value: item.get()
};
if (item.precision) {
_settings[appKey].precision = item.precision;
}
});
return _settings;
};
-51
View File
@@ -17,54 +17,3 @@ module.exports.updateProperties = function(obj, descriptor) {
Object.defineProperty(obj, prop, descriptor);
});
};
/**
* Converts the val into a type compatible with Pebble.sendAppMessage().
* - Strings will be returned without modification
* - Numbers will be returned without modification
* - Booleans will be converted to a 0 or 1
* - Arrays that contain strings will be split with a zero.
* eg: ['one', 'two'] becomes ['one', 0, 'two', 0]
* - Arrays that contain numbers will be returned without modification
* eg: [1, 2] becomes [1, 2]
* - Arrays that contain booleans will be converted to a 0 or 1
* eg: [true, false] becomes [1, 0]
* - Arrays must be single dimensional
* @param {number|string|boolean|Array} val
* @returns {number|string|Array}
*/
module.exports.prepareForAppMessage = function(val) {
var result;
if (typeof val === 'boolean') {
result = val ? 1 : 0;
} else if (Array.isArray(val)) {
result = [];
val.forEach(function(item) {
var itemConverted = module.exports.prepareForAppMessage(item);
result.push(itemConverted);
if (typeof itemConverted === 'string') {
result.push(0);
}
});
} else {
result = val;
}
return result;
};
/**
* Converts a Clay settings dict into one that is compatible with
* Pebble.sendAppMessage();
* @see {prepareForAppMessage}
* @param {Object} settings
* @returns {{}}
*/
module.exports.prepareSettingsForAppMessage = function(settings) {
var result = {};
Object.keys(settings).forEach(function(key) {
result[key] = module.exports.prepareForAppMessage(settings[key]);
});
return result;
};