mirror of
https://github.com/TeamPiped/Piped.git
synced 2024-08-14 23:57:27 +00:00
Add only one listener on the window
This commit is contained in:
parent
95a0e4cbc8
commit
8311888501
2 changed files with 13 additions and 17 deletions
|
@ -71,7 +71,6 @@ export default {
|
|||
uploader: { type: String, default: null },
|
||||
videoId: { type: String, default: null },
|
||||
},
|
||||
emits: ["seek"],
|
||||
data() {
|
||||
return {
|
||||
loadingReplies: false,
|
||||
|
@ -80,21 +79,6 @@ export default {
|
|||
nextpage: null,
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
const thisComment = this;
|
||||
this.$el.querySelectorAll("a").forEach(elem => {
|
||||
if (elem.innerText.match(/(?:[\d]{1,2}:)?(?:[\d]{1,2}):(?:[\d]{1,2})/)) {
|
||||
elem.addEventListener("click", function (event) {
|
||||
if (!event || !event.target) return;
|
||||
if (!event.target.getAttribute("href").match(/(?<=t=)\d{1,}/)) return;
|
||||
|
||||
const time = parseInt(event.target.getAttribute("href").match(/(?<=t=)\d{1,}/)[0]);
|
||||
thisComment.$emit("seek", time);
|
||||
event.preventDefault();
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
async loadReplies() {
|
||||
if (!this.showingReplies && this.loadingReplies) {
|
||||
|
|
|
@ -186,7 +186,6 @@
|
|||
:comment="comment"
|
||||
:uploader="video.uploader"
|
||||
:video-id="getVideoId()"
|
||||
@seek="navigate"
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
@ -337,6 +336,19 @@ export default {
|
|||
this.getPlaylistData();
|
||||
this.getSponsors();
|
||||
if (!this.isEmbed && this.showComments) this.getComments();
|
||||
window.addEventListener("click", 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(event.target.getAttribute("href").match(/(?<=t=)\d+/)[0]);
|
||||
this.navigate(time);
|
||||
event.preventDefault();
|
||||
});
|
||||
window.addEventListener("resize", () => {
|
||||
this.smallView = this.smallViewQuery.matches;
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue