UNPKG

@hocgin/gin-snow

Version:
83 lines (69 loc) 3.07 kB
import _Reflect$construct from "@babel/runtime-corejs3/core-js-stable/reflect/construct"; import _classCallCheck from "@babel/runtime-corejs3/helpers/classCallCheck"; import _createClass from "@babel/runtime-corejs3/helpers/createClass"; import _inherits from "@babel/runtime-corejs3/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime-corejs3/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime-corejs3/helpers/getPrototypeOf"; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct) return false; if (_Reflect$construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } import React, { Component } from 'react'; var Index = /*#__PURE__*/function (_Component) { _inherits(Index, _Component); var _super = _createSuper(Index); function Index(props, context) { _classCallCheck(this, Index); return _super.call(this, props, context); } _createClass(Index, [{ key: "componentDidMount", value: function componentDidMount() { var _this = this; var isShow = this.props.isShow; if (isShow) { this.getOrCreateSnowContainer(); this.loadScript('//libs.baidu.com/jquery/2.0.0/jquery.min.js', function () { return _this.loadScript('//cdn.hocgin.top/snowy.js'); }); } } }, { key: "getOrCreateSnowContainer", value: function getOrCreateSnowContainer() { var sc = document.querySelector('.snow-container'); if (sc != null) { return sc; } var divEl = document.createElement('div'); divEl.className += 'snow-container'; divEl.style.position = 'fixed'; divEl.style.top = '0'; divEl.style.left = '0'; divEl.style.width = '100vw'; divEl.style.height = '100vh'; divEl.style.pointerEvents = 'none'; divEl.style.zIndex = '100001'; document.body.appendChild(divEl); return divEl; } }, { key: "loadScript", value: function loadScript(url, onload) { var script = document.createElement('script'); script.async = true; script.onload = onload; script.src = url; document.head.appendChild(script); } }, { key: "render", value: function render() { var children = this.props.children; return /*#__PURE__*/React.createElement(React.Fragment, null, children); } }]); return Index; }(Component); Index.defaultProps = { isShow: true }; export default Index;