in lib/Habitat.js [82:148]
value: function parseProps(ele) {
// Default props with reference to the initiating node
var props = {
proxy: ele // Pass in a reference to the original node
};
// Populate custom props from reading any ele attributes that start with 'data-prop-'
for (var i = 0; i < ele.attributes.length; i++) {
var a = ele.attributes[i];
if (a.name.indexOf(HABITAT_PROP) === 0) {
// Convert prop name from hyphens to camel case
var name = getNameFor(HABITAT_PROP, a.name);
var value = a.value || '';
// Parse booleans
if (typeof value === 'string' && value.toLowerCase() === 'false') {
value = false;
}
if (typeof value === 'string' && value.toLowerCase() === 'true') {
value = true;
}
// Parse json strings
if (typeof value === 'string' && value.length >= 2 && (value[0] === '{' && value[value.length - 1] === '}' || value[0] === '[' && value[value.length - 1] === ']')) {
value = JSON.parse(value);
}
// Parse nulls
if (typeof value === 'string' && value.toLowerCase() === 'null') {
value = null;
}
props[name] = value;
} else
// JSON type props
if (a.name === HABITAT_PROP_JSON) {
// Parse all of the props as json
Object.assign(props, JSON.parse(a.value));
} else
// Number type props
if (a.name.indexOf('data-n-prop-') === 0) {
// Convert prop name from hyphens to camel case
var _name = getNameFor(HABITAT_PROP_NUMBER, a.name);
// Parse the value as a float as it handles both floats and whole int's
// Might want to look at configuring the radix somehow in the future
props[_name] = parseFloat(a.value);
} else
// Reference type props
if (window && a.name.indexOf(HABITAT_PROP_REF) === 0) {
// Convert prop name from hyphens to camel case
var _name2 = getNameFor(HABITAT_PROP_REF, a.name);
// Set the reference to the global object
props[_name2] = window[a.value];
}
}
return props;
}