@@ -26,6 +26,7 @@ import {
2626 draw_slur ,
2727 isSlurDownward ,
2828 get_by_id ,
29+ get_by_oldid ,
2930 handleFlip
3031} from '../utils/misc'
3132
@@ -466,6 +467,25 @@ export function draw_metarelation(draw_context, mei_graph, g_elem) {
466467 return added
467468}
468469
470+ /**
471+ * Gets the element by old ID, and gets it by ID if not found
472+ *
473+ * @param {MEI_graph } mei_graph The graph to look the element into
474+ * @param {element } el The element to look for
475+ *
476+ * @return {MEI_node } The node in the MEI of the element
477+ */
478+ function get_by_oldid_and_id ( mei_graph , el ) {
479+
480+ let meiNode = get_by_oldid ( mei_graph , el . getAttribute ( 'oldid' ) )
481+ if ( ! meiNode ) {
482+ let id = el . id . slice ( el . id . match ( / ^ \d / ) )
483+ meiNode = get_by_id ( mei_graph , id )
484+ }
485+
486+ return meiNode
487+ }
488+
469489// Recursively add hover class to elements and their children
470490function addHoverClassToChildren ( element , isRoot , isPrimary , draw_context , mei_graph ) {
471491 if ( ! element ) return
@@ -475,8 +495,9 @@ function addHoverClassToChildren(element, isRoot, isPrimary, draw_context, mei_g
475495 // Add hover class to the meta-relation itself
476496 if ( ! isRoot ) element . classList . add ( isPrimary ? 'extrarelationhover' : 'relationhover' )
477497
478- // Get the corresponding MEI node using the oldid attribute
479- let meiNode = get_by_id ( mei_graph , element . getAttribute ( 'oldid' ) || element . id )
498+ let meiNode = get_by_oldid_and_id ( mei_graph , element )
499+
500+ if ( ! meiNode || ! meiNode . length ) return
480501
481502 // Recursively add hover class to the children
482503 let primaries = relation_primaries ( mei_graph , meiNode ) . map (
@@ -504,9 +525,9 @@ function removeHoverClassToChildren(element, isRoot, isPrimary, draw_context, me
504525 // Remove hover class from the meta-relation itself
505526 if ( ! isRoot ) element . classList . remove ( isPrimary ? 'extrarelationhover' : 'relationhover' )
506527
507- // Get the corresponding MEI node using the oldid attribute
508- // TODO: might be undefined and produce error
509- let meiNode = get_by_id ( mei_graph , element . getAttribute ( 'oldid' ) || element . id )
528+ let meiNode = get_by_oldid_and_id ( mei_graph , element )
529+
530+ if ( ! meiNode || ! meiNode . length ) return
510531
511532 // Recursively remove hover class from the children
512533 let primaries = relation_primaries ( mei_graph , meiNode ) . map (
0 commit comments