UNPKG

mobinge

Version:

Client-heavy webcomic site display system

106 lines (86 loc) 4.11 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _panelset = require('./panelset'); var _panelset2 = _interopRequireDefault(_panelset); var _reactResponsive = require('react-responsive'); var _reactResponsive2 = _interopRequireDefault(_reactResponsive); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var Mobinge = function (_React$Component) { _inherits(Mobinge, _React$Component); function Mobinge(props) { _classCallCheck(this, Mobinge); var ratio = .75; var width = parseInt(props.width); var startPanel = parseInt(props.startPanel); var _this = _possibleConstructorReturn(this, (Mobinge.__proto__ || Object.getPrototypeOf(Mobinge)).call(this, props)); _this.state = { width: width, height: width / ratio, startPanel: startPanel - 1, manifest: props.manifest }; return _this; } _createClass(Mobinge, [{ key: 'getOffset', value: function getOffset() { return this.state.offset * this.state.width; } }, { key: 'getQueryParam', value: function getQueryParam(count) { var padding = 20; var queryParam = { key: 'query-' + count }; if (count > 1) { queryParam.minWidth = this.props.width * count + padding; } if (count < this.props.maxPanel) { queryParam.maxWidth = this.props.width * (count + 1) + padding - 1; } return queryParam; } }, { key: 'getStyle', value: function getStyle(count) { return { 'overflow': 'hidden', 'width': this.state.width * count + 'px' }; } }, { key: 'render', value: function render() { var queries = []; for (var count = this.props.maxPanel; count; count--) { queries.push(_react2.default.createElement( _reactResponsive2.default, this.getQueryParam(count), _react2.default.createElement( 'div', { key: 'strip-' + count, style: this.getStyle(count) }, _react2.default.createElement(_panelset2.default, { width: this.state.width, height: this.state.height, arrowWidth: count >= this.props.arrowThreshold ? count : false, startPanel: this.state.startPanel, manifest: this.state.manifest }) ) )); } return _react2.default.createElement( 'div', { key: 'strip' }, queries ); } }]); return Mobinge; }(_react2.default.Component); exports.default = Mobinge;