Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
84 lines (84 loc) · 5.64 KB
/
Copy pathscript.js
File metadata and controls
84 lines (84 loc) · 5.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
(() => {
'use strict';
const data=window.VisualTalkData;
if(!data) return;
const labels={finance:'Finance',education_zh:'Chinese education',education_en:'English education'};
const domains=Object.keys(labels);
const grid=document.getElementById('video-grid');
const dialog=document.getElementById('video-dialog');
const player=document.getElementById('example-video');
const title=document.getElementById('dialog-title');
const dialogMeta=document.getElementById('dialog-meta');
const errorPanel=document.getElementById('video-error');
let lastTrigger=null;
function fmt(num){return num==null?'N/A':Number(num).toFixed(2)}
function create(tag, cls, value){const n=document.createElement(tag);if(cls)n.className=cls;if(value!=null)n.textContent=value;return n}
function renderResults(){
const tbody=document.getElementById('results-body');tbody.replaceChildren();
data.results.forEach((r,i)=>{
const tr=create('tr',i===0?'featured':'');
const heading=create('th','',r.agent);heading.scope='row';tr.append(heading);
['speech','visual','consistency','quality','jerk','pointingAccuracy','pointingRate'].forEach(key=>tr.append(create('td','',fmt(r[key]))));
tbody.append(tr);
});
}
function tryPlay(){player.play().catch(()=>{/* Keep native controls available when the browser requires another tap. */});}
function openVideo(item, trigger){
lastTrigger=trigger;
title.textContent=item.topic;
dialogMeta.textContent=`${labels[item.domain]} · ${item.subject} · ${item.id} · ${item.sceneId} · ${item.duration.toFixed(2)} s${item.domain==='finance'?' · one scene of a three-scene answer':''}`;
errorPanel.hidden=true;player.pause();
player.poster=item.fullPoster;player.src=item.fullVideo;player.load();
dialog.showModal();document.body.classList.add('video-open');tryPlay();
}
function closeVideo(){if(dialog.open)dialog.close()}
function renderVideos(domain){
grid.replaceChildren();
document.getElementById('video-panel').setAttribute('aria-labelledby',`domain-${domain}`);
data.references.filter(it=>it.domain===domain).forEach(it=>{
const figure=create('figure','video-item');
const button=create('button','video-button');button.type='button';button.dataset.sample=it.id;
button.setAttribute('aria-label','Play '+it.topic+', '+it.sceneId);button.setAttribute('aria-haspopup','dialog');
const img=document.createElement('img');img.src=it.fullPoster;img.loading='lazy';img.width=it.width;img.height=it.height;img.alt='';
const play=create('span','play','▶');play.setAttribute('aria-hidden','true');button.append(img,play);
button.addEventListener('click',()=>openVideo(it,button));
figure.append(button,create('figcaption','video-caption',it.topic),create('div','video-meta',`${it.subject} · ${it.id} · ${it.sceneId}`));
grid.append(figure);
});
document.getElementById('video-status').textContent=`Four selected ${labels[domain]} reference scenes.`;
}
function selectDomain(domain){
document.querySelectorAll('[data-domain]').forEach(b=>{const active=b.dataset.domain===domain;b.classList.toggle('active',active);b.setAttribute('aria-selected',String(active));b.tabIndex=active?0:-1;});
renderVideos(domain);
}
document.querySelectorAll('[data-domain]').forEach(b=>{
b.addEventListener('click',()=>selectDomain(b.dataset.domain));
b.addEventListener('keydown',event=>{
const i=domains.indexOf(b.dataset.domain),next={ArrowRight:(i+1)%3,ArrowLeft:(i+2)%3,Home:0,End:2}[event.key];
if(next===undefined)return;event.preventDefault();selectDomain(domains[next]);document.getElementById(`domain-${domains[next]}`).focus();
});
});
document.getElementById('close-video').addEventListener('click',closeVideo);
dialog.addEventListener('click',event=>{
const bounds=dialog.getBoundingClientRect();
if(event.target===dialog&&(event.clientX<bounds.left||event.clientX>bounds.right||event.clientY<bounds.top||event.clientY>bounds.bottom))closeVideo();
});
dialog.addEventListener('close',()=>{
player.pause();player.removeAttribute('src');player.removeAttribute('poster');player.load();
errorPanel.hidden=true;document.body.classList.remove('video-open');lastTrigger?.focus({preventScroll:true});lastTrigger=null;
});
player.addEventListener('error',()=>{if(player.getAttribute('src'))errorPanel.hidden=false;});
player.addEventListener('loadeddata',()=>{errorPanel.hidden=true;});
document.getElementById('retry-video').addEventListener('click',()=>{errorPanel.hidden=true;player.load();tryPlay();});
document.addEventListener('visibilitychange',()=>{if(document.hidden)player.pause()});
// Support bundled papers and confirmed public URLs; retain other placeholders.
const links=document.getElementById('publication-links');links.replaceChildren();let missing=0;
for(const key of ['paper','code','dataset']){
const name=key[0].toUpperCase()+key.slice(1),url=data.resources?.[key];
let publicURL=null;try{if(typeof url==='string'&&url.trim()){const parsed=new URL(url,document.baseURI);if(['https:','http:'].includes(parsed.protocol)&&(/^(?:https?:\/\/|assets\/)/.test(url)))publicURL=parsed.href}}catch{/* Unconfigured link. */}
if(publicURL){const a=create('a','',name);a.href=publicURL;a.target='_blank';a.rel='noopener noreferrer';links.append(a)}
else{const placeholder=create('span','resource-placeholder',name);placeholder.title='Public link not yet available';links.append(placeholder);missing++;}
}
if(missing)links.append(create('small','',missing===3?'Links to be added upon public release':'Additional links will be added upon public release'));
renderResults();renderVideos('finance');
})();