Fixed copy-to-clipboard re-appearing after document switch

This commit is contained in:
squidfunk
2020-02-29 12:38:11 +01:00
parent 6029122f96
commit a1393fdbc3
7 changed files with 17 additions and 13 deletions

View File

@@ -314,16 +314,19 @@ export function initialize(config: unknown) {
* Location change
*/
interface State {
url: URL // TODO: use URL!?
url: URL
data?: ViewportOffset
}
function isInternalLink(el: HTMLAnchorElement | URL) {
return el.hostname === location.hostname
return el.host === location.host && (
!el.pathname || /\/[\w-]+(?:\/?|\.html)$/i.test(el.pathname)
)
}
// on same page!
function isAnchorLink(el: HTMLAnchorElement | URL) {
return el.hash.length > 0
return el.pathname === location.pathname && el.hash.length > 0
}
function compareState(
@@ -421,7 +424,7 @@ export function initialize(config: unknown) {
prev.url.href.match(next.url.href) !== null &&
isAnchorLink(prev.url)
) {
dialog$.next(`Potential Candidate: ${JSON.stringify(next.data)}`, ) // awesome debugging.
// dialog$.next(`Potential Candidate: ${JSON.stringify(next.data)}`, ) // awesome debugging.
setViewportOffset(next.data || { y: 0 })
}
// console.log("Potential Candidate")

View File

@@ -20,13 +20,14 @@
* IN THE SOFTWARE.
*/
import { Subject, animationFrameScheduler } from "rxjs"
import { Subject, animationFrameScheduler, of } from "rxjs"
import {
delay,
map,
observeOn,
switchMap,
tap
tap,
withLatestFrom
} from "rxjs/operators"
import { useComponent } from "components"
@@ -65,7 +66,7 @@ export function setupDialog(
/* Display dialog */
dialog$
.pipe(
switchMap(text => useComponent("container")
switchMap(text => of(document.body) // useComponent("container")
.pipe(
map(container => container.appendChild(dialog)),
observeOn(animationFrameScheduler),