Updated timelink copy to be able to link back to the existing embed place
This commit is contained in:
parent
1de19dd5f6
commit
1b29fadaa0
@ -128,7 +128,7 @@
|
||||
* The Object has a toString() method which returns the parameters in the
|
||||
* same format as `window.location.search`.
|
||||
*/
|
||||
function parseGETParameters() {
|
||||
function parseGETParameters(presID) {
|
||||
const get = window.location.search.substring(1);
|
||||
const out = {};
|
||||
get.split('&').forEach((arg) => {
|
||||
@ -138,7 +138,13 @@
|
||||
const split = arg.split('=');
|
||||
const name = split[0];
|
||||
var value = null;
|
||||
if(split.length > 1) {
|
||||
if(name === presID) {
|
||||
value = {};
|
||||
split[1].split(';').forEach((localarg) => {
|
||||
const [localkey, localvalue] = localarg.split(':');
|
||||
value[localkey] = localvalue;
|
||||
});
|
||||
} else if(split.length > 1) {
|
||||
value = split[1];
|
||||
}
|
||||
out[name] = value;
|
||||
@ -150,12 +156,20 @@
|
||||
if(key === 'toString') {
|
||||
return;
|
||||
}
|
||||
if(this[key]) {
|
||||
if(key === presID) {
|
||||
const localresult = [];
|
||||
Object.keys(this[key]).forEach((localkey) => {
|
||||
localresult.push(localkey + ':'
|
||||
+ this[key][localkey]);
|
||||
});
|
||||
result.push(key + '=' + localresult.join(';'));
|
||||
} else if(this[key]) {
|
||||
result.push(key + '=' + this[key]);
|
||||
} else {
|
||||
result.push(key);
|
||||
}
|
||||
});
|
||||
console.log(this, result);
|
||||
return '?' + result.join('&');
|
||||
}
|
||||
|
||||
@ -251,7 +265,7 @@
|
||||
class MultiPlayer extends HTMLElement {
|
||||
static get observedAttributes() {
|
||||
return ['play', 'play-local', 'list', 'list-local',
|
||||
'nomunge', 'timelink', 'time'];
|
||||
'nomunge', 'timelink'];
|
||||
}
|
||||
|
||||
attributeChangedCallback(name, oldValue, newValue) {
|
||||
@ -294,9 +308,6 @@
|
||||
case 'timelink':
|
||||
this.toggleTimelink(newValue);
|
||||
break;
|
||||
case 'time':
|
||||
this._startTime = newValue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -309,9 +320,6 @@
|
||||
// Controlled by the 'nomunge' attribute on this element.
|
||||
this._mungeSources = true;
|
||||
|
||||
// The time to start playback at
|
||||
this._startTime = 0;
|
||||
|
||||
// raw presentation json is stored here
|
||||
this._presentation = null;
|
||||
|
||||
@ -606,23 +614,20 @@
|
||||
[createIcon(['timelink'])]);
|
||||
|
||||
this._timelinkButton.addEventListener('click', (event) => {
|
||||
const params = parseGETParameters();
|
||||
// Add presentation argument
|
||||
params['play'] = this.attributes['play'].nodeValue;
|
||||
|
||||
// Add playlist argument if present
|
||||
const playlistAttribute = this.attributes['list'];
|
||||
if(playlistAttribute && playlistAttribute.nodeValue) {
|
||||
params['list'] = playlistAttribute.nodeValue;
|
||||
const params = parseGETParameters(this._presentation.id);
|
||||
if(!params[this._presentation.id]) {
|
||||
params[this._presentation.id] = {};
|
||||
}
|
||||
const localargs = params[this._presentation.id];
|
||||
|
||||
// Add time argument
|
||||
const time = this._mainSource.currentTime;
|
||||
params['time'] = time.toFixed(1);
|
||||
localargs['t'] = time.toFixed(1);
|
||||
|
||||
// Save to clipboard
|
||||
navigator.clipboard.writeText(this._timelinkURL
|
||||
+ params.toString());
|
||||
const url = window.location.href.split('?', 1)
|
||||
+ params.toString()
|
||||
navigator.clipboard.writeText(url);
|
||||
});
|
||||
|
||||
// setSubtitles() requires this._subtitlesSelect to
|
||||
@ -769,7 +774,6 @@
|
||||
this._subtitlesSelect.classList.add('hidden');
|
||||
}
|
||||
|
||||
this._controlSource.currentTime = this._startTime;
|
||||
this.setActivePlaylistItem();
|
||||
this.autoBlurControls();
|
||||
this.initProgressContainer();
|
||||
@ -1011,6 +1015,15 @@
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Apply start time if applicable
|
||||
const args = parseGETParameters(this._presentation.id);
|
||||
if(args[this._presentation.id]) {
|
||||
const localargs = args[this._presentation.id];
|
||||
if(localargs['t']) {
|
||||
this._controlSource.currentTime = localargs['t'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1207,13 +1220,12 @@
|
||||
/*
|
||||
* Set the visibility of the time link button.
|
||||
*/
|
||||
toggleTimelink(url) {
|
||||
if(url) {
|
||||
toggleTimelink(visible) {
|
||||
if(visible) {
|
||||
this._timelinkButton.classList.remove('hidden');
|
||||
} else {
|
||||
this._timelinkButton.classList.add('hidden');
|
||||
}
|
||||
this._timelinkURL = url;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user