@patternplate/client
Version:
Universal javascript client application for patternplate
57 lines (42 loc) • 1.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.type = exports.default = void 0;
var _scrollparent = _interopRequireDefault(require("scrollparent"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _default = scrollTo;
exports.default = _default;
const type = "SCROLL_TO";
exports.type = type;
const NOOP = () => {};
function scrollTo(to) {
const _global = global,
document = _global.document;
if (!document) {
return NOOP;
}
const target = getTarget(to);
if (!target) {
return NOOP;
}
const parent = (0, _scrollparent.default)(target);
if (!parent) {
return NOOP;
}
parent.scrollTop = target.offsetParent.offsetTop;
return dispatch => {
dispatch({
type: "SCROLLED_TO",
payload: to
});
};
}
function getTarget(to) {
if (typeof to === "string") {
return document.getElementById(to);
}
return to;
}
scrollTo.type = type;
//# sourceMappingURL=scroll-to.js.map