From 1df45adcada6a847ab880a432fa6340db79f7bd0 Mon Sep 17 00:00:00 2001 From: A-Circle Zhang Date: Sun, 19 Aug 2018 18:30:09 +0800 Subject: [PATCH] Update controller.js --- src/js/controller.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/js/controller.js b/src/js/controller.js index 602eb57..ac94a3d 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -29,6 +29,7 @@ class Controller { this.initQualityButton(); this.initScreenshotButton(); this.initSubtitleButton(); + this.initHighlights(); if (!utils.isMobile) { this.initVolumeButton(); } @@ -56,6 +57,29 @@ class Controller { }); } } + + initHighlights () { + this.player.on('durationchange', () => { + if (this.player.video.duration !== 1 && this.player.video.duration !== Infinity) { + if (this.player.options.highlight) { + const highlights = document.querySelectorAll('.dplayer-highlight'); + [].slice.call(highlights, 0).map((item) => { + this.player.template.playedBarWrap.removeChild(item); + }); + for (let i = 0; i < this.player.options.highlight.length; i++) { + if (!this.player.options.highlight[i].text || !this.player.options.highlight[i].time) { + continue; + } + const p = document.createElement('div'); + p.classList.add('dplayer-highlight'); + p.style.left = ( (this.player.options.highlight[i].time / this.player.video.duration) * 100) + '%'; + p.innerHTML = '' + this.player.options.highlight[i].text + ''; + this.player.template.playedBarWrap.insertBefore(p, this.player.template.playedBarTime); + } + } + } + }); + } initThumbnails () { if (this.player.options.video.thumbnails) {