Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions src/js/action/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
draw_slur,
isSlurDownward,
get_by_id,
get_by_oldid,
handleFlip
} from '../utils/misc'

Expand Down Expand Up @@ -466,6 +467,25 @@ export function draw_metarelation(draw_context, mei_graph, g_elem) {
return added
}

/**
* Gets the element by old ID, and gets it by ID if not found
*
* @param {MEI_graph} mei_graph The graph to look the element into
* @param {element} el The element to look for
*
* @return {MEI_node} The node in the MEI of the element
*/
function get_by_oldid_and_id(mei_graph, el) {

let meiNode = get_by_oldid(mei_graph, el.getAttribute('oldid'))
if (!meiNode) {
let id = el.id.slice(el.id.match(/^\d/))
meiNode = get_by_id(mei_graph, id)
}

return meiNode
}

// Recursively add hover class to elements and their children
function addHoverClassToChildren(element, isRoot, isPrimary, draw_context, mei_graph) {
if (!element) return
Expand All @@ -475,8 +495,9 @@ function addHoverClassToChildren(element, isRoot, isPrimary, draw_context, mei_g
// Add hover class to the meta-relation itself
if (!isRoot) element.classList.add(isPrimary ? 'extrarelationhover' : 'relationhover')

// Get the corresponding MEI node using the oldid attribute
let meiNode = get_by_id(mei_graph, element.getAttribute('oldid') || element.id)
let meiNode = get_by_oldid_and_id(mei_graph, element)

if (!meiNode || !meiNode.length) return

// Recursively add hover class to the children
let primaries = relation_primaries(mei_graph, meiNode).map(
Expand Down Expand Up @@ -504,9 +525,9 @@ function removeHoverClassToChildren(element, isRoot, isPrimary, draw_context, me
// Remove hover class from the meta-relation itself
if (!isRoot) element.classList.remove(isPrimary ? 'extrarelationhover' : 'relationhover')

// Get the corresponding MEI node using the oldid attribute
// TODO: might be undefined and produce error
let meiNode = get_by_id(mei_graph, element.getAttribute('oldid') || element.id)
let meiNode = get_by_oldid_and_id(mei_graph, element)

if (!meiNode || !meiNode.length) return

// Recursively remove hover class from the children
let primaries = relation_primaries(mei_graph, meiNode).map(
Expand Down
2 changes: 2 additions & 0 deletions src/js/utils/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ export function note_coords(note) {

// Gets all elements from the doc with the oldid
export function get_by_oldid(doc, id) {
if (!id)
return null
if (id[0] == '#') { id = id.slice(1) }
var elems = doc.querySelectorAll('[*|oldid=\'' + id + '\']')
if (elems) {
Expand Down