UNPKG

ldx-widgets

Version:

widgets

50 lines (43 loc) 1.37 kB
(function() { var React, imagePaths, img, prefix; prefix = process.env.NODE_ENV === "development" ? '/images/' : '/build/images/'; imagePaths = ['flowsheet/internal/clinical.svg', 'flowsheet/external/clinical.svg', 'flowsheet/internal/doc.svg', 'flowsheet/external/doc.svg', 'flowsheet/internal/lab.svg', 'flowsheet/external/lab.svg', 'logo.svg', 'default_picture.svg']; React = require('react'); img = require('react-dom-factories').img; module.exports = { getInitialState: function() { return { preloadActive: true }; }, componentDidMount: function() { return this.loadCount = 0; }, preloadImages: function() { var i, imagePath, len, preloadActive, results; preloadActive = this.state.preloadActive; if (preloadActive) { results = []; for (i = 0, len = imagePaths.length; i < len; i++) { imagePath = imagePaths[i]; results.push(img({ key: imagePath, src: "" + prefix + imagePath, onLoad: this.loadCounter })); } return results; } else { return []; } }, loadCounter: function() { this.loadCount += 1; if (this.loadCount === imagePaths.length) { return this.setState({ preloadActive: false }); } } }; }).call(this);