mirror of
https://github.com/TeamPiped/Piped.git
synced 2024-08-14 23:57:27 +00:00
Factor out handler func, remove Listener on unmount
This commit is contained in:
parent
b8fdf3efeb
commit
4732c76dac
1 changed files with 15 additions and 13 deletions
|
@ -336,19 +336,7 @@ export default {
|
||||||
this.getPlaylistData();
|
this.getPlaylistData();
|
||||||
this.getSponsors();
|
this.getSponsors();
|
||||||
if (!this.isEmbed && this.showComments) this.getComments();
|
if (!this.isEmbed && this.showComments) this.getComments();
|
||||||
window.addEventListener("click", event => {
|
window.addEventListener("click", this.handleClick);
|
||||||
if (!event || !event.target) return;
|
|
||||||
var target = event.target;
|
|
||||||
if (
|
|
||||||
!target.nodeName == "A" ||
|
|
||||||
!target.getAttribute("href") ||
|
|
||||||
!target.innerText.match(/(?:[\d]{1,2}:)?(?:[\d]{1,2}):(?:[\d]{1,2})/)
|
|
||||||
)
|
|
||||||
return;
|
|
||||||
const time = parseInt(target.getAttribute("href").match(/(?<=t=)\d+/)[0]);
|
|
||||||
this.navigate(time);
|
|
||||||
event.preventDefault();
|
|
||||||
});
|
|
||||||
window.addEventListener("resize", () => {
|
window.addEventListener("resize", () => {
|
||||||
this.smallView = this.smallViewQuery.matches;
|
this.smallView = this.smallViewQuery.matches;
|
||||||
});
|
});
|
||||||
|
@ -372,6 +360,7 @@ export default {
|
||||||
},
|
},
|
||||||
unmounted() {
|
unmounted() {
|
||||||
window.removeEventListener("scroll", this.handleScroll);
|
window.removeEventListener("scroll", this.handleScroll);
|
||||||
|
window.removeEventListener("click", this.handleClick);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
fetchVideo() {
|
fetchVideo() {
|
||||||
|
@ -524,6 +513,19 @@ export default {
|
||||||
}
|
}
|
||||||
this.subscribed = !this.subscribed;
|
this.subscribed = !this.subscribed;
|
||||||
},
|
},
|
||||||
|
handleClick(event) {
|
||||||
|
if (!event || !event.target) return;
|
||||||
|
var target = event.target;
|
||||||
|
if (
|
||||||
|
!target.nodeName == "A" ||
|
||||||
|
!target.getAttribute("href") ||
|
||||||
|
!target.innerText.match(/(?:[\d]{1,2}:)?(?:[\d]{1,2}):(?:[\d]{1,2})/)
|
||||||
|
)
|
||||||
|
return;
|
||||||
|
const time = parseInt(target.getAttribute("href").match(/(?<=t=)\d+/)[0]);
|
||||||
|
this.navigate(time);
|
||||||
|
event.preventDefault();
|
||||||
|
},
|
||||||
handleScroll() {
|
handleScroll() {
|
||||||
if (this.loading || !this.comments || !this.comments.nextpage) return;
|
if (this.loading || !this.comments || !this.comments.nextpage) return;
|
||||||
if (window.innerHeight + window.scrollY >= this.$refs.comments?.offsetHeight - window.innerHeight) {
|
if (window.innerHeight + window.scrollY >= this.$refs.comments?.offsetHeight - window.innerHeight) {
|
||||||
|
|
Loading…
Reference in a new issue