UNPKG

overlayscrollbarschat-ligo

Version:

A simple OverlayScrollbars extension that provides basic chat window behaviour.

57 lines (46 loc) 1.89 kB
/*! overlayscrollbarschat v0.2.0 | (c) 2018-2020 fpdrozd | MIT license (see LICENSE) */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory() : typeof define === 'function' && define.amd ? define(factory) : (factory()); }(this, (function () { 'use strict'; function scrollBehavior(scrollbar, elements, content, oldContentHeight, appendScroll) { var calculate = function calculate() { var position = scrollbar.scroll().position.y; var hostHeight = elements.host.clientHeight; var contentHeight = content.clientHeight; if (!position) scrollbar.scroll({ y: contentHeight - oldContentHeight });else if (position + hostHeight == oldContentHeight) scrollbar.scroll({ y: contentHeight - hostHeight }, appendScroll.duration, appendScroll.easing); oldContentHeight = contentHeight; }; return calculate; } function OverlayScrollbarsChat(defaultOptions, framework) { var scrollbar = this; var osChat = {}; var scrollBehavior$$1 = function scrollBehavior$$1() {}; osChat.added = function (options) { var appendScroll = framework.extend(true, {}, { appendScroll: { duration: 200, easing: 'linear' } }, options).appendScroll; var elements = scrollbar.getElements(); var content = elements.content.querySelector('div'); var oldContentHeight = content.clientHeight; scrollBehavior$$1 = scrollBehavior(scrollbar, elements, content, oldContentHeight, appendScroll); }; osChat.removed = function () { scrollBehavior$$1 = function scrollBehavior$$1() {}; }; osChat.on = function (ev) { if (ev == 'contentSizeChanged') scrollBehavior$$1(); }; return osChat; } OverlayScrollbars.extension('OverlayScrollbarsChat', OverlayScrollbarsChat); })));