2015-10-15 23:11:09 -04:00
|
|
|
|
var ReactDOM = require('react-dom');
|
2015-12-16 12:00:42 -05:00
|
|
|
|
|
|
|
|
|
var ReactIntl = require('./intl.jsx');
|
2015-10-15 23:11:09 -04:00
|
|
|
|
var IntlProvider = ReactIntl.IntlProvider;
|
|
|
|
|
|
2016-01-14 08:16:02 -05:00
|
|
|
|
var Navigation = require('../components/navigation/navigation.jsx');
|
|
|
|
|
var Footer = require('../components/footer/footer.jsx');
|
|
|
|
|
|
2016-01-08 13:50:58 -05:00
|
|
|
|
var render = function (jsx, element) {
|
2015-10-15 23:11:09 -04:00
|
|
|
|
// Get locale and messages from global namespace (see "init.js")
|
2016-01-06 14:09:32 -05:00
|
|
|
|
var locale = window._locale || 'en';
|
2016-01-08 13:50:58 -05:00
|
|
|
|
if (typeof window._messages[locale] === 'undefined') {
|
2016-01-06 14:09:32 -05:00
|
|
|
|
// Fall back on the split
|
|
|
|
|
locale = locale.split('-')[0];
|
|
|
|
|
}
|
2016-01-08 13:50:58 -05:00
|
|
|
|
if (typeof window._messages[locale] === 'undefined') {
|
2016-01-06 14:09:32 -05:00
|
|
|
|
// Language appears to not be supported – fall back to 'en'
|
|
|
|
|
locale = 'en';
|
|
|
|
|
}
|
2016-01-08 13:50:58 -05:00
|
|
|
|
var messages = window._messages[locale];
|
2015-10-15 23:11:09 -04:00
|
|
|
|
|
2016-01-14 08:16:02 -05:00
|
|
|
|
|
|
|
|
|
// Render nav and footer for page.
|
|
|
|
|
var nav = ReactDOM.render(
|
|
|
|
|
<IntlProvider locale={locale} messages={messages}>
|
|
|
|
|
<Navigation />
|
|
|
|
|
</IntlProvider>,
|
|
|
|
|
document.getElementById('navigation')
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
var footer = ReactDOM.render(
|
|
|
|
|
<IntlProvider locale={locale} messages={messages}>
|
|
|
|
|
<Footer />
|
|
|
|
|
</IntlProvider>,
|
|
|
|
|
document.getElementById('footer')
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Provide list of rendered components
|
|
|
|
|
window._renderedComponents = window._renderedComponents || [];
|
|
|
|
|
window._renderedComponents.push(nav);
|
|
|
|
|
window._renderedComponents.push(footer);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Render view component
|
2015-10-15 23:11:09 -04:00
|
|
|
|
var component = ReactDOM.render(
|
2016-01-08 13:50:58 -05:00
|
|
|
|
<IntlProvider locale={locale} messages={messages}>
|
2015-10-15 23:11:09 -04:00
|
|
|
|
{jsx}
|
|
|
|
|
</IntlProvider>,
|
|
|
|
|
element
|
|
|
|
|
);
|
|
|
|
|
|
2015-11-03 10:49:32 -05:00
|
|
|
|
window._renderedComponents.push(component);
|
2015-10-15 23:11:09 -04:00
|
|
|
|
};
|
2015-10-16 15:10:17 -04:00
|
|
|
|
|
|
|
|
|
module.exports = render;
|