2018-12-08 07:23:48 +00:00
|
|
|
<div class="compose-box-button-sentinel" ref:sentinel></div>
|
2019-10-08 12:59:45 +00:00
|
|
|
<div class="{computedClass}"
|
2018-12-02 19:22:18 +00:00
|
|
|
ref:wrapper >
|
|
|
|
<ComposeButton {overLimit} {sticky} on:click="onClickButton()" />
|
|
|
|
</div>
|
|
|
|
<style>
|
|
|
|
.compose-box-button-wrapper {
|
|
|
|
/*
|
|
|
|
* We want pointer-events only for the sticky button, so use fit-content so that
|
|
|
|
* the element doesn't take up the full width, and then set its left margin to
|
|
|
|
* auto so that it sticks to the right. fit-content doesn't work in Edge, but
|
|
|
|
* that just means that content that is level with the button is not clickable.
|
|
|
|
*/
|
|
|
|
width: -moz-fit-content;
|
|
|
|
width: fit-content;
|
|
|
|
margin-left: auto;
|
|
|
|
display: flex;
|
|
|
|
justify-content: flex-end;
|
|
|
|
}
|
|
|
|
|
|
|
|
.compose-box-button-sticky {
|
|
|
|
position: -webkit-sticky;
|
|
|
|
position: sticky;
|
|
|
|
}
|
|
|
|
|
|
|
|
:global(.compose-box-button-sticky, .compose-box-button-fixed) {
|
|
|
|
z-index: 5000;
|
2019-09-21 06:17:57 +00:00
|
|
|
top: calc(var(--main-content-pad-top) + var(--sticky-pad-top));
|
2018-12-02 19:22:18 +00:00
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<script>
|
|
|
|
import ComposeButton from './ComposeButton.html'
|
|
|
|
import { store } from '../../_store/store'
|
2019-10-30 01:58:49 +00:00
|
|
|
import { importShowComposeDialog } from '../dialog/asyncDialogs/importShowComposeDialog.js'
|
2018-12-02 19:22:18 +00:00
|
|
|
import { observe } from 'svelte-extras'
|
2019-10-08 12:59:45 +00:00
|
|
|
import { classname } from '../../_utils/classname'
|
2018-12-02 19:22:18 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
oncreate () {
|
2019-08-11 18:09:43 +00:00
|
|
|
this.setupIntersectionObservers()
|
2018-12-02 19:22:18 +00:00
|
|
|
},
|
|
|
|
ondestroy () {
|
2019-08-11 18:09:43 +00:00
|
|
|
this.teardownIntersectionObservers()
|
2018-12-02 19:22:18 +00:00
|
|
|
},
|
|
|
|
store: () => store,
|
|
|
|
data: () => ({
|
|
|
|
sticky: false
|
|
|
|
}),
|
|
|
|
computed: {
|
2019-10-08 12:59:45 +00:00
|
|
|
timelineInitialized: ({ $timelineInitialized }) => $timelineInitialized,
|
|
|
|
computedClass: ({ showSticky, hideAndFadeIn }) => (classname(
|
|
|
|
'compose-box-button-wrapper',
|
|
|
|
showSticky && 'compose-box-button-sticky',
|
|
|
|
hideAndFadeIn
|
|
|
|
))
|
2018-12-02 19:22:18 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
observe,
|
|
|
|
onClickButton () {
|
2019-08-03 20:49:37 +00:00
|
|
|
const { sticky } = this.get()
|
2018-12-02 19:22:18 +00:00
|
|
|
if (sticky) {
|
|
|
|
// when the button is sticky, we're scrolled down the home timeline,
|
|
|
|
// so we should launch a new compose dialog
|
|
|
|
this.showDialog()
|
|
|
|
} else {
|
|
|
|
// else we're actually posting a new toot, let our parent know
|
|
|
|
this.fire('postAction')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async showDialog () {
|
|
|
|
(await importShowComposeDialog())()
|
|
|
|
},
|
2019-08-11 18:09:43 +00:00
|
|
|
setupIntersectionObservers () {
|
2019-08-03 20:49:37 +00:00
|
|
|
const sentinel = this.refs.sentinel
|
2018-12-02 19:22:18 +00:00
|
|
|
|
|
|
|
this.__stickyObserver = new IntersectionObserver(entries => this.onObserve(entries))
|
|
|
|
this.__stickyObserver.observe(sentinel)
|
|
|
|
|
|
|
|
// also create a one-shot observer for the $timelineInitialized event,
|
|
|
|
// due to a bug in Firefox where when the scrollTop is set
|
|
|
|
// manually, the other observer doesn't necessarily fire
|
|
|
|
this.observe('timelineInitialized', timelineInitialized => {
|
2019-08-11 18:09:43 +00:00
|
|
|
if (timelineInitialized && !this.__oneShotObserver) {
|
|
|
|
this.__oneShotObserver = new IntersectionObserver(entries => {
|
2018-12-02 19:22:18 +00:00
|
|
|
this.onObserve(entries)
|
2019-08-11 18:09:43 +00:00
|
|
|
this.__oneShotObserver.disconnect()
|
|
|
|
this.__oneShotObserver = null
|
2018-12-02 19:22:18 +00:00
|
|
|
})
|
2019-08-11 18:09:43 +00:00
|
|
|
this.__oneShotObserver.observe(sentinel)
|
2018-12-02 19:22:18 +00:00
|
|
|
}
|
|
|
|
}, { init: false })
|
|
|
|
},
|
|
|
|
onObserve (entries) {
|
|
|
|
this.set({ sticky: !entries[0].isIntersecting })
|
|
|
|
},
|
2019-08-11 18:09:43 +00:00
|
|
|
teardownIntersectionObservers () {
|
2018-12-02 19:22:18 +00:00
|
|
|
if (this.__stickyObserver) {
|
|
|
|
this.__stickyObserver.disconnect()
|
2019-08-11 18:09:43 +00:00
|
|
|
this.__stickyObserver = null
|
|
|
|
}
|
|
|
|
if (this.__oneShotObserver) {
|
|
|
|
this.__oneShotObserver.disconnect()
|
|
|
|
this.__oneShotObserver = null
|
2018-12-02 19:22:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
ComposeButton
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|