mirror of
https://gitea.invidious.io/iv-org/videojs-vtt-thumbnails.git
synced 2024-08-15 00:43:16 +00:00
Add src api call, more thorough base base qualification
This commit is contained in:
parent
af1cb0df92
commit
ae376a28aa
1 changed files with 41 additions and 6 deletions
|
@ -24,8 +24,8 @@ const registerPlugin = videojs.registerPlugin || videojs.plugin
|
||||||
* A plain object containing options for the plugin.
|
* A plain object containing options for the plugin.
|
||||||
*/
|
*/
|
||||||
const onPlayerReady = (player, options) => {
|
const onPlayerReady = (player, options) => {
|
||||||
player.addClass('vjs-vtt-thumbnails')
|
player.addClass('vjs-vtt-thumbnails');
|
||||||
new vttThumbnailsPlugin(player, options)
|
player.vttThumbnails = new vttThumbnailsPlugin(player, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,7 +68,20 @@ class vttThumbnailsPlugin {
|
||||||
constructor (player, options) {
|
constructor (player, options) {
|
||||||
this.player = player
|
this.player = player
|
||||||
this.options = options
|
this.options = options
|
||||||
this.initializeThumbnails()
|
this.initializeThumbnails();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
src(source){
|
||||||
|
delete this.vttData;
|
||||||
|
delete this.thumbnailHolder;
|
||||||
|
delete this.lastStyle;
|
||||||
|
this.progressBar.removeEventListener('mouseenter',() => { return this.onBarMouseenter() });
|
||||||
|
this.progressBar.removeEventListener('mouseleave',() => { return this.onBarMouseleave() });
|
||||||
|
this.progressBar.removeEventListener('mousemove',this.onBarMousemove);
|
||||||
|
delete this.progressBar;
|
||||||
|
this.options.src = source;
|
||||||
|
this.initializeThumbnails();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -222,12 +235,28 @@ class vttThumbnailsPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
getFullyQualifiedUrl (path, base) {
|
getFullyQualifiedUrl (path, base) {
|
||||||
if (!path.match(/\/\//i)) {
|
if (path.indexOf('//') >= 0) {
|
||||||
|
// We have a fully qualified path.
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
if (base.indexOf('//') === 0) {
|
||||||
|
// We don't have a fully qualified path, but need to
|
||||||
|
// be careful with trimming.
|
||||||
|
return [
|
||||||
|
base.replace(/\/$/gi, ''),
|
||||||
|
this.trim(path, '/')
|
||||||
|
].join('/')
|
||||||
|
}
|
||||||
|
if (base.indexOf('//') > 0) {
|
||||||
|
// We don't have a fully qualified path, and should
|
||||||
|
// trim both sides of base and path.
|
||||||
return [
|
return [
|
||||||
this.trim(base, '/'),
|
this.trim(base, '/'),
|
||||||
this.trim(path, '/')
|
this.trim(path, '/')
|
||||||
].join('/')
|
].join('/')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If all else fails.
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,8 +279,14 @@ class vttThumbnailsPlugin {
|
||||||
const cssObj = {}
|
const cssObj = {}
|
||||||
|
|
||||||
// If there isn't a protocol, use the VTT source URL.
|
// If there isn't a protocol, use the VTT source URL.
|
||||||
const baseSplit = this.options.src.split(/([^\/]*)$/gi)
|
let baseSplit
|
||||||
vttImageDef = this.getFullyQualifiedUrl(vttImageDef, baseSplit[0])
|
if (this.options.src.indexOf('//') >= 0) {
|
||||||
|
baseSplit = this.options.src.split(/([^\/]*)$/gi).shift()
|
||||||
|
} else {
|
||||||
|
baseSplit = this.getBaseUrl() + this.options.src.split(/([^\/]*)$/gi).shift()
|
||||||
|
}
|
||||||
|
|
||||||
|
vttImageDef = this.getFullyQualifiedUrl(vttImageDef, baseSplit)
|
||||||
|
|
||||||
if (!vttImageDef.match(/#xywh=/i)) {
|
if (!vttImageDef.match(/#xywh=/i)) {
|
||||||
cssObj.background = 'url("' + vttImageDef + '")'
|
cssObj.background = 'url("' + vttImageDef + '")'
|
||||||
|
|
Loading…
Reference in a new issue