Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Ameeta-Prakash authored Aug 16, 2024
1 parent c4121d9 commit 26983c3
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 8 deletions.
Binary file added assets/latex.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
127 changes: 119 additions & 8 deletions assets/pm9yEBG_pnaAyi7L/player-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
'player:play': triggerPlay,
'player:focus': focusPlayer,
'preview:navigate': jumpToContext,
'preview:changeset': livePreview
'preview:changeset': livePreview,
'targetMode:toggle': toggleTargetMode,
'targetMode:focus': selectElementByPath,
'targetMode:translationHovered': handleHoveredTranslation,
'targetMode:translationHoverClear': handleClearHoverPath
}

if (Object.prototype.hasOwnProperty.call(params, 'wmode')) {
Expand All @@ -53,13 +57,19 @@

window.vRestoreStateData = params.state

window.isTargetModeEnabled = false

window.vInterfaceObject = {
isRise: !!params.rise,
OnSlideStarted: function (id) {
sendParentMessage({
type: 'slide:change',
data: id
})
sendParentMessage({
type: 'targetMode:status',
data: getIsTargetModeAvailable()
})
},
OnSlideTransition: function (id, duration) {
sendParentMessage({
Expand All @@ -78,13 +88,15 @@
OnEnterFullscreen: function () {
sendParentMessage({
type: 'fullscreen:enter',
windowName: window.name
windowName: window.name,
data: { windowName: window.name }
})
},
OnExitFullscreen: function () {
sendParentMessage({
type: 'fullscreen:exit',
windowName: window.name
windowName: window.name,
data: { windowName: window.name }
})
},
OnPlayerClicked: function () {
Expand Down Expand Up @@ -158,7 +170,16 @@

return
}
player.JumpToLocation(data.path)
player.JumpToLocation(data.path).then((data) => {
if (!data || !data?.target) {
return
}

sendParentMessage({
type: 'preview:navigate:success',
data: data.target?.replace(/_player./, '')
})
})
}

function triggerPlay() {
Expand All @@ -177,18 +198,101 @@

function livePreview(data) {
const player = window.GetPlayer()
if (typeof player.UpdateSegmentPartText !== 'function') {
log('player-interface.js: player.UpdateSegmentPartText is not a function! returning early')
if (typeof player.UpdateTextLibItem !== 'function') {
log('player-interface.js: player.UpdateTextLibItem is not a function! returning early')

return
}
data.forEach(change => {
if (change?.updatedXlifTarget) {
return player.UpdateSegmentPartText(change?.path[1], change?.updatedXlifTarget)
return sendParentMessage({
type: 'error',
data: {
errorJson: stringifyError({ message: 'Xlif target is not supported in this player version' }),
playerVersion: (window.globals && window.globals.playerVersion) || 'unknown'
}
})
}

player.UpdateTextLibItem(change?.path, change?.updatedTarget)
player.UpdateTextLibItem(change?.path, change?.updatedTarget, change?.livePreviewData)
})
}


function handleHoveredTargetPath(targetPath) {
log('player-interface.js: handleHoveredTargetPath', targetPath)
sendParentMessage({
type: 'targetMode:hovered',
data: targetPath
})

return targetPath
}

function handleSelectedTargetPath(targetPath) {
log('player-interface.js: handleSelectedTargetPath', targetPath)
sendParentMessage({
type: 'targetMode:selected',
data: targetPath
})
window.isTargetModeEnabled = false
}

function selectElementByPath({ path }) {
const player = window.GetPlayer()
if (typeof player.HighlightObject !== 'function') {
log('player-interface.js: player.HighlightObject is not a function! returning early')

return
}

if (!window.isTargetModeEnabled) {
return
}

player.HighlightObject(path, true)
}

function handleHoveredTranslation({ path }) {
const player = window.GetPlayer()
if (typeof player.HighlightObject !== 'function') {
log('player-interface.js: player.HighlightObject is not a function! returning early')

return
}

player.HighlightObject(path, false)
}

function handleClearHoverPath() {
const player = window.GetPlayer()
if (typeof player.HighlightObject !== 'function') {
log('player-interface.js: player.HighlightObject is not a function! returning early')

return
}
player.HighlightObject(null, false)
}

function toggleTargetMode({ isActive }) {
const player = window.GetPlayer()
if (!getIsTargetModeAvailable()) {
log('player-interface.js: player.EnterTargetMode is not a function! returning early')

return
}

if (window.isTargetModeEnabled) {
player.EnterTargetMode(false)
window.isTargetModeEnabled = false

return
}

if (isActive) {
player.EnterTargetMode(true, handleHoveredTargetPath).then(handleSelectedTargetPath)
window.isTargetModeEnabled = true
}
}

function handleMessage(e) {
Expand Down Expand Up @@ -258,4 +362,11 @@

return jsonify(pseudoError)
}

function getIsTargetModeAvailable() {
const player = window.GetPlayer()

return typeof player.EnterTargetMode === 'function'
}

})()

0 comments on commit 26983c3

Please sign in to comment.